aboutsummaryrefslogtreecommitdiff
path: root/challenge-266
diff options
context:
space:
mode:
authorPacky Anderson <PackyAnderson@gmail.com>2024-05-06 23:41:04 -0400
committerGitHub <noreply@github.com>2024-05-06 23:41:04 -0400
commit8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b (patch)
tree4cc9a6443382d2a32208246c481cd566b6ea0142 /challenge-266
parente4a2c66b30346606d347ecc4a08b83b733797d2a (diff)
parentc1756b0e7aed0ad70fa63feb2565c69215c9d426 (diff)
downloadperlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.gz
perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.tar.bz2
perlweeklychallenge-club-8da3f7983b54d8c8eb96326f4d7f3d52f1a78d9b.zip
Merge branch 'manwar:master' into challenge-268
Diffstat (limited to 'challenge-266')
-rw-r--r--challenge-266/0rir/raku/ch-1.raku60
-rw-r--r--challenge-266/0rir/raku/ch-2.raku85
-rw-r--r--challenge-266/2colours/php/ch-1.php14
-rw-r--r--challenge-266/2colours/php/ch-2.php22
-rw-r--r--challenge-266/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-266/arne-sommer/raku/ch-1.raku16
-rwxr-xr-xchallenge-266/arne-sommer/raku/ch-2.raku42
-rwxr-xr-xchallenge-266/arne-sommer/raku/uncommon-words16
-rwxr-xr-xchallenge-266/arne-sommer/raku/x-matrix42
-rw-r--r--challenge-266/athanasius/perl/ch-1.pl203
-rw-r--r--challenge-266/athanasius/perl/ch-2.pl267
-rw-r--r--challenge-266/athanasius/raku/ch-1.raku193
-rw-r--r--challenge-266/athanasius/raku/ch-2.raku277
-rw-r--r--challenge-266/barroff/julia/ch-1.jl18
-rw-r--r--challenge-266/barroff/raku/ch-1.p632
-rw-r--r--challenge-266/barroff/raku/ch-2.p633
-rw-r--r--challenge-266/bob-lied/README6
-rw-r--r--challenge-266/bob-lied/perl/ch-1.pl58
-rw-r--r--challenge-266/bob-lied/perl/ch-2.pl165
-rw-r--r--challenge-266/bruce-gray/raku/ch-1.raku50
-rw-r--r--challenge-266/bruce-gray/raku/ch-2.raku88
-rw-r--r--challenge-266/cheok-yin-fung/perl/ch-1.pl31
-rw-r--r--challenge-266/cheok-yin-fung/perl/ch-2.pl46
-rw-r--r--challenge-266/dave-jacoby/perl/ch-1.pl32
-rw-r--r--challenge-266/dave-jacoby/perl/ch-2.pl60
-rw-r--r--challenge-266/deadmarshal/blog.txt1
-rw-r--r--challenge-266/deadmarshal/perl/ch-1.pl15
-rw-r--r--challenge-266/deadmarshal/perl/ch-2.pl31
-rw-r--r--challenge-266/deadmarshal/raku/ch-1.raku13
-rw-r--r--challenge-266/deadmarshal/raku/ch-2.raku26
-rw-r--r--challenge-266/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-266/jaldhar-h-vyas/perl/ch-1.pl21
-rwxr-xr-xchallenge-266/jaldhar-h-vyas/perl/ch-2.pl28
-rwxr-xr-xchallenge-266/jaldhar-h-vyas/raku/ch-1.raku11
-rwxr-xr-xchallenge-266/jaldhar-h-vyas/raku/ch-2.raku30
-rw-r--r--challenge-266/james-smith/perl/ch-1.pl8
-rw-r--r--challenge-266/james-smith/perl/ch-2.pl20
-rw-r--r--challenge-266/jeanluc2020/blog-1.txt1
-rw-r--r--challenge-266/jeanluc2020/blog-2.txt1
-rwxr-xr-xchallenge-266/jeanluc2020/perl/ch-1.pl67
-rwxr-xr-xchallenge-266/jeanluc2020/perl/ch-2.pl77
-rw-r--r--challenge-266/jo-37/blog.txt1
-rwxr-xr-xchallenge-266/jo-37/perl/ch-1.pl68
-rwxr-xr-xchallenge-266/jo-37/perl/ch-2.pl88
-rw-r--r--challenge-266/lance-wicks/perl/ch-1.sh1
-rw-r--r--challenge-266/lance-wicks/perl/lib/UCW.pm38
-rw-r--r--challenge-266/lance-wicks/perl/t/01-ucw.t24
-rw-r--r--challenge-266/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-266/laurent-rosenfeld/blog1.txt1
-rw-r--r--challenge-266/laurent-rosenfeld/perl/ch-1.pl18
-rw-r--r--challenge-266/laurent-rosenfeld/perl/ch-2.pl39
-rw-r--r--challenge-266/laurent-rosenfeld/raku/ch-1.raku12
-rw-r--r--challenge-266/laurent-rosenfeld/raku/ch-2.raku33
-rw-r--r--challenge-266/matthias-muth/README.md9
-rwxr-xr-xchallenge-266/matthias-muth/perl/ch-1.pl29
-rwxr-xr-xchallenge-266/matthias-muth/perl/ch-2.pl31
-rw-r--r--challenge-266/matthias-muth/perl/challenge-266.txt62
-rwxr-xr-xchallenge-266/mattneleigh/perl/ch-1.pl102
-rwxr-xr-xchallenge-266/mattneleigh/perl/ch-2.pl171
-rwxr-xr-xchallenge-266/nelo-tovar/bash/ch-1.sh63
-rw-r--r--challenge-266/nelo-tovar/perl/ch-1.pl46
-rw-r--r--challenge-266/nelo-tovar/perl/ch-2.pl60
-rw-r--r--challenge-266/packy-anderson/blog.txt2
-rw-r--r--[-rwxr-xr-x]challenge-266/packy-anderson/perl/ch-1.pl2
-rw-r--r--[-rwxr-xr-x]challenge-266/packy-anderson/perl/ch-2.pl2
-rw-r--r--[-rwxr-xr-x]challenge-266/packy-anderson/python/ch-1.py2
-rw-r--r--[-rwxr-xr-x]challenge-266/packy-anderson/python/ch-2.py2
-rw-r--r--[-rwxr-xr-x]challenge-266/packy-anderson/raku/ch-1.raku2
-rw-r--r--[-rwxr-xr-x]challenge-266/packy-anderson/raku/ch-2.raku2
-rw-r--r--challenge-266/pokgopun/go/ch-1.go88
-rw-r--r--challenge-266/pokgopun/go/ch-2.go143
-rw-r--r--challenge-266/pokgopun/python/ch-1.py57
-rw-r--r--challenge-266/pokgopun/python/ch-2.py103
-rw-r--r--challenge-266/reinier-maliepaard/perl/ch-2a.pl52
-rw-r--r--challenge-266/robbie-hatley/blog.txt1
-rwxr-xr-xchallenge-266/robbie-hatley/perl/ch-1.pl106
-rwxr-xr-xchallenge-266/robbie-hatley/perl/ch-2.pl149
-rw-r--r--challenge-266/roger-bell-west/blog.txt1
-rw-r--r--challenge-266/sgreen/README.md4
-rw-r--r--challenge-266/sgreen/blog.txt1
-rwxr-xr-xchallenge-266/sgreen/perl/ch-1.pl29
-rwxr-xr-xchallenge-266/sgreen/perl/ch-2.pl42
-rwxr-xr-xchallenge-266/sgreen/python/ch-1.py38
-rwxr-xr-xchallenge-266/sgreen/python/ch-2.py45
-rwxr-xr-xchallenge-266/sgreen/python/test.py43
-rwxr-xr-xchallenge-266/ulrich-rieke/cpp/ch-1.cpp57
-rwxr-xr-xchallenge-266/ulrich-rieke/cpp/ch-2.cpp72
-rwxr-xr-xchallenge-266/ulrich-rieke/haskell/ch-1.hs20
-rwxr-xr-xchallenge-266/ulrich-rieke/haskell/ch-2.hs37
-rwxr-xr-xchallenge-266/ulrich-rieke/perl/ch-1.pl24
-rwxr-xr-xchallenge-266/ulrich-rieke/perl/ch-2.pl64
-rwxr-xr-xchallenge-266/ulrich-rieke/raku/ch-1.raku19
-rwxr-xr-xchallenge-266/ulrich-rieke/rust/ch-1.rs29
-rwxr-xr-xchallenge-266/ulrich-rieke/rust/ch-2.rs58
-rw-r--r--challenge-266/wambash/raku/ch-1.raku20
-rw-r--r--challenge-266/wambash/raku/ch-2.raku41
-rwxr-xr-xchallenge-266/wanderdoc/perl/ch-1.pl83
-rwxr-xr-xchallenge-266/wanderdoc/perl/ch-2.pl81
98 files changed, 4609 insertions, 17 deletions
diff --git a/challenge-266/0rir/raku/ch-1.raku b/challenge-266/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..896c4e86dd
--- /dev/null
+++ b/challenge-266/0rir/raku/ch-1.raku
@@ -0,0 +1,60 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+266-1: Uncommon Words Submitted by: Mohammad Sajid Anwar
+You are given two sentences, $line1 and $line2.
+
+Write a script to find all uncommmon words in any order in the given two sentences. Return ('') if none found.
+
+A word is uncommon if it appears exactly once in one of the sentences and doesn’t appear in other sentence.
+
+Example 1
+Input: $line1 = 'Mango is sweet'
+ $line2 = 'Mango is sour'
+Output: ('sweet', 'sour')
+Example 2
+Input: $line1 = 'Mango Mango'
+ $line2 = 'Orange'
+Output: ('Orange')
+Example 3
+Input: $line1 = 'Mango is Mango'
+ $line2 = 'Orange is Orange'
+Output: ('')
+=end comment
+
+my @Test =
+ # in-a in-b result result-lc
+ 'Mango is sweet', 'Mango is sour', ('sweet', 'sour'), ('sweet', 'sour'),
+ 'Mango Mango', 'Orange', ('Orange',), ('orange',),
+ 'Mango is Mango', 'Orange is Orange', ('',), ('',),
+ '', '', ('',), ('',),
+;
+plan @Test ÷ 2;
+
+# ignore case by using .lc
+multi once-words( Bool :$lc!, *@word-text -->List) {
+ (@word-text.words».lc).Bag.grep( *.value == 1)».key;
+}
+# case sensitive
+multi once-words( *@word-text -->List) {
+ @word-text.words.Bag.grep( *.value == 1)».key;
+}
+
+for @Test -> $l1, $l2, @exp, @lc {
+ is once-words( $l1, $l2).sort, @exp.sort, "@exp[] <- $l1 / $l2";
+ is once-words( :lc, $l1, $l2).sort, @lc.sort, "@lc[] <- $l1 / $l2";
+}
+
+done-testing;
+
+my $line1 = 'Ripe mango is sweet';
+my $line2 = 'New mango is sour';
+say "\nInput: \$line1 = '$line1'\n"
+ ~ " \$line2 = '$line2'\nOutput: ",
+ $ = (once-words( $line1, $line2)».&( "'" ~ * ~ "'")) ~~ Empty
+ ?? "('')"
+ !! (once-words( $line1, $line2)».&( "'" ~ * ~ "'"));
+
diff --git a/challenge-266/0rir/raku/ch-2.raku b/challenge-266/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..0a415cec3b
--- /dev/null
+++ b/challenge-266/0rir/raku/ch-2.raku
@@ -0,0 +1,85 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+266-2: X Matrix Submitted by: Mohammad Sajid Anwar
+You are given a square matrix, $matrix.
+
+Write a script to find if the given matrix is X Matrix.
+
+A square matrix is an X Matrix if all the elements on the main diagonal and antidiagonal are non-zero and everything else are zero.
+
+Example 1
+Input: $matrix = [ [1, 0, 0, 2],
+ [0, 3, 4, 0],
+ [0, 5, 6, 0],
+ [7, 0, 0, 1],
+ ]
+Output: true
+
+=end comment
+
+my @Dead = [], [[,],] ;
+
+my @Test =
+ [ [1], ], True,
+ [ [0], ], False,
+ [ [1, 1], [2, 2], ], True,
+ [ [1, 0], [2, 2], ], False,
+ [ [1, 2, 3],
+ [4, 5, 6],
+ [7, 8, 9], ], False,
+ [ [1, 0, 3],
+ [0, 5, 0],
+ [7, 0, 9], ], True,
+ [ [1, 0, 2],
+ [0, 3, 0],
+ [4, 0, 5], ], True,
+ [ [1, 0, 0, 2],
+ [0, 3, 4, 0],
+ [0, 5, 6, 0],
+ [7, 0, 0, 1], ], True,
+;
+plan 2 + +@Test ÷ 2;
+
+multi is-X-matrix( [[],]) { die "what is that" }
+multi is-X-matrix( []) { die "unsatisfying" }
+multi is-X-matrix( @a -->Bool:D) {
+ my ( $x1,$x2) = 0, @a.end; # Set up tracking of main diag. loca.
+ my @X;
+ for @a -> @r {
+ @X = ($x1, $x2).squish.sort;
+ my @non-zed-loc = @r.grep( :k, * !~~ 0); # Get all non-zed loca
+ return False if +@non-zed-loc ≠ +@X; # Have wrong count of non-zed
+ return False if @non-zed-loc !~~ @X ; # Check diag values
+ ++ $x1;
+ -- $x2;
+ }
+ return True;
+}
+
+for @Test -> @in, $exp {
+ is is-X-matrix(@in), $exp, "$exp <- @in.raku()";
+}
+for @Dead -> @in {
+ dies-ok { is-X-matrix @in }, "@in.raku() No numbers";
+}
+
+
+sub display-matrix( $prefix, @matrix -->Str) {
+ my $ret = "$prefix [\n";
+ my $shift = $prefix.chars;
+ for @matrix -> @r {
+ $ret ~= ' ' x ($shift + 3) ~ @r.raku() ~ "\n";
+ }
+ $ret ~= ' ' x $shift ~ "]\n";
+ $ret;
+}
+done-testing;
+
+my @matrix = [ [1, 0, 0, 2], [0, 3, 4, 0], [0, 5, 6, 0], [7, 0, 0, 1], ];
+say display-matrix( "\nInput: @matrix = ", @matrix);
+say "Output: ", is-X-matrix( @matrix);
+
diff --git a/challenge-266/2colours/php/ch-1.php b/challenge-266/2colours/php/ch-1.php
new file mode 100644
index 0000000000..3079fd5dff
--- /dev/null
+++ b/challenge-266/2colours/php/ch-1.php
@@ -0,0 +1,14 @@
+<?php
+
+echo '$line1 = ';
+$line1 = preg_split('/\s+/', rtrim(fgets(STDIN)));
+echo '$line2 = ';
+$line2 = preg_split('/\s+/', rtrim(fgets(STDIN)));
+
+$word_frequencies = array_count_values($line1);
+foreach (array_count_values($line2) as $key => $value) {
+ @$word_frequencies[$key] += $value;
+}
+
+$solution = array_keys(array_filter($word_frequencies, fn($freq) => $freq === 1)) ?: [''];
+var_dump($solution);
diff --git a/challenge-266/2colours/php/ch-2.php b/challenge-266/2colours/php/ch-2.php
new file mode 100644
index 0000000000..c8f7064f37
--- /dev/null
+++ b/challenge-266/2colours/php/ch-2.php
@@ -0,0 +1,22 @@
+<?php
+
+$matrix = json_decode(file_get_contents('php://stdin'));
+$size = count($matrix[0]); # let's hope it's actually a square matrix...
+
+// all 0's except for those 2 - which may be one if it's the middle
+function is_row_compliant($row, $diagonal_position, $size)
+{
+ $is_middle = $diagonal_position === $size - 1 - $diagonal_position;
+ return @array_count_values($row)[0] === $size - ($is_middle ? 1 : 2) && $row[$diagonal_position] !== 0 && $row[$size - 1 - $diagonal_position] !== 0;
+}
+
+//[$diagonal_position, $solution] = array_reduce($matrix, fn ($state, $row) => [$state[0] + 1, $state[1] && is_row_compliant($row, $state[0], $size)], [0, true]); # is this really worth it? :D
+$solution = true;
+foreach ($matrix as $row_index => $row) {
+ if (!is_row_compliant($row, $row_index, $size)) {
+ $solution = false;
+ break;
+ }
+}
+
+var_dump($solution); \ No newline at end of file
diff --git a/challenge-266/arne-sommer/blog.txt b/challenge-266/arne-sommer/blog.txt
new file mode 100644
index 0000000000..28aabc6510
--- /dev/null
+++ b/challenge-266/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/uncommon-x.html
diff --git a/challenge-266/arne-sommer/raku/ch-1.raku b/challenge-266/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..a9b8fc4986
--- /dev/null
+++ b/challenge-266/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,16 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@