diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2021-03-20 11:24:58 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2021-03-20 11:25:56 +0100 |
| commit | 3368166499ec496ca0a6c8564d0c33f65d4adc07 (patch) | |
| tree | 2d2c1efda1fde36c0b0c15828119a3a0d93922c7 /challenge-104/jo-37 | |
| parent | 19750d81e7350048af6c55560ead52cad5e2eebc (diff) | |
| download | perlweeklychallenge-club-3368166499ec496ca0a6c8564d0c33f65d4adc07.tar.gz perlweeklychallenge-club-3368166499ec496ca0a6c8564d0c33f65d4adc07.tar.bz2 perlweeklychallenge-club-3368166499ec496ca0a6c8564d0c33f65d4adc07.zip | |
avoid elements outside pascal's triangle
Diffstat (limited to 'challenge-104/jo-37')
| -rwxr-xr-x | challenge-104/jo-37/perl/ch-1.pl | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/challenge-104/jo-37/perl/ch-1.pl b/challenge-104/jo-37/perl/ch-1.pl index 83e366daa3..c06ed04f32 100755 --- a/challenge-104/jo-37/perl/ch-1.pl +++ b/challenge-104/jo-37/perl/ch-1.pl @@ -3,6 +3,7 @@ use v5.16; use Test2::V0; use Math::Prime::Util 'binomial'; +use Math::Utils 'ceil'; use List::Util 'reduce'; use experimental 'signatures'; @@ -34,7 +35,7 @@ EOS ### Input and Output -my $n = shift || 50; +my $n = shift // 50; if ($fusc) { say "fusc($n)=" x !!$verbose, fusc($n); } else { @@ -47,9 +48,11 @@ if ($fusc) { # Non-recursive implementation of fusc according to # http://oeis.org/A002487 sub fusc ($n) { - reduce {$a += $b % 2} 0, map binomial($_, $n - $_ - 1), 0 .. $n - 1; + reduce {$a += $b % 2} 0, map binomial($_, $n - $_ - 1), + ceil(($n - 1) / 2) .. $n - 1; } + ### Tests sub run_tests { |
