diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-04-03 01:11:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-03 01:11:16 +0100 |
| commit | 8db5cffaf71e1a4ed18bbbfb54aa01aecc010d62 (patch) | |
| tree | b14f322fc2b1a1c74628f27cd28eff8055297c24 | |
| parent | 1b4ec79803cd2a2c533a9d0f9bf66ee2bc2e8357 (diff) | |
| parent | a0f25ecb795323fb3c80ac0c4c4fd87b8067a38e (diff) | |
| download | perlweeklychallenge-club-8db5cffaf71e1a4ed18bbbfb54aa01aecc010d62.tar.gz perlweeklychallenge-club-8db5cffaf71e1a4ed18bbbfb54aa01aecc010d62.tar.bz2 perlweeklychallenge-club-8db5cffaf71e1a4ed18bbbfb54aa01aecc010d62.zip | |
Merge pull request #7839 from wambash/challenge-week-210
solution week 210-2
| -rw-r--r-- | challenge-210/wambash/raku/ch-2.raku | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/challenge-210/wambash/raku/ch-2.raku b/challenge-210/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..cd355bf9ca --- /dev/null +++ b/challenge-210/wambash/raku/ch-2.raku @@ -0,0 +1,39 @@ +#!/usr/bin/env raku + +subset Pos of Int where * > 0; +subset Neg of Int where * < 0; + +multi number-colision-iter ( [Pos $t,*@ll], [Neg $h,*@rl] ) { + with $t <=> -$h { + when More { ($t,|@ll), @rl } + when Less { @ll, ($h,|@rl) } + when Same { @ll, @rl } + } +} + +multi number-colision-iter ( @tll, [$h,*@rl] ) {($h,|@tll), @rl} + +sub number-colision (+@list) { + ((),@list), {number-colision-iter |$_ } ... *[1] eq Empty + andthen .tail + andthen .[0] + andthen .reverse +} + +multi MAIN (Bool :test($)!) { + use Test; + is number-colision-iter((2,), (3,-1)),((3,2),(-1,)); + is number-colision-iter((3, 2), (-1,)),((3,2),()); + is number-colision-iter((3, 2), (-4,)),((2,),(-4)); + is number-colision-iter((2,), (-4,)),((),(-4)); + is number-colision-iter((), (-4,)),((-4),()); + is number-colision(2,3,-1),(2,3); + is number-colision(2,3,-4),(-4); + is number-colision(1,-1),(); + is number-colision(3,2,-1,2,-1,-2,5,-4),(3,2,5); + done-testing; +} + +multi MAIN (*@list) { + put number-colision @list +} |
