Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: (OT) Hofstadter Metapuzzle

by hagus (Monk)
on May 23, 2002 at 10:30 UTC ( #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.


Comment on Re: (OT) Hofstadter Metapuzzle
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2014-08-21 08:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (128 votes), past polls