#!/usr/bin/perl my $board = do{local $/=undef; <>}; $board =~ s/[^\s\d]/0/sg; $board =~ s/\s//sg; $SIG{"__DIE__"} = sub { for my $row (0..8) { print "\n" if ($row % 3 == 0 && $row); for my $col (0..8) { print " " if ($col % 3 == 0 && $col); print $A[$row*9+$col]; } print "\n"; } exit; }; # http://www.ecclestoad.co.uk/blog/2005/06/02/sudoku_solver_in_three_lines_explained.html use integer;@A=split//,$board;sub R{for$i(0..80){next if$A[$i];my%t=map{$_/9 ==$i/9||$_%9==$i%9||$_/27==$i/27&&$_%9/3==$i%9/3?$A[$_]:0=>1}0..80;R($A[ $i]=$_)for grep{!$t{$_}}1..9;return$A[$i]=0}die@A}R