Boustrophedon transform: Difference between revisions
Content added Content deleted
m (→Python) |
(→{{header|Perl}}: use vecsum from ntheory (~4x faster) (Math::AnyNum::sum() would be even faster)) |
||
Line 707: | Line 707: | ||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
<syntaxhighlight lang="perl" line>use v5.36; use experimental <builtin for_list>; |
<syntaxhighlight lang="perl" line>use v5.36; use experimental <builtin for_list>; |
||
use ntheory <factorial lucasu nth_prime>; |
use ntheory <factorial lucasu nth_prime vecsum>; |
||
use List::Util 'head'; |
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 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) { |
sub boustrophedon_transform (@seq) { |
||
Line 718: | Line 716: | ||
my @bx = $seq[0]; |
my @bx = $seq[0]; |
||
for (my $c = 0; $c < @seq; $c++) { |
for (my $c = 0; $c < @seq; $c++) { |
||
@bx = reverse map { |
@bx = reverse map { vecsum head $_+1, $seq[$c], @bx } 0 .. $c; |
||
push @bt, $bx[0]; |
push @bt, $bx[0]; |
||
} |
} |
||
Line 762: | Line 760: | ||
1 2 5 17 73 381 2347 16701 134993 1222873 12279251 135425553 1627809401 21183890469 296773827547 |
1 2 5 17 73 381 2347 16701 134993 1222873 12279251 135425553 1627809401 21183890469 296773827547 |
||
100th term: 31807659526053444023..65546706672657314921 (157 digits)</pre> |
100th term: 31807659526053444023..65546706672657314921 (157 digits)</pre> |
||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--<syntaxhighlight lang="phix">--> |
<!--<syntaxhighlight lang="phix">--> |