Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Edmund von der Burg (ecclestoad.co.uk)has written a simple sudoku solver. The solver processes one sudoku and then dies.

To be able to handle a list of sudokus as input I adhoc replaced the "die" command by "warn".

That had the effect that the execution time for the 5 sudokos of the example increased from 82 s (for die) to 717 s.

How come?
use integer; my $start = time; while(<DATA>){ if(/#----END----#/){ my $duration = time - $start; die "Execution time: $duration s\n"; } @A = split //,; &R; } 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; } $sum=0; for(@A){$sum+=$_} print" $sum\n"; warn @A; # Execution time = 717 s # die @A; # Execution time 31 + 31 + 14 + 1 + 5 = 82 s } __DATA__ 1204003003000100500060001007000900000406030000030020005000807000070000 +05000000098 0000000390000010050030508000080900060700020001004000000090800500200006 +00400700000 1203000043500001000040000000054002006000700000000080900031005000000090 +70000060008 0030000004000800360080001000400600730009000000000020050040700686000000 +00700600500 8000000000036000000700902000500070000000457000001000300010000680085000 +10090000400 #----END----# 1284653793742198569568371427651984232496735818135429675923867144879216 +35631754298 7518462398923714656432598712381975469745623181654389273196847525279136 +84486725193 1263957843598471628746219539854162376319728452475386917631845294182593 +76592763418 1234567894571892369683271542495618735769384128317426953142759686958143 +27782693541 8127536499436821756754912831542378963698457212871695345219743684385269 +17796318452

In reply to Sudoku solver by ecube

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-18 14:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found