Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: (OT) Hofstadter Metapuzzle

by hagus (Monk)
on May 23, 2002 at 10:30 UTC ( [id://168737]=note: print w/replies, xml ) Need Help??


in reply to (OT) Hofstadter Metapuzzle

Another solution for the hell of it. No idea how you would coax the second solution out of it. No matter how I tweak things (shotgun debugging :) it converges to the same answer. Hmm.

#!/usr/bin/perl use strict; use warnings; my @arr = (0..9); my %hash; @hash{@arr} = (0) x @arr; sub scanit { my $number = shift; my $cnt = 0; for (0..9) { foreach my $c (split //, $hash{$_}) { $cnt++ if ($number == $c); } } $cnt+1; } my $solcount=0; while (1) { my $cond = 0; # update the counts for (my $i=9; $i>=0; $i--) { my $cnt = scanit($i); $hash{$i} = $cnt; } # check whether our solution is valid. for (0..9) { my $cnt = scanit($_); $cond = 1 if ($hash{$_} != $cnt); } # print it if it is. if ($cond == 0) { my @print; for (1..9) { push @print, "of $_ "."s is $hash{$_}"; } print "The number of 0s in this sentence is $hash{0}, " . join(", ", @print) . "\n"; die; } else { $cond = 1; } }
--
Ash OS durbatulk, ash OS gimbatul,
Ash OS thrakatulk, agh burzum-ishi krimpatul!
Uzg-Microsoft-ishi amal fauthut burguuli.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2025-06-20 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.