From 2d5c90ff101d935bafe7f2ca19a637335e652c4a Mon Sep 17 00:00:00 2001 From: Jan Krňávek Date: Sun, 13 Nov 2022 22:57:51 +0100 Subject: solutions week 190 --- challenge-190/wambash/raku/ch-1.raku | 19 +++++++++++++++++++ challenge-190/wambash/raku/ch-2.raku | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 challenge-190/wambash/raku/ch-1.raku create mode 100644 challenge-190/wambash/raku/ch-2.raku diff --git a/challenge-190/wambash/raku/ch-1.raku b/challenge-190/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..adffa1d7db --- /dev/null +++ b/challenge-190/wambash/raku/ch-1.raku @@ -0,0 +1,19 @@ +#!/usr/bin/env raku + +sub capital-detection ($s) { + $s + andthen .contains: / ^ [ <:LC> <:Ll>+ | <:Lu>+ ] $ / +} + +multi MAIN (Bool :test($)!) { + use Test; + is capital-detection('Perl'), True; + is capital-detection('TPRF'), True; + is capital-detection('PyThon'),False; + is capital-detection('raku'), True; + done-testing; +} + +multi MAIN ($s) { + say +capital-detection $s +} diff --git a/challenge-190/wambash/raku/ch-2.raku b/challenge-190/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..55d4ea667b --- /dev/null +++ b/challenge-190/wambash/raku/ch-2.raku @@ -0,0 +1,34 @@ +#!/usr/bin/env raku + +multi decode(Int(Str) $coded-char) { + chr $coded-char + 'A'.ord - 1 +} + +multi decode(+@coded-str) { + @coded-str + andthen .map: &decode + andthen .join +} + +sub decoded-list (Int(Str) $s) { + $s + andthen m:ex{ ^(\d|\d**2 )+$ } #> + andthen .map: *.[0]>>.Int + andthen .map: &decode + andthen .reverse +} + +multi MAIN (Bool :test($)!) { + use Test; + is decode(1),'A'; + is decode(26),'Z'; + is decode(1,7,15,26), 'AGOZ'; + is decoded-list(11), ('AA','K'); + is decoded-list(1115), ; + is decoded-list(127), ('ABG','LG'); + done-testing; +} + +multi MAIN (Int $s) { + put decoded-list $s +} -- cgit