Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Puzzler

by gaspodethewonderdog (Monk)
on Jan 19, 2001 at 21:56 UTC ( [id://53048]=perlmeditation: print w/replies, xml ) Need Help??

Well monks, it's a slow Friday for me here and I just coded up a program to solve a puzzle. If you've got nothing better to do you've got the solution... now you just need to find the question :).
for $p (0..14) { $t[$p] = "000000010000000"; $t[7] = "1"x15; substr($t[$p], $p, 1) = "1"; substr($t[$p], 14-$p, 1) = "1"; } for $x (0..7) { for $y (0..7) { $m[$x+($y*8)] .= substr($t[7-$y+$_], 7-$x, 8) for 0..7; } } $b = "0" x 64; $a = $b; &z($_, $d+1) for 0..63; $s =~ s/([^\n]{8})/$1\n/g; print $s; sub z { my ($p,$d) = @_; ($b & $m[$p]) ne $a?return:eval 'substr($b, $p, 1) = "1"'; $d == 8?eval '$s .= "$b|" if $s !~ /$b/':&z($_, $d+1) for 0..63; substr($b, $p, 1) = "0"; }
Sorry about the code being a little squished... but I had to do it to make it easier to cut and paste... the code isn't terribly obfuscated or anything as I only spent enough time to get it down from 2k to under 512 bytes... it certainly isn't some confusing 1 liner (drats)...

Anyway... if any of you are interested enough good luck! If you have any questions about it, need hints or otherwise either post off of the thread or you can email me at gaspode_2000@yahoo.com...

Oh and as with most solutions to puzzles this one takes a pretty good time to find all the solutions... so you'll need a fast computer if you just wanted to let it run to find all the solutions... or let it run over the weekend... so good luck :)

UPDATE

Sorry about the compile problem guys!!!! I fixed it... I had been actually running a slightly different version on my system than what I was modifying... sorry about the confusion it is fixed now...

Replies are listed 'Best First'.
Re: Puzzler
by myocom (Deacon) on Jan 19, 2001 at 23:50 UTC

    I'm afraid this code doesn't compile (at least under 5.005 on Win32).

    Can't modify return in scalar assignment at C:\puzzle.pl line 16, near + ""1";" syntax error at C:\puzzle.pl line 17, near ""$b|" if" Execution of C:\puzzle.pl aborted due to compilation errors.
      I've hacked it a bit to fix the error, I think this is still in the spirit the author had intended:

      Replace in sub z:
      ($b & $m[$p]) ne $a?return:substr($b, $p, 1) = "1"; $d == 8?$s .= "$b|" if $s !~ /$b/:&z($_, $d+1) for 0..63;

      With:
      if (($b & $m[$p]) ne $a) { return; } else { substr($b, $p, 1) = "1"; } if ($d == 8) { $s .= "$b|" if $s !~ /$b/; } else { &z($_, $d+1) for 0..63; }

      The errors go away on Perl 5.6. Is it proper to use return in that kind of switch? I'd assume its not because of the error, but do many of you use ? : instead of branching with if/else? This may have just been the author's attempt at obfuscating the code... *shrug*
      Or on Linux RH 6.2 running Perl 5.005_03
      I received the exact same error.

      TStanley
      In the end, there can be only one!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://53048]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2024-04-24 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found