diff options
Diffstat (limited to 'challenge-251')
| -rw-r--r-- | challenge-251/laurent-rosenfeld/blog.txt | 1 | ||||
| -rw-r--r-- | challenge-251/laurent-rosenfeld/perl/ch-1.pl | 18 | ||||
| -rw-r--r-- | challenge-251/laurent-rosenfeld/raku/ch-1.raku | 13 | ||||
| -rwxr-xr-x | challenge-251/perlboy1967/perl/ch-1.pl (renamed from challenge-251/perlboy1967/perl/ch1.pl) | 0 | ||||
| -rwxr-xr-x | challenge-251/perlboy1967/perl/ch-2.pl (renamed from challenge-251/perlboy1967/perl/ch2.pl) | 0 |
5 files changed, 32 insertions, 0 deletions
diff --git a/challenge-251/laurent-rosenfeld/blog.txt b/challenge-251/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..312e6abc5b --- /dev/null +++ b/challenge-251/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2024/01/perl-weekly-challenge-251-concatenation-value.html diff --git a/challenge-251/laurent-rosenfeld/perl/ch-1.pl b/challenge-251/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..8ff2ab1549 --- /dev/null +++ b/challenge-251/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,18 @@ +use strict; +use warnings; +use feature 'say'; + +sub concat_vals { + my @in = @_; + my $concat; + while (@in > 1) { + $concat += (shift @in) . (pop @in); + } + $concat += shift @in if @in > 0; # if we have 1 item left + return $concat; +} + +for my $test ([<6 12 25 1>], [<10 7 31 5 2 2>], [<1 2 10>]) { + printf "%-15s => ", "@$test"; + say concat_vals @$test; +} diff --git a/challenge-251/laurent-rosenfeld/raku/ch-1.raku b/challenge-251/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..341957a396 --- /dev/null +++ b/challenge-251/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,13 @@ +sub concat-vals (@in is copy) { + my $concat; + while @in.elems > 1 { + $concat += @in.shift ~ @in.pop; + } + $concat += shift @in if @in.elems > 0; # last item if any + return $concat; +} + +for <6 12 25 1>, <10 7 31 5 2 2>, <1 2 10> -> @test { + printf "%-15s => ", "@test[]"; + say concat-vals @test; +} diff --git a/challenge-251/perlboy1967/perl/ch1.pl b/challenge-251/perlboy1967/perl/ch-1.pl index 57f97135fc..57f97135fc 100755 --- a/challenge-251/perlboy1967/perl/ch1.pl +++ b/challenge-251/perlboy1967/perl/ch-1.pl diff --git a/challenge-251/perlboy1967/perl/ch2.pl b/challenge-251/perlboy1967/perl/ch-2.pl index 60cd0517ed..60cd0517ed 100755 --- a/challenge-251/perlboy1967/perl/ch2.pl +++ b/challenge-251/perlboy1967/perl/ch-2.pl |
