aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcarlos157oliveira <carlos157oliveira@gmail.com>2023-01-22 18:10:07 -0300
committercarlos157oliveira <carlos157oliveira@gmail.com>2023-01-22 18:45:58 -0300
commit0e82ba78225149c44998aaca0b8e7593dd209dfd (patch)
tree6eb17556f6c9cdd36d948d32fd9b18c9a2338be3
parent952f98a3d4e479992cd18e544ebb441a952f7159 (diff)
downloadperlweeklychallenge-club-0e82ba78225149c44998aaca0b8e7593dd209dfd.tar.gz
perlweeklychallenge-club-0e82ba78225149c44998aaca0b8e7593dd209dfd.tar.bz2
perlweeklychallenge-club-0e82ba78225149c44998aaca0b8e7593dd209dfd.zip
solution to challenge 200
-rw-r--r--challenge-200/carlos-oliveira/raku/ch-1.raku13
-rw-r--r--challenge-200/carlos-oliveira/raku/ch-2.raku38
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;