My last nocturnal cycle was enjoyable. I awoke "early" enough to study at the Daily Grind with buildmuscle. While we were there, I received a phone call from the young lady who didn't understand what I said clearly - twice. Abusing my politeness is one of those acts that has the unremarkable ability to grate on my nerves.
buildmuscle then received another one of his evil brainwaves and suggested I force things super-clear in the most entertaining way (to him) possible. Initially, I rejected his proposal strenuously - it's very not-quadhome. However, 40 minutes of peer pressure and I'm as gentle as a newborn babe...
Sound of my cell phone ringing.
"I'm just finishing up my third dinner tonight."
"I'm getting pretty tired, so I'm probably going to go to bed soon. What are you doing, though?"
"I'm just leaving the Grind and heading home. If you still want to hang out, you should come over and we should have sex."
"Hahahaha, that's a good idea."
"I thought so."
"Yeah, well, do you still want to visit my work?"
"Hmm, I'm thinking I don't think so."
"Why, did you suddenly lose interest?"
"Yes." End call.
I'll admit, after it was done, I was entertained too. When all pretenses of disappearing quietly are abandoned, being a direct jerk is just as effective.
I arrived home later, and was delighted by action on bar_in_taiwan. A new post and pictures! I took care of the behind the scene details while considering the consumption of a slice of slightly burnt pumpkin pie. No pie, but a new gallery has been uploaded. The evening only improved when I received an IM-buddy request from my Father! We chatted for a while, but he had to leave as someone else wanted to use the computer.
I settled in for the night, and decided to finish the homework due at the end of the break. The assignment wasn't difficult - so I had some fun and reimplemented the recursive search algorithm using a co-routine and a stack.
entry = findMostConstrained() # raises "failed" if some position is over-constrained if entry == None: raise "success" # this occurs when there is exactly one possibility for each square # otherwise ... # try each of the possibilities, one by one possibilities = entry.getPossibleValues() for val in possibilities: entry.setPossibleValues([val]) # assume this entry has value val undo = self.addConstraint(entry.row, entry.col, val) # propagate that as a constraint # then ... try: # try to solve from the new state and ... self.solve() except "failed": # if this results in some square with no possibilities ... pass # or doesn't result in success then # undo the propagation and try the next value from the list of possibilities undoConstraints(undo) # if we run out of possibilities without achieving success # put back the the entry as it was... entry.setPossibleValues(possibilities) # ... and raise "failed" to backtrack to the next higher level raise "failed"
# Find the most constrained cell, from which to begin the search from. entry = _findMostConstrained() if entry == None: yield True return # Try each of the possibilities, one by one. stack_possibilities = [(entry, value) for value in entry.getPossibleValues()] while stack_possibilities: # Two items can be on the stack. Either a possibility to check # (tuple), or an action to undo. (list) item = stack_possibilities.pop() if isinstance(item, list): (entry, saved_possibilities, constraints) = item _undoConstraints(constraints) entry.setPossibleValues(saved_possibilities) continue (entry, value) = item # Try the specific value. saved_possibilities = entry.getPossibleValues() entry.setPossibleValues([value]) # Push the actions necessary to undo on to the stack. stack_possibilities.append([entry, saved_possibilities, self.addConstraint(entry.row, entry.col, value)]) # Check if a solution has been found? new_entry = _findMostConstrained() if new_entry: # No solutions were found, load the stack with the possibilities. stack_possibilities.extend([(new_entry, value) for value in new_entry.getPossibleValues()]) elif new_entry == None: # We found a solution! yield True