in reply to (OT) Hofstadter Metapuzzle
The great mystery is finally revealed. Golf anyone?#!/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";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Hofstadter Metapuzzle
by MeowChow (Vicar) on May 22, 2002 at 23:51 UTC | |
by tadman (Prior) on May 23, 2002 at 00:29 UTC | |
by MeowChow (Vicar) on May 23, 2002 at 00:45 UTC | |
Re: Re: Hofstadter Metapuzzle
by jynx (Priest) on May 23, 2002 at 17:56 UTC |