From e67a6703eb0b6750672b3c0ed14e4b35d3f8c2a0 Mon Sep 17 00:00:00 2001 From: Util Date: Sun, 4 Sep 2022 15:59:58 -0500 Subject: Add TWC 180 solutions by Bruce Gray : Raku only. --- challenge-180/bruce-gray/raku/ch-1.raku | 14 ++++++++++++++ challenge-180/bruce-gray/raku/ch-2.raku | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 challenge-180/bruce-gray/raku/ch-1.raku create mode 100644 challenge-180/bruce-gray/raku/ch-2.raku diff --git a/challenge-180/bruce-gray/raku/ch-1.raku b/challenge-180/bruce-gray/raku/ch-1.raku new file mode 100644 index 0000000000..73ce6f55e9 --- /dev/null +++ b/challenge-180/bruce-gray/raku/ch-1.raku @@ -0,0 +1,14 @@ +sub first_unique_character_index ( Str $_ --> UInt ) { + my @c = .lc.comb; + my %h = @c.repeated.Set; + return @c.first: :k, * !~~ %h; +} + +my @tests = + 'Perl Weekly Challenge' => 0, + 'Long Live Perl' => 1, + 'abc abc' => 3, +; +use Test; +plan +@tests; +is first_unique_character_index(.key), .value for @tests; diff --git a/challenge-180/bruce-gray/raku/ch-2.raku b/challenge-180/bruce-gray/raku/ch-2.raku new file mode 100644 index 0000000000..55d7c638cc --- /dev/null +++ b/challenge-180/bruce-gray/raku/ch-2.raku @@ -0,0 +1,13 @@ +sub trim_list ( $i, @n ) { + return @n.grep: * > $i; +} + +my @tests = + ( 3, (1,4,2,3,5) , (4,5) ), + ( 4, (9,0,6,2,3,8,5) , (9,6,8,5) ), +; +use Test; +plan +@tests; +for @tests -> ( $i, $n, $expected ) { + is-deeply trim_list($i, $n), $expected; +} -- cgit