Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Euler#151 solution. Slow...
  • Loading branch information
shlomif committed May 6, 2015
1 parent 5754db0 commit 76e4e37
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions categories/euler/prob151-shlomif.p6
@@ -0,0 +1,37 @@
use v6;

my $total_num = 0;
my $sum = 0;

# rec is short for "recurse".
sub rec($factor, @counts, $result)
{
say @counts.join(",");
my $cnt = [+] @counts;
if $cnt == 0
{
$sum += $factor * $result;
$total_num += $factor;
}
else
{
for (@counts.kv) -> $size, $f
{
if $f > 0
{
my @c = @counts;
@c[$size]--;
for $size+1 .. 4 -> $s
{
@c[$s]++;
}
rec( $factor*$f/$cnt, @c, $result + ($cnt == 1) );
}
}
}
return;
}

rec(1,[1],0);

say "Result == ", ($sum / $total_num - 2).fmt("%.6f");

0 comments on commit 76e4e37

Please sign in to comment.