diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-16 18:24:07 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-16 18:24:07 +0000 |
| commit | 9d38db293e8a5fc5bc5958d1d26d662ae354f8af (patch) | |
| tree | e487227d5ecfa6167345134d4949634699bf8586 /challenge-252 | |
| parent | 7c939f3b32e5363f639a1a20acd17cf04b9e7fac (diff) | |
| parent | 30da28de6974e7dad3e917b89662285e683e92ac (diff) | |
| download | perlweeklychallenge-club-9d38db293e8a5fc5bc5958d1d26d662ae354f8af.tar.gz perlweeklychallenge-club-9d38db293e8a5fc5bc5958d1d26d662ae354f8af.tar.bz2 perlweeklychallenge-club-9d38db293e8a5fc5bc5958d1d26d662ae354f8af.zip | |
Merge pull request #9403 from Scimon/master
Challenge 252
Diffstat (limited to 'challenge-252')
| -rw-r--r-- | challenge-252/simon-proctor/raku/ch-1.raku | 26 | ||||
| -rw-r--r-- | challenge-252/simon-proctor/raku/ch-2.raku | 29 |
2 files changed, 55 insertions, 0 deletions
diff --git a/challenge-252/simon-proctor/raku/ch-1.raku b/challenge-252/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..79b880dc11 --- /dev/null +++ b/challenge-252/simon-proctor/raku/ch-1.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku + +#| Run the test suite +multi sub MAIN('test') { + use Test; + is specials(1,2,3,4), (1,2,4); + is squares(1,2,4), (1,4,16); + is specials(2, 7, 1, 19, 18, 3), (2,7,1,3); + done-testing; +} + +#| Find the sum of the special numbers +multi sub MAIN( + *@vars where all(@vars) ~~ Int #= List of integers +) { + say [+] squares(specials(|@vars)); +} + +sub specials(*@vars) { + @vars.grep({ @vars.elems %% ++$ }); +} + +sub squares(*@vars) { + @vars.map( *² ); +} + diff --git a/challenge-252/simon-proctor/raku/ch-2.raku b/challenge-252/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..b4cf5b3963 --- /dev/null +++ b/challenge-252/simon-proctor/raku/ch-2.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +#| Run test suite +multi MAIN('test') { + use Test; + is number-list(4), (-2,-1,1,2); + for (1..10) -> $n { + is ([+] number-list($n)), 0; + } + done-testing; +} + +#| give a list of unqiue integers that add up to zero +multi sub MAIN( + $n where Int #= List length +) { + number-list($n).join(', ').say; +} + +multi sub number-list( $n where $n %% 2 ) { + my $p = $n div 2; + my @neg = (-$p..^0).list; + my @pos = @neg.map(* * -1); + ( |@neg, |@pos ).sort; +} + +multi sub number-list($n) { + ( |number-list($n-1), 0 ).sort; +} |
