diff options
| author | Scimon <simon.proctor@gmail.com> | 2024-01-02 14:58:14 +0000 |
|---|---|---|
| committer | Scimon <simon.proctor@gmail.com> | 2024-01-02 14:58:14 +0000 |
| commit | c0076b0001985bc9d540d84157454dc5e604af41 (patch) | |
| tree | 3212d84b3300dc7c44ff1798601ee6f8557dc575 | |
| parent | 8fc3b368ac11c9b264fc21c5ccf853e4b61118a6 (diff) | |
| download | perlweeklychallenge-club-c0076b0001985bc9d540d84157454dc5e604af41.tar.gz perlweeklychallenge-club-c0076b0001985bc9d540d84157454dc5e604af41.tar.bz2 perlweeklychallenge-club-c0076b0001985bc9d540d84157454dc5e604af41.zip | |
New year, back on the challenges
| -rw-r--r-- | challenge-250/simon-proctor/raku/ch-1.raku | 18 | ||||
| -rw-r--r-- | challenge-250/simon-proctor/raku/ch-2.raku | 29 |
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-250/simon-proctor/raku/ch-1.raku b/challenge-250/simon-proctor/raku/ch-1.raku new file mode 100644 index 0000000000..bbf5aab356 --- /dev/null +++ b/challenge-250/simon-proctor/raku/ch-1.raku @@ -0,0 +1,18 @@ +#!/usr/bin/env raku + +multi sub MAIN('test') { + use Test; + is smallest-index(0,1,2), 0; + is smallest-index(4,3,2,1), 2; + is smallest-index(1,2,3,4,5,6,7,8,9,0), -1; + done-testing; +} + +multi sub MAIN(*@vals) { + say smallest-index(|@vals); +} + +sub smallest-index(*@vals) { + my $min = @vals.grep( -> $v { $v % 10 ~~ @vals[$v] } ).min; + $min = $min ~~ Inf ?? -1 !! $min; +} diff --git a/challenge-250/simon-proctor/raku/ch-2.raku b/challenge-250/simon-proctor/raku/ch-2.raku new file mode 100644 index 0000000000..c411ee8dc3 --- /dev/null +++ b/challenge-250/simon-proctor/raku/ch-2.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +multi sub MAIN('test') { + use Test; + is alpha-string("perl"), 4; + is alpha-string("2"),2; + is alpha-string("000"),0; + is alpha-string("python"),6; + is alpha-string("r4ku"),4; + is alpha-string("001"),1; + is alpha-string("1"),1; + is alpha-string("000"),0; + is alpha-string("0001"),1; + is max-alpha("perl", "2", "000", "python", "r4ku"),6; + is max-alpha("001", "1", "000", "0001"), 1; + done-testing; +} + +multi sub MAIN(*@vals) { + max-alpha(|@vals).say; +} + +sub alpha-string($v) { + $v ~~ /^ \d+ $/ ?? $v.Int !! $v.codes; +} + +sub max-alpha(*@vals) { + @vals.map({alpha-string($_)}).max; +} |
