diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-03-21 17:59:15 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-03-21 17:59:15 +0000 |
| commit | 8e95e94de527f8344f979dbb45b935139b1ddeb7 (patch) | |
| tree | 02f051923040a88ab2524f1cb0bccc84b9e32818 /challenge-261 | |
| parent | 8324f1a32086d3c296f2cc1aa2e2d36456213810 (diff) | |
| download | perlweeklychallenge-club-8e95e94de527f8344f979dbb45b935139b1ddeb7.tar.gz perlweeklychallenge-club-8e95e94de527f8344f979dbb45b935139b1ddeb7.tar.bz2 perlweeklychallenge-club-8e95e94de527f8344f979dbb45b935139b1ddeb7.zip | |
- Added solutions by Arne Sommer.
- Added solutions by Athanasius.
- Added solutions by PokGoPun.
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-261')
| -rw-r--r-- | challenge-261/laurent-rosenfeld/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-261/laurent-rosenfeld/perl/ch-2.pl | 17 | ||||
| -rw-r--r-- | challenge-261/laurent-rosenfeld/raku/ch-2.raku | 11 |
3 files changed, 29 insertions, 0 deletions
diff --git a/challenge-261/laurent-rosenfeld/blog1.txt b/challenge-261/laurent-rosenfeld/blog1.txt new file mode 100644 index 0000000000..83ce046aae --- /dev/null +++ b/challenge-261/laurent-rosenfeld/blog1.txt @@ -0,0 +1 @@ +https://blogs.perl.org/users/laurent_r/2024/03/perl-weekly-challenge-261-multiply-by-two.html diff --git a/challenge-261/laurent-rosenfeld/perl/ch-2.pl b/challenge-261/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..b77de6c889 --- /dev/null +++ b/challenge-261/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,17 @@ +use strict; +use warnings; +use feature 'say'; + +sub multiply_by_two { + my $start = shift; + die "$start cannot be 0" if $start == 0; + my %present = map { $_ => 1 } @_; + $start *= 2 while $present{$start}; + return $start; +} + +my @tests = ( [3, [5,3,6,1,12]], [1, [1,2,4,3]], [2, [5,6,7]] ); +for my $test (@tests) { + printf "%d - %-15s => ", $test->[0], "@{$test->[1]}"; + say multiply_by_two @$test[0], @{$test->[1]}; +} diff --git a/challenge-261/laurent-rosenfeld/raku/ch-2.raku b/challenge-261/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..67860cd2f3 --- /dev/null +++ b/challenge-261/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,11 @@ +sub multiply-by-two ($start is copy where * != 0, @in) { + my $bag = @in.Bag; + $start *= 2 while $bag{$start}; + return $start; +} + +my @tests = (3, (5,3,6,1,12)), (1, (1,2,4,3)), (2, (5,6,7)); +for @tests -> @test { + printf "%d - %-15s => ", @test[0], "@test[1]"; + say multiply-by-two @test[0], @test[1]; +} |
