Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
go ahead... be a heretic
 
PerlMonks  

Re: Improving Evolutionary Algorithm

by delirium (Chaplain)
on Feb 19, 2004 at 14:59 UTC ( [id://330337]=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 Improving Evolutionary Algorithm

Woo-hoo! More Hofstadter fans!

Strangely, the 9 10 digit problem is solvable without using genetic algorithms or any randomization functions. Here's a solution that just starts with each count at 0 and feeds the last counts into the next sentence, evaluates, and repeats until the sentence is truthful:

#!/usr/bin/perl use strict; use warnings; my @list = 0..9; my %hash; $hash{$_} = 0 for @list; my $valid = 0; my $test = ''; while (!$valid) { $valid = 1; $test = 'This sentence contains '; $test .= "$hash{$_} ${_}s, " for @list; $test .= '. - '; print $test; my %test_hash; for (@list) { $test_hash{$_} = eval("\$test =~ tr/$_//"); $valid = 0 if ($hash{$_} != $test_hash{$_}); $hash{$_} = $test_hash{$_}; } ($valid == 1) ? print "yes\n" : print "no\n"; }

I won't spoil this by printing the answer, but it only took 4 iterations to achieve.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://330337]
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.