Skip to main content

Posts

Sudoku in Perl5 #1 - a brute-force solution

Having written the Perl6 Sudoku solver, I decided to go back to the Perl5 version I wrote when I was experimenting with Moose, but I couldn't find where I put it. While waiting for my senile memory to function, I implemented a brute-force solution. The basic concept of the brute-force approach is that you begin with a grid, some cells of which have been defined by the puzzle designer. I begin with the first empty cell ( call it A) and set it to '1'. I check to see if that conflicts with any already specified cells in the same row, in the same column, in the same block. If there's a conflict, I try the next element in the list of possible values : 2, 3..9. If a value does not conflict with existing cells, then on to the next cell. If all values create a conflict, then an earlier cell must have the wrong value, so back up. By recursively calling a routine over and over, backing up is easy, just return . If we run out of cells to the right, advance to the next row; when we

Niagara Escarpment Autumn Photos

Exploring Perl6

I've been exploring Perl6 since Rakudo-star was released in late July. There's a lot of exciting things to learn about Perl6, and you have to start early to figure things out. I've been working on implementing a simple sudoku solver, as something to do. My conclusion is that I'm delighted with what's been done, and what's coming ... and frustrated waiting for what's coming to turn into usable features! Sudoku In case you've been on Mars the last few years, sudoku is a puzzle with nine rows and nine columns. That block is also divided into 3x3 regions ... like a tic-tac-toe board subdivided into tic-tac-toe boards. When solved, each row contains the digits 1 to 9, without repetition; so does each column, and each block. Each puzzle begins with a certain number of cells filled in, your job is to figure out the rest. You know that cell A1 can't be a 1, because there's a one already in that row, it can't be a 2 or 4 or 6 or 7 or 8. From the othe

It didn't happen if you don't have photos

Visited Niagara Falls last weekend. Everyone was busy proving they had been there.

Tall Ships

There was a gathering of tall ships in Toronto Canada / Independence Day weekend, and while I found some interesting shots of rigging and hardware, I especially liked this rope hanging off the stern of the German ship, so swimmers could climb back aboard. The ship was steady, being tied to the dock, hardly any motion at all, so the movement of the water expressed itself relative to the monkey's fist knot at the bottom of the gently swaying rope. This one is scaled down; click on the picture to go to my photo website gallery of animations and see it full size.