diff options
110 files changed, 7150 insertions, 3160 deletions
diff --git a/challenge-248/wambash/raku/ch-1.raku b/challenge-248/wambash/raku/ch-1.raku new file mode 100644 index 0000000000..ca7faf8cb0 --- /dev/null +++ b/challenge-248/wambash/raku/ch-1.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +sub shortest-distance-index ($index, $str, $char) { + $str + andthen .indices: $char + andthen .map: { abs $_ - $index }\ + andthen .min +} + +sub shortest-distance ($str, $char) { + my $length = $str.chars; + + ^$length .map: *.&shortest-distance-index: $str, $char +} + +multi MAIN (Bool :test($)!) { + use Test; + is shortest-distance-index(3,'loveleetcode','l'), 1; + is shortest-distance-index(1,'loveleetcode','l'), 1; + is shortest-distance-index(0,'loveleetcode','c'), 8; + is shortest-distance-index(11,'loveleetcode','c'), 3; + is shortest-distance('loveleetcode','e'), (3,2,1,0,1,0,0,1,2,2,1,0); + is shortest-distance('aaab','b'), (3,2,1,0); + done-testing; +} + +multi MAIN ($str, $char) { + say shortest-distance $str, $char +} diff --git a/challenge-248/wambash/raku/ch-2.raku b/challenge-248/wambash/raku/ch-2.raku new file mode 100644 index 0000000000..acd7ab5310 --- /dev/null +++ b/challenge-248/wambash/raku/ch-2.raku @@ -0,0 +1,20 @@ +#!/usr/bin/env raku + + +sub submatrix-sum (+a) { + a + andthen .map: *.rotor( 2 => -1 ).map: *.sum + andthen .rotor: 2 => -1 + andthen .map: -> (@f, @s) { @f Z+ @s } +} + +multi MAIN (Bool :test($)!) { + use Test; + cmp-ok submatrix-sum((1...12).rotor(4)), &[~~], ((14,18,22),(30,34,38)); + cmp-ok submatrix-sum((1,0,0,0),(0,1,0,0),(0,0,1,0),(0,0,0,1)), &[~~], ((2,1,0),(1,2,1),(0,1,2)); + done-testing; +} + +multi MAIN (+a) { + say submatrix-sum +a +} diff --git a/challenge-249/arne-sommer/blog.txt b/challenge-249/arne-sommer/blog.txt new file mode 100644 index 0000000000..9c3ec53f8a --- /dev/null +++ b/challenge-249/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/equal-di.html diff --git a/challenge-249/arne-sommer/raku/ch-1.raku b/challenge-249/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..96989560ee --- /dev/null +++ b/challenge-249/arne-sommer/raku/ch-1.raku @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where @ints.elems %% 2 && @ints.elems > 0 && all(@ints) ~~ Int, :v(:$verbose)); + +my @output; +my @sorted = @ints>>.Int.sort; + +say ":Sorted: { @sorted.join(",") }" if $verbose; + +while @sorted +{ + my $first = @sorted.shift; + my $second = @sorted.shift; + + if $first == $second + { + @output.push: ($first, $second); + say ":Pair: $first,$second" if $verbose; + } + else + { + say ":Non-pair: $first,$second" if $verbose; + say "()"; + exit; + } +} + +say @output.map({ "($_[0], $_[1])"}).join(", "); diff --git a/challenge-249/arne-sommer/raku/ch-2.raku b/challenge-249/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..9f90401bc1 --- /dev/null +++ b/challenge-249/arne-sommer/raku/ch-2.raku @@ -0,0 +1,25 @@ +#! /usr/bin/env raku + +unit sub MAIN ($s where $s ~~ /^<[ID]>+$/, :v(:$verbose)); + +my @output; +my @integers = (0 .. $s.chars); + +for $s.comb -> $char +{ + if $char eq "I" + { + @output.push: @integers.shift; + say ":I -> lowest integer { @output.tail }" if $verbose; + } + else + { + @output.push: @integers.pop; + say ":D -> highest integer { @output.tail }" if $verbose; + } +} + +@output.push: @integers[0]; +say ": -> remaining integer { @output.tail }" if $verbose; + +say "({ @output.join(", ") })"; diff --git a/challenge-249/arne-sommer/raku/di-string-match b/challenge-249/arne-sommer/raku/di-string-match new file mode 100755 index 0000000000..9f90401bc1 --- /dev/null +++ b/challenge-249/arne-sommer/raku/di-string-match @@ -0,0 +1,25 @@ +#! /usr/bin/env raku + +unit sub MAIN ($s where $s ~~ /^<[ID]>+$/, :v(:$verbose)); + +my @output; +my @integers = (0 .. $s.chars); + +for $s.comb -> $char +{ + if $char eq "I" + { + @output.push: @integers.shift; + say ":I -> lowest integer { @output.tail }" if $verbose; + } + else + { + @output.push: @integers.pop; + say ":D -> highest integer { @output.tail }" if $verbose; + } +} + +@output.push: @integers[0]; +say ": -> remaining integer { @output.tail }" if $verbose; + +say "({ @output.join(", ") })"; diff --git a/challenge-249/arne-sommer/raku/equal-pairs b/challenge-249/arne-sommer/raku/equal-pairs new file mode 100755 index 0000000000..96989560ee --- /dev/null +++ b/challenge-249/arne-sommer/raku/equal-pairs @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where @ints.elems %% 2 && @ints.elems > 0 && all(@ints) ~~ Int, :v(:$verbose)); + +my @output; +my @sorted = @ints>>.Int.sort; + +say ":Sorted: { @sorted.join(",") }" if $verbose; + +while @sorted +{ + my $first = @sorted.shift; + my $second = @sorted.shift; + + if $first == $second + { + @output.push: ($first, $second); + say ":Pair: $first,$second" if $verbose; + } + else + { + say ":Non-pair: $first,$second" if $verbose; + say "()"; |
