From: Adam Shelly Date: 2005-08-24T02:31:48+09:00 Subject: Re: [QUIZ] Sodoku Solver (#43) On 8/23/05, James Edward Gray II wrote: > Looking good. Here's a few general Ruby style tips. Feel free to > ignore, if your not interested: > > 1. An easier way to write `print "line\n"` is `puts line`. > 2. Instead of using the dprint() method and commenting out the thanks > 3. You can drop those outer parenthesis for if statements. `if > (condition)` can be just `if condition`. I know, but C programmer habits die hard. just looks funny without them... So here's one thing I couldn't figure out last night, maybe someone can help me: I wanted to throw an exception in the middle of a pair of recursive functions, and catch it at the beginning of recursion. But I can't figure out where to put the rescue. I wanted to do something like this pseudocode: def solve deduce startGuessing if !solved return solved end def deduce ...work... raise BadGuess if conflict end def startGuessing @depth+=1 begin while candidates do begin guess #chose a candidate cloneBoard.solve #with that candidate rescue BadGuess #go on to next candidate end end #while raise UnsolvableBoard if !solved rescue UnsolvableBoard if @depth == 1 # this doesn't work. # if I remove the if, I end up at the level I started with. # and putting the rescue in the solve function doesn't help either. # ? So can I get back to the next candidate on the 1st level, # without checking return codes the whole way down # (which is what I ended up doing)? end end Thanks for any ideas, -Adam