Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (11)
    As of 2014-08-01 16:38 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who would be the most fun to work for?















      Results (30 votes), past polls