diff options
| author | Lucas Ransan <lucas@ransan.tk> | 2021-06-15 02:05:04 +0200 |
|---|---|---|
| committer | Lucas Ransan <lucas@ransan.tk> | 2021-06-15 10:35:11 +0200 |
| commit | a3e6903512e7724aabd32861216daa5fc501406e (patch) | |
| tree | 59ba4a430a7ba19b52a3ae4d2861cab98b5e88a5 | |
| parent | bab377cd85c27a372a72dd05949702c4e78f197b (diff) | |
| download | perlweeklychallenge-club-a3e6903512e7724aabd32861216daa5fc501406e.tar.gz perlweeklychallenge-club-a3e6903512e7724aabd32861216daa5fc501406e.tar.bz2 perlweeklychallenge-club-a3e6903512e7724aabd32861216daa5fc501406e.zip | |
Raku week 117 task 2
| -rwxr-xr-x | challenge-117/luc65r/raku/ch-2.raku | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-117/luc65r/raku/ch-2.raku b/challenge-117/luc65r/raku/ch-2.raku new file mode 100755 index 0000000000..f5ae5d6246 --- /dev/null +++ b/challenge-117/luc65r/raku/ch-2.raku @@ -0,0 +1,37 @@ +#!/usr/bin/env raku + +enum Move <H L R>; + +class Node { + also is Hash[Node, Move:D]; + + method dirs(Node:D: --> Iterable) { + gather { + for self.kv -> $k, $v { + with $v { + my @d = .dirs; + take $k ~ $_ for @d ?? @d !! ''; + } + } + } + } +} + +sub MAIN(UInt:D $size) { + my $top = construct-triangle($size); + .say for $top.dirs; +} + +sub construct-triangle(UInt:D $size --> Node) { + my Node @line; + for $size … 0 -> $j { + for 0 .. $j -> $i { + @line[$i] = Node.new( + (H) => try { @line[$i - 1] }, + (L) => @line[$i + 1], + (R) => @line[$i], + ); + } + } + @line[0] +} |
