in reply to Project Euler (a series of challenging mathematical/computer programming problems)
my $max = .99; my $bouncy = 0; for (my $n=1; ; $n++) { my ($inc, $dec) = (0, 0); my @d = split //, $n; for (my $i=0; $i<@d-1; $i++) { if ($d[$i] < $d[$i+1]) { $inc++ } elsif ($d[$i] > $d[$i+1]) { $dec++ } } $bouncy++ if $inc and $dec; next if $max > $bouncy/$n; printf "n=%d: %%%f\n", $n, $bouncy/$n; last; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Project Euler (a series of challenging mathematical/computer programming problems)
by hv (Prior) on Feb 11, 2006 at 23:59 UTC | |
|
Re^2: Project Euler (a series of challenging mathematical/computer programming problems)
by mpolo (Chaplain) on Feb 12, 2006 at 17:18 UTC |