diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-08-11 00:24:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-11 00:24:08 +0100 |
| commit | 87cd98ca2abcbcef67b3e9aa873c760adb25d363 (patch) | |
| tree | 7172e5ccee9220939a4bf40d0103cfa18a5b014a | |
| parent | b3d61dcc00dc21a997af9a4c9d8de69fba311062 (diff) | |
| parent | cfe29ff27ec7f39edbe6667444b11d76e66838a3 (diff) | |
| download | perlweeklychallenge-club-87cd98ca2abcbcef67b3e9aa873c760adb25d363.tar.gz perlweeklychallenge-club-87cd98ca2abcbcef67b3e9aa873c760adb25d363.tar.bz2 perlweeklychallenge-club-87cd98ca2abcbcef67b3e9aa873c760adb25d363.zip | |
Merge pull request #12493 from wambash/challenge-week-333
solutions week 333
| -rw-r--r-- | challenge-333/wambash/raku/ch-1.raku | 29 | ||||
| -rw-r--r-- | challenge-333/wambash/raku/ch-2.raku | 21 |
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-333/wambash/raku/ch-1.raku b/challenge-333/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..38641156f3 --- /dev/null +++ b/challenge-333/wambash/raku/ch-1.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +sub straight-line (+@list) { + my ($M, $N) = @list.squish( with => &[eqv] ); + return True without $N; + + my $a=$M[0]-$N[0]; + my $b=$M[1]-$N[1]; + + @list + andthen .map: {$b * .[0] - $a * .[1]}\ + andthen [==] $_ +} + +multi MAIN (Bool :test($)!) { + use Test; + is straight-line((2,1),(2,3),(2,5)), True; + is straight-line((1,4),(3,4),(10,4)), True; + is straight-line((0,0),(1,1),(2,3)), False; + is straight-line((1,1),(2,2),(3,3)), True; + is straight-line((1,1),(1,1),(1,1)), True; + is straight-line((1,1),(1,1),(2,2),(3,4)), False; + is straight-line((1_000_000,1_000_000),(2_000_000,2_000_000),(3_000_000,3_000_000)), True; + done-testing; +} + +multi MAIN (+list) { + say straight-line list.map: *.split(',').cache; +} diff --git a/challenge-333/wambash/raku/ch-2.raku b/challenge-333/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..10110f03ff --- /dev/null +++ b/challenge-333/wambash/raku/ch-2.raku @@ -0,0 +1,21 @@ +#!/usr/bin/env raku + +sub duplicate-zeros (+ints) { + ints + andthen .map: { $_ == 0 ?? slip 0,0 !! $_ }\ + andthen .head: ints.elems +} + +multi MAIN (Bool :test($)!) { + use Test; + is duplicate-zeros(1, 0, 2, 3, 0, 4, 5, 0), (1, 0, 0, 2, 3, 0, 0, 4); + is duplicate-zeros(1, 2, 3), (1, 2, 3,); + is duplicate-zeros(1, 2, 3, 0), (1, 2, 3,0); + is duplicate-zeros(0,0,1, 2), (0,0,0,0); + is duplicate-zeros(1, 2, 0, 3,4), (1, 2, 0,0,3); + done-testing; +} + +multi MAIN (+ints) { + put duplicate-zeros ints; +} |
