Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Hofstadter Metapuzzle

by tadman (Prior)
on May 22, 2002 at 23:20 UTC ( #168615=note: print w/ replies, xml ) Need Help??


in reply to (OT) Hofstadter Metapuzzle

Thankfully, the statement doesn't "overflow" so this program works:

#!/usr/bin/perl -w use strict; my $statement = "The number of 0s in this sentence is _, of 1s is _, o +f 2s is _, of 3s is _, of 4s is _, of 5s is _, of 6s is _, of 7s is _ +, of 8s is _, and of 9s is _."; my @index; my $resume = 0; while (($resume = index($statement, "_", $resume)) && $resume > 0) { push (@index, $resume++); } my $changed; do { $changed = 0; for my $n (0 .. $#index) { my $count = (grep { /$n/ } split (//, $statement)); my $old_count = substr($statement, $index[$n], 1); if ($count ne $old_count) { substr($statement, $index[$n], 1) = $count; $changed++; } } } while ($changed); print $statement,"\n";
The great mystery is finally revealed. Golf anyone?


Comment on Re: Hofstadter Metapuzzle
Download Code
Re: Re: Hofstadter Metapuzzle
by MeowChow (Vicar) on May 22, 2002 at 23:51 UTC
    Nice work. Iterative processes are hit-or-miss with these sorts of problems, though. They depend on your initial state, can degenerate into cycles, and are not necessarily capable of producing all possible solutions. I wonder if this program can be tweaked to produce the second solution?
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
      Some puzzles like this don't settle into a steady state, leaving the logical equivalent of a "flip-flop" circuit, the classic paradoxical "This statement is false."-type problem, or two self-defeating, self-reinforcing arrangements like in the "Life" game.

      I think if you seed the initial statement differently, it might settle on a different possibility, though of course, this particular implementation uses the underscores for placement, so that will have to change.
        Sure, you can seed it with the second solution :)
           MeowChow                                   
                       s aamecha.s a..a\u$&owag.print
Re: Re: Hofstadter Metapuzzle
by jynx (Priest) on May 23, 2002 at 17:56 UTC

    Not counting the data section,

    i get a score of 128. i'm not counting the data section since anyone golfing will need the input, so it shouldn't be counted. That's my theory at least. Anyway, here's my attempt:

    #23456789_123456789_123456789_123456789_123456789_123456789_123456789_ $_=<DATA>;push@_,@+while/_/g;{for$a(0..$#_){substr($_,$_[$a]-1,1 )=$;,$|++if($;=@{[/$a/g]})!=substr$_,$_[$a]-1,1}$|--&&redo}print __DATA__ The number of 0s in this sentence is _, of 1s is _, of 2s is _, of 3s +is _, of 4 s is _, of 5s is _, of 6s is _, of 7s is _, of 8s is _, and of 9s is _ +.
    On the other hand, here's a much shorter 77 byte solution that's less interesting. It uses the same data section as above. Please note in both cases there should be no "\n"s in the data.
    sub{$a=<DATA>;$a=~s,($_.*?)_,$1.pop,efor-1..9;print$a}->(1,1,2,1,1,1,2 +,3,7,1)
    enjoy,
    jynx

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://168615]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2014-08-30 01:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls