From: Adam Shelly Date: 2005-08-26T08:10:23+09:00 Subject: Re: [SUMMARY] Sodoku Solver (#43) On 8/25/05, Simon Kr�ger wrote: > i have another version for you: > > def parse_board(file) > @@boxcols= (s = file.read).scan(/[+-]+/).size() -1 > boardlist = s.scan(/[0-9A-Za-z_]/).map{|c| c.hex} > return boardlist, Math.sqrt(boardlist.size).to_i > end > > assuming that boxcols is the number of boxes in horizontal or > vertical direction, boardlist is one array (e.g. with 81 cells > for a 9x9 board) and the second return parameter is the number > of columns or rows. right? > almost. boxcols counted the +'s in the horizontal direction (columns), yours counts vertical (rows). The difference is important in solving +-----+-----+-----+-----+ | 1 _ | _ _ | _ _ | _ _ | | _ 2 | 1 _ | _ _ | _ _ | | _ _ | 3 _ | _ _ | _ _ | | _ _ | _ 4 | _ _ | _ _ | +-----+-----+-----+-----+ | _ _ | _ _ | 5 _ | _ _ | | _ _ | _ _ | _ 6 | _ _ | | _ _ | _ _ | _ _ | 7 _ | | _ _ | _ _ | _ _ | _ 8 | +-----+-----+-----+-----+ vs +---------+---------+ | 1 _ _ _ | _ _ _ _ | | _ 2 _ _ | _ _ _ _ | +---------+---------+ | _ 1 3 _ | _ _ _ _ | | _ _ _ 4 | _ _ _ _ | +---------+---------+ | _ _ _ _ | 5 _ _ _ | | _ _ _ _ | _ 6 _ _ | +---------+---------+ | _ _ _ _ | _ _ 7 _ | | _ _ _ _ | _ _ _ 8 | +---------+---------+ My code handles both puzzles. And it's an easy fix to make it work with your 'boxrows' instead. Thanks for the tips. -Adam