diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-09 22:24:41 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-09 22:24:41 +0000 |
| commit | 8ec5e7a17b4aa0746626fd5356889f95e59c6b47 (patch) | |
| tree | 1405ed91099fef9ac1d1f95efefb2e1831d005c3 | |
| parent | 3a3a56faab94f54807236a9d53fb46990191a7ec (diff) | |
| parent | 00850929ecd605a3bfbf3a8d1bb21c71ec9150a7 (diff) | |
| download | perlweeklychallenge-club-8ec5e7a17b4aa0746626fd5356889f95e59c6b47.tar.gz perlweeklychallenge-club-8ec5e7a17b4aa0746626fd5356889f95e59c6b47.tar.bz2 perlweeklychallenge-club-8ec5e7a17b4aa0746626fd5356889f95e59c6b47.zip | |
Merge pull request #9379 from arnesom/branch-for-challenge-251
Arne Sommer
| -rw-r--r-- | challenge-251/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-251/arne-sommer/raku/ch-1.raku | 20 | ||||
| -rwxr-xr-x | challenge-251/arne-sommer/raku/ch-2.raku | 36 | ||||
| -rwxr-xr-x | challenge-251/arne-sommer/raku/concatenation-value | 20 | ||||
| -rwxr-xr-x | challenge-251/arne-sommer/raku/lucky-numbers | 36 |
5 files changed, 113 insertions, 0 deletions
diff --git a/challenge-251/arne-sommer/blog.txt b/challenge-251/arne-sommer/blog.txt new file mode 100644 index 0000000000..a331d2688b --- /dev/null +++ b/challenge-251/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/lucky-concatenation.html diff --git a/challenge-251/arne-sommer/raku/ch-1.raku b/challenge-251/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..92a6078c7d --- /dev/null +++ b/challenge-251/arne-sommer/raku/ch-1.raku @@ -0,0 +1,20 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where all(@ints) ~~ Int && @ints.elems > 0, :v(:$verbose)); + +my $output = 0; + +say ":Remaining:{ @ints.join(",") }" if $verbose; + +while @ints +{ + my $add = @ints.shift; + + $add ~= @ints.pop if @ints.elems; + + $output += $add; + + say ":Remaining:{ @ints.join(",") } - Add:$add (Total:$output)" if $verbose; +} + +say $output; diff --git a/challenge-251/arne-sommer/raku/ch-2.raku b/challenge-251/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..95127ebba3 --- /dev/null +++ b/challenge-251/arne-sommer/raku/ch-2.raku @@ -0,0 +1,36 @@ +#! /usr/bin/env raku + +unit sub MAIN (Str $matrix = "3 7 8 | 9 11 13 | 15 16 17", :v(:$verbose)); + +my @a = $matrix.split("|")>>.words>>.Int>>.Array; +my $rows = @a.elems; +my $cols = @a[0].elems; + +my @values = @a[*;*]; + +die "The rows must have the same size" unless [==] @a>>.elems; +die "Integers only" unless all(@values) ~~ Int; +die "Unique values only" unless @values.elems == @values.unique.elems; + +say ":Matrix: { @a.raku }" if $verbose; + +for 0 .. $rows -1 -> $row +{ + my @row = |@a[$row]; + my ($col, $min) = @row.minpairs.first.kv; + + say ":Row[$row]: { @row.join(",") } - lowest:$min (at column:$col)" if $verbose; + + my @col = @a[*;$col]; + my $max = @col.max; + + say ":- Col[$col]: { @col.join(",") } - highest:$max" if $verbose; + + if $max == $min + { + say $max; + exit; + } +} + +say "-1"; diff --git a/challenge-251/arne-sommer/raku/concatenation-value b/challenge-251/arne-sommer/raku/concatenation-value new file mode 100755 index 0000000000..92a6078c7d --- /dev/null +++ b/challenge-251/arne-sommer/raku/concatenation-value @@ -0,0 +1,20 @@ +#! /usr/bin/env raku + +unit sub MAIN (*@ints where all(@ints) ~~ Int && @ints.elems > 0, :v(:$verbose)); + +my $output = 0; + +say ":Remaining:{ @ints.join(",") }" if $verbose; + +while @ints +{ + my $add = @ints.shift; + + $add ~= @ints.pop if @ints.elems; + + $output += $add; + + say ":Remaining:{ @ints.join(",") } - Add:$add (Total:$output)" if $verbose; +} + +say $output; diff --git a/challenge-251/arne-sommer/raku/lucky-numbers b/challenge-251/arne-sommer/raku/lucky-numbers new file mode 100755 index 0000000000..95127ebba3 --- /dev/null +++ b/challenge-251/arne-sommer/raku/lucky-numbers @@ -0,0 +1,36 @@ +#! /usr/bin/env raku + +unit sub MAIN (Str $matrix = "3 7 8 | 9 11 13 | 15 16 17", :v(:$verbose)); + +my @a = $matrix.split("|")>>.words>>.Int>>.Array; +my $rows = @a.elems; +my $cols = @a[0].elems; + +my @values = @a[*;*]; + +die "The rows must have the same size" unless [==] @a>>.elems; +die "Integers only" unless all(@values) ~~ Int; +die "Unique values only" unless @values.elems == @values.unique.elems; + +say ":Matrix: { @a.raku }" if $verbose; + +for 0 .. $rows -1 -> $row +{ + my @row = |@a[$row]; + my ($col, $min) = @row.minpairs.first.kv; + + say ":Row[$row]: { @row.join(",") } - lowest:$min (at column:$col)" if $verbose; + + my @col = @a[*;$col]; + my $max = @col.max; + + say ":- Col[$col]: { @col.join(",") } - highest:$max" if $verbose; + + if $max == $min + { + say $max; + exit; + } +} + +say "-1"; |
