diff options
| -rw-r--r-- | challenge-200/carlos-oliveira/raku/ch-1.raku | 13 | ||||
| -rw-r--r-- | challenge-200/carlos-oliveira/raku/ch-2.raku | 38 |
2 files changed, 51 insertions, 0 deletions
diff --git a/challenge-200/carlos-oliveira/raku/ch-1.raku b/challenge-200/carlos-oliveira/raku/ch-1.raku new file mode 100644 index 0000000000..40faa354f0 --- /dev/null +++ b/challenge-200/carlos-oliveira/raku/ch-1.raku @@ -0,0 +1,13 @@ +sub arithmetic-slices (Int:D @integers --> List:D[Int:D]) { + my @arithmetic-slices; + for @integers.combinations(3..*) -> @slice { + @slice ==> zip(@slice.tail(*-1)) + ==> map({ @_[0] - @_[1] }) + ==> my @diffs; + @arithmetic-slices.push: @slice if all(@diffs) == @diffs[0]; + } + return @arithmetic-slices; +} + +say arithmetic-slices (my Int @ = (1,2,3,4)); +say arithmetic-slices (my Int @ = (2)); diff --git a/challenge-200/carlos-oliveira/raku/ch-2.raku b/challenge-200/carlos-oliveira/raku/ch-2.raku new file mode 100644 index 0000000000..a8bc385eb3 --- /dev/null +++ b/challenge-200/carlos-oliveira/raku/ch-2.raku @@ -0,0 +1,38 @@ +sub draw-number-as-ascii (Int:D $number) { + my @encodings = $number.comb.map({ + given $_ { + when 0 { 'abcdef' } + when 1 { 'bc' } + when 2 { 'abdeg' } + when 3 { 'abcdg' } + when 4 { 'bcfg' } + when 5 { 'acdfg' } + when 6 { 'acdefg' } + when 7 { 'abc' } + when 8 { 'abcdefg' } + when 9 { 'abcfg' } + } + }); + my @ascii-matrix; + for @encodings -> $encoding { + sub three-segments (Str $left_segment, Str $bottom_segment, Str $right_segment, @lines where .elems == 3) { + my @chars = $encoding.contains($left_segment,) ?? '|' !! ' '; + @chars.push: ' '; + @chars.push: $encoding.contains($right_segment) ?? '|' !! ' '; + @ascii-matrix[$_].push: @chars.join for @lines[0..1]; + @chars[1] = '_____' if $encoding.contains($bottom_segment); + @ascii-matrix[@lines[2]].push: @chars.join; + } + @ascii-matrix[0].push: $encoding.contains('a') ?? ' _____ ' !! ' '; + three-segments 'f', 'g', 'b', 1..3; + three-segments 'e', 'd', 'c', 4..6; + } + for @ascii-matrix -> @line { + say @line.join: ' ' + } +} + +draw-number-as-ascii 200; +draw-number-as-ascii 198; +draw-number-as-ascii 987654321; +draw-number-as-ascii 123456789; |
