Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Do you know where your variables are?
 
PerlMonks  

Re: (OT) Hofstadter Metapuzzle

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.