aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark <53903062+andemark@users.noreply.github.com>2023-04-26 04:42:41 +0000
committerMark <53903062+andemark@users.noreply.github.com>2023-04-26 04:42:41 +0000
commit05c74535ed438cd5875cff7acc9df7091c4df68a (patch)
tree168ff74bfb41aec582999a40cbcaa60dc3548b2f
parenta0d9ecf91bcc757cea259d0c869c50d8794d8edd (diff)
downloadperlweeklychallenge-club-05c74535ed438cd5875cff7acc9df7091c4df68a.tar.gz
perlweeklychallenge-club-05c74535ed438cd5875cff7acc9df7091c4df68a.tar.bz2
perlweeklychallenge-club-05c74535ed438cd5875cff7acc9df7091c4df68a.zip
ch-1.raku do-over
-rw-r--r--challenge-214/mark-anderson/raku/ch-1.raku19
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-214/mark-anderson/raku/ch-1.raku b/challenge-214/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..94051dcb01
--- /dev/null
+++ b/challenge-214/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,19 @@
+#!/usr/bin/env raku
+use Test;
+
+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>;
+is rank-score(<22 77 11 55 77 11 22 22 11 22 22>), <4 G 9 B G 9 4 4 9 4 4>;
+
+sub rank-score($list)
+{
+ my $b = $list.Bag;
+ my @a = [\+] flat 1, $b.sort(-*.key)>>.value;
+ my %h = <1 2 3> Z=> <G S B>;
+
+ @a .= map({ %h{$_} ?? %h{$_} !! $_ });
+ %h = $b.keys.sort(-*) Z=> @a;
+ $list.map({ %h{$_} })
+}