aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMárton Polgár <37218286+2colours@users.noreply.github.com>2022-07-10 23:18:01 +0200
committerGitHub <noreply@github.com>2022-07-10 23:18:01 +0200
commitd917e83557936971ff484560e04ba34eb1a41789 (patch)
tree82cf5af9b753e6a5424743f96d50b240920e3862
parent0a9b85926bf1bc18770397f058fdb6e4aebebabd (diff)
downloadperlweeklychallenge-club-d917e83557936971ff484560e04ba34eb1a41789.tar.gz
perlweeklychallenge-club-d917e83557936971ff484560e04ba34eb1a41789.tar.bz2
perlweeklychallenge-club-d917e83557936971ff484560e04ba34eb1a41789.zip
Create ch-2.raku
-rw-r--r--challenge-172/2colours/raku/ch-2.raku18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-172/2colours/raku/ch-2.raku b/challenge-172/2colours/raku/ch-2.raku
new file mode 100644
index 0000000000..141a587750
--- /dev/null
+++ b/challenge-172/2colours/raku/ch-2.raku
@@ -0,0 +1,18 @@
+class IntSample does Associative {
+ has @!data;
+ submethod BUILD(:@data) {
+ @!data = sort @data;
+ }
+ method AT-KEY($scale) {
+ given $scale {
+ when Whatever { @!data[@!data - 1] }
+ when WhateverCode { @!data[.(@!data - 1)] }
+ when Int { @!data[$_] }
+ when * %% 0.5 { (.[$scale.floor] + .[$scale.ceiling]) / 2 given @!data }
+ default { @!data[.round] }
+ }
+ }
+
+}
+
+say IntSample.new(data => $*IN.lines>>.Int){0,*/4,*/2,* * 3/4, *}