diff options
| -rw-r--r-- | challenge-349/ash/raku/ch-1.raku | 12 | ||||
| -rw-r--r-- | challenge-349/ash/raku/ch-2.raku | 25 |
2 files changed, 37 insertions, 0 deletions
diff --git a/challenge-349/ash/raku/ch-1.raku b/challenge-349/ash/raku/ch-1.raku new file mode 100644 index 0000000000..d87b142308 --- /dev/null +++ b/challenge-349/ash/raku/ch-1.raku @@ -0,0 +1,12 @@ +# Task 1 of the Weekly Challenge 349 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-349/#TASK1 + +say str-power('textbook'); # 2 +say str-power('aaaaa'); # 5 +say str-power('hoorayyy'); # 3 +say str-power('x'); # 1 +say str-power('aabcccddeeffffghijjk'); # 4 + +sub str-power($s) { + ($s.match(/ (.) $0+ /, :g)>>.Str>>.chars || 1).max +} diff --git a/challenge-349/ash/raku/ch-2.raku b/challenge-349/ash/raku/ch-2.raku new file mode 100644 index 0000000000..a280885be9 --- /dev/null +++ b/challenge-349/ash/raku/ch-2.raku @@ -0,0 +1,25 @@ +# Task 2 of the Weekly Challenge 349 +# https://theweeklychallenge.org/blog/perl-weekly-challenge-349/#TASK2 + +say go('ULD'); # False +say go('ULDR'); # True +say go('UUURRRDDD'); # False +say go('UURRRDDLLL'); # True +say go('RRUULLDDRRUU'); # True + +sub go($path) { + my ($x, $y) = 0, 0; + + for $path.comb -> $step { + given $step { + when 'U' {$y++} + when 'D' {$y--} + when 'R' {$x++} + when 'L' {$x--} + } + + return True if $x == $y == 0; + } + + return False; +}
\ No newline at end of file |
