aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2023-04-30 16:27:31 +0100
committerGitHub <noreply@github.com>2023-04-30 16:27:31 +0100
commitb501303c2e414a17b5d39a9bfe3832198a1203a7 (patch)
treef5a558798f8ccd6bbb8ec02caae73d1600369d0a
parente880ece2510e03fe9fc4bb81613bfbf9ae77c3b4 (diff)
parentd5b8ea4f4e751c853f7fab8fa0c3c41ce6127f9b (diff)
downloadperlweeklychallenge-club-b501303c2e414a17b5d39a9bfe3832198a1203a7.tar.gz
perlweeklychallenge-club-b501303c2e414a17b5d39a9bfe3832198a1203a7.tar.bz2
perlweeklychallenge-club-b501303c2e414a17b5d39a9bfe3832198a1203a7.zip
Merge pull request #7989 from wambash/challenge-week-214
solutions week 214-1
-rw-r--r--challenge-214/wambash/raku/ch-1.raku26
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-214/wambash/raku/ch-1.raku b/challenge-214/wambash/raku/ch-1.raku
new file mode 100644
index 0000000000..73610129a1
--- /dev/null
+++ b/challenge-214/wambash/raku/ch-1.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+enum M (<G S B>);
+
+multi rank-place (M(Int) $_){ $_ }
+multi rank-place (Int $_ where * > 2){ $_ + 1 }
+multi rank-place (+@place) { @place.map: &rank-place }
+
+sub rank-score (+@score) {
+ my %rank := @score.sort.reverse.antipairs.squish( as => *.key ).hash;
+
+ @score.map: { rank-place %rank{$_} }
+}
+
+multi MAIN (Bool :test($)!) {
+ use Test;
+ is rank-place(0,1,3,2,4),(G,S,4,B,5);
+ is rank-score(1,2,4,3,5),(5,4,S,B,G);
+ is rank-score(8,5,6,7,4),(G,4,B,S,5);
+ is rank-score(3,5,4,2) ,(B,G,S,4);
+ is rank-score(2,5,2,1,7,5,1),(4,S,4,6,G,S,6);
+ done-testing;
+}
+
+multi MAIN (*@score) {
+ say rank-score @score;
+}