diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2023-12-21 09:43:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-21 09:43:42 +0000 |
| commit | f89e715e4679d28318e8660608d44840a6468cbe (patch) | |
| tree | a465bedb1a1bbbe6380c3c169404bf4565b893c3 | |
| parent | 33f4358de5040ddc31b53689b6a781efbc2847c1 (diff) | |
| parent | ac10d33ad4be2763bba001150bef6e838d017546 (diff) | |
| download | perlweeklychallenge-club-f89e715e4679d28318e8660608d44840a6468cbe.tar.gz perlweeklychallenge-club-f89e715e4679d28318e8660608d44840a6468cbe.tar.bz2 perlweeklychallenge-club-f89e715e4679d28318e8660608d44840a6468cbe.zip | |
Merge pull request #9270 from jmaslak/master
Joelle Maslak Week 248
| -rw-r--r-- | challenge-248/joelle-maslak/raku/ch-1.raku | 42 | ||||
| -rw-r--r-- | challenge-248/joelle-maslak/raku/ch-2.raku | 37 |
2 files changed, 79 insertions, 0 deletions
diff --git a/challenge-248/joelle-maslak/raku/ch-1.raku b/challenge-248/joelle-maslak/raku/ch-1.raku new file mode 100644 index 0000000000..a9f3bedcfc --- /dev/null +++ b/challenge-248/joelle-maslak/raku/ch-1.raku @@ -0,0 +1,42 @@ +#!/usr/bin/env raku +use v6.d; + +# +# Copyright © 2023 Joelle Maslak +# All Rights Reserved - See License +# + +sub MAIN(Str:D $str = "loveleetcode", Str:D $char = "e") { + if $char.chars ≠ 1 { + say("You must provide exactly one letter as your character input."); + return 1; + } + my @c = $str.split("", :skip-empty); + my @positions; + for @c.kv -> $i, $letter { + @positions.push($i) if $letter eq $char; + } + + if @positions.elems == 0 { + say("The letter '$char' is not found."); + return 2; + } + + my $prev = @c.elems; + my $next = shift @positions; + my @output; + for @c.keys -> $i { + if $next == $i { + @output.push: 0; + $prev = $next; + $next = @positions.elems ?? shift @positions !! @c.elems; + } else { + @output.push: min abs($i - $prev), abs($next - $i); + } + } + + say "(" ~ @output.join(",") ~ ")"; + return 0; +} + + diff --git a/challenge-248/joelle-maslak/raku/ch-2.raku b/challenge-248/joelle-maslak/raku/ch-2.raku new file mode 100644 index 0000000000..5fa392d9d2 --- /dev/null +++ b/challenge-248/joelle-maslak/raku/ch-2.raku @@ -0,0 +1,37 @@ +#!/usr/bin/env raku +use v6.d; + +# +# Copyright © 2023 Joelle Maslak +# All Rights Reserved - See License +# + +sub MAIN(*@rows) { + my @a = gather { + if @rows.elems { + for @rows<> -> $row { + take $row.words.map({Int($^a)}).list; + } + } else { + for $*IN.lines() -> $row { + take $row.words.map({Int($^a)}).list; + } + } + } + + my $row-count = @a.elems(); + my $col-count = @a[0].elems(); + if @a.first( { $^a.elems ≠ $col-count } ) { + die("All rows must have the same number of elements"); + } + + my @b; + for 0..^($row-count - 1) -> $i { + @b.push: []; + for 0..^($col-count - 1) -> $k { + @b[*-1].push: [+] cross(($i, $i+1),($k, $k+1)).map( { @a[$^a[0]; $^a[1]] } ); + } + say join " ", @b[*-1].map: { sprintf("%4d", $^a) }; + } +} + |
