From 3368166499ec496ca0a6c8564d0c33f65d4adc07 Mon Sep 17 00:00:00 2001 From: Jörg Sommrey <28217714+jo-37@users.noreply.github.com> Date: Sat, 20 Mar 2021 11:24:58 +0100 Subject: avoid elements outside pascal's triangle --- challenge-104/jo-37/perl/ch-1.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'challenge-104') 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 { -- cgit