Boustrophedon transform: Difference between revisions

→‎{{header|Perl}}: use vecsum from ntheory (~4x faster) (Math::AnyNum::sum() would be even faster)
(→‎{{header|Perl}}: use vecsum from ntheory (~4x faster) (Math::AnyNum::sum() would be even faster))
Line 707:
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36; use experimental <builtin for_list>;
use ntheory <factorial lucasu nth_prime vecsum>;
use List::Util 'head';
use bigint;
 
sub abbr ($d) { my $l = length $d; $l < 41 ? $d : substr($d,0,20) . '..' . substr($d,-20) . " ($l digits)" }
sub sum (@a) { my $sum = Math::BigInt->bzero(); $sum += $_ for @a; $sum }
 
sub boustrophedon_transform (@seq) {
Line 718 ⟶ 716:
my @bx = $seq[0];
for (my $c = 0; $c < @seq; $c++) {
@bx = reverse map { sumvecsum head $_+1, $seq[$c], @bx } 0 .. $c;
push @bt, $bx[0];
}
Line 762 ⟶ 760:
1 2 5 17 73 381 2347 16701 134993 1222873 12279251 135425553 1627809401 21183890469 296773827547
100th term: 31807659526053444023..65546706672657314921 (157 digits)</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">-->
2,747

edits