aboutsummaryrefslogtreecommitdiff
path: root/challenge-242
diff options
context:
space:
mode:
authorntovar <tovar.nelo@gmail.com>2023-11-13 10:19:21 -0500
committerntovar <tovar.nelo@gmail.com>2023-11-13 10:19:21 -0500
commit4333c415ec1503cffa0618876e2ded4f6eb2ce8d (patch)
tree00121627979e3bd168d6e1b14b873e2f6b1df575 /challenge-242
parent04f30726f8970a4ac098e39f897f8761ba6ee8f8 (diff)
parentaeed5ae2bdafdcf14de24d172392278b8ba0b44f (diff)
downloadperlweeklychallenge-club-4333c415ec1503cffa0618876e2ded4f6eb2ce8d.tar.gz
perlweeklychallenge-club-4333c415ec1503cffa0618876e2ded4f6eb2ce8d.tar.bz2
perlweeklychallenge-club-4333c415ec1503cffa0618876e2ded4f6eb2ce8d.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-242')
-rw-r--r--challenge-242/0rir/ch-1.raku73
-rw-r--r--challenge-242/0rir/ch-2.raku62
-rw-r--r--challenge-242/adam-russell/blog.txt1
-rw-r--r--challenge-242/adam-russell/blog1.txt1
-rw-r--r--challenge-242/adam-russell/javascript/ch-1.js33
-rw-r--r--challenge-242/adam-russell/javascript/ch-2.js14
-rw-r--r--challenge-242/adam-russell/perl/ch-1.pl58
-rw-r--r--challenge-242/adam-russell/perl/ch-2.pl30
-rw-r--r--challenge-242/adam-russell/prolog/ch-1.p8
-rw-r--r--challenge-242/adam-russell/prolog/ch-2.p7
-rw-r--r--challenge-242/adam-russell/r/ch-1.r18
-rw-r--r--challenge-242/adam-russell/r/ch-2.r28
-rw-r--r--challenge-242/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-242/arne-sommer/raku/ch-1.raku18
-rwxr-xr-xchallenge-242/arne-sommer/raku/ch-2.raku24
-rwxr-xr-xchallenge-242/arne-sommer/raku/flip-matrix24
-rwxr-xr-xchallenge-242/arne-sommer/raku/missing-members18
-rw-r--r--challenge-242/athanasius/perl/ch-1.pl196
-rw-r--r--challenge-242/athanasius/perl/ch-2.pl199
-rw-r--r--challenge-242/athanasius/raku/ch-1.raku215
-rw-r--r--challenge-242/athanasius/raku/ch-2.raku206
-rw-r--r--challenge-242/augiedb/blog.txt1
-rw-r--r--challenge-242/augiedb/perl/ch-1.pl56
-rw-r--r--challenge-242/barroff/julia/ch-1.jl14
-rw-r--r--challenge-242/barroff/julia/ch-2.jl13
-rw-r--r--challenge-242/barroff/nim/ch_1.nim28
-rw-r--r--challenge-242/barroff/nim/ch_2.nim24
-rw-r--r--challenge-242/barroff/raku/ch-1.p622
-rw-r--r--challenge-242/barroff/raku/ch-2.p620
-rw-r--r--challenge-242/bob-lied/README6
-rw-r--r--challenge-242/bob-lied/blog.txt1
-rw-r--r--challenge-242/bob-lied/perl/ch-1.pl96
-rw-r--r--challenge-242/bob-lied/perl/ch-2.pl112
-rw-r--r--challenge-242/bruce-gray/fsharp/ch-1.fsx29
-rw-r--r--challenge-242/bruce-gray/fsharp/ch-1_scary.fsx28
-rw-r--r--challenge-242/bruce-gray/fsharp/ch-2.fsx32
-rw-r--r--challenge-242/bruce-gray/raku/ch-1.raku15
-rw-r--r--challenge-242/bruce-gray/raku/ch-2.raku23
-rw-r--r--challenge-242/cheok-yin-fung/perl/ch-1.pl41
-rw-r--r--challenge-242/cheok-yin-fung/perl/ch-2.pl22
-rw-r--r--challenge-242/deadmarshal/blog.txt1
-rw-r--r--challenge-242/deadmarshal/perl/ch-1.pl15
-rw-r--r--challenge-242/deadmarshal/perl/ch-2.pl12
-rw-r--r--challenge-242/deadmarshal/raku/ch-1.raku10
-rw-r--r--challenge-242/deadmarshal/raku/ch-2.raku10
-rw-r--r--challenge-242/ianrifkin/README.md181
-rw-r--r--challenge-242/ianrifkin/blog.txt1
-rw-r--r--challenge-242/ianrifkin/perl/ch-1.pl98
-rw-r--r--challenge-242/ianrifkin/perl/ch-2.pl70
-rw-r--r--challenge-242/jo-37/Blog.md44
-rw-r--r--challenge-242/jo-37/blog.txt1
-rwxr-xr-xchallenge-242/jo-37/perl/ch-1.pl62
-rwxr-xr-xchallenge-242/jo-37/perl/ch-2.pl66
-rw-r--r--challenge-242/laurent-rosenfeld/blog1.txt1
-rw-r--r--challenge-242/laurent-rosenfeld/perl/ch-2.pl26
-rw-r--r--challenge-242/laurent-rosenfeld/raku/ch-2.raku15
-rw-r--r--challenge-242/lubos-kolouch/blog.txt1
-rw-r--r--challenge-242/lubos-kolouch/perl/ch-1.pl25
-rw-r--r--challenge-242/lubos-kolouch/perl/ch-2.pl12
-rw-r--r--challenge-242/lubos-kolouch/python/ch-1.py26
-rw-r--r--challenge-242/lubos-kolouch/python/ch-2.py29
-rw-r--r--challenge-242/lubos-kolouch/raku/ch-1.raku22
-rw-r--r--challenge-242/lubos-kolouch/raku/ch-2.raku11
-rw-r--r--challenge-242/massa/raku/ch-1.raku64
-rw-r--r--challenge-242/massa/raku/ch-2.raku72
-rw-r--r--challenge-242/matthias-muth/README.md183
-rw-r--r--challenge-242/matthias-muth/blog.txt1
-rw-r--r--challenge-242/matthias-muth/perl/TestExtractor.pm258
-rwxr-xr-xchallenge-242/matthias-muth/perl/ch-1.pl31
-rwxr-xr-xchallenge-242/matthias-muth/perl/ch-2.pl24
-rw-r--r--challenge-242/matthias-muth/perl/challenge-242.txt63
-rw-r--r--challenge-242/memark/blog.txt1
-rw-r--r--challenge-242/memark/uiua/ch-1.ua9
-rw-r--r--challenge-242/memark/uiua/ch-2.ua9
-rw-r--r--challenge-242/packy-anderson/README.md7
-rw-r--r--challenge-242/paulo-custodio/c/ch-1.c130
-rw-r--r--challenge-242/paulo-custodio/c/ch-2.c151
-rw-r--r--challenge-242/paulo-custodio/c/utarray.h252
-rw-r--r--challenge-242/paulo-custodio/cpp/ch-1.cpp101
-rw-r--r--challenge-242/paulo-custodio/cpp/ch-2.cpp128
-rw-r--r--challenge-242/paulo-custodio/perl/ch-2.pl41
-rwxr-xr-xchallenge-242/peter-meszaros/perl/ch-1.pl67
-rwxr-xr-xchallenge-242/peter-meszaros/perl/ch-2.pl58
-rw-r--r--challenge-242/roger-bell-west/blog.txt1
-rw-r--r--challenge-242/wambash/raku/ch-1.raku17
-rw-r--r--challenge-242/wambash/raku/ch-2.raku26
-rwxr-xr-xchallenge-242/wanderdoc/perl/ch-1.pl56
-rwxr-xr-xchallenge-242/wanderdoc/perl/ch-2.pl46
88 files changed, 4137 insertions, 215 deletions
diff --git a/challenge-242/0rir/ch-1.raku b/challenge-242/0rir/ch-1.raku
new file mode 100644
index 0000000000..62ca11361e
--- /dev/null
+++ b/challenge-242/0rir/ch-1.raku
@@ -0,0 +1,73 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉ ≡ ≢ «␤ » ∴
+use v6.d;
+use lib $?FILE.IO.cleanup.parent(2).add("lib");
+use Test;
+
+=begin comment
+242-1: Missing Members Submitted by: Mohammad S Anwar
+
+You are given two arrays of integers.
+Write a script to find out the missing members in each other arrays.
+
+Example 1
+Input: @arr1 = (1, 2, 3)
+ @arr2 = (2, 4, 6)
+Output: ([1, 3], [4, 6])
+
+(1, 2, 3) has 2 members (1, 3) missing in the array (2, 4, 6).
+(2, 4, 6) has 2 members (4, 6) missing in the array (1, 2, 3).
+Example 2
+Input: @arr1 = (1, 2, 3, 3)
+ @arr2 = (1, 1, 2, 2)
+Output: ([3])
+
+(1, 2, 3, 3) has 2 members (3, 3) missing in the array (1, 1, 2, 2). Since they are same, keep just one.
+(1, 1, 2, 2) has 0 member missing in the array (1, 2, 3, 3).
+=end comment
+
+=begin comment
+Often, I resist the idea that a string is the desired output. The given
+output is ambiguous for example 2, i.e. the @ary1 and @ary2 could be in
+@ary2, @ary1 order.
+
+=end comment
+
+my @Test =
+ # @a @b @exp @exp-shortened
+ (1, 2, 3), (2, 4, 6), ((1, 3), (4, 6)), ((1, 3), (4, 6),),
+ (1, 2, 3, 3), (1, 1, 2, 2), ((3,),()), ((3,),),
+ (1, 1, 2, 2), (1, 2, 3, 3), ((), (3,)), ((3,)),
+ (1, 1, 2, 2), (1, 1, 2, 2), ((),()), (),
+ (), (1,), ((), 1), (1,),
+ (1,), (), (1, ()), (1,),
+ (), (), ((),()), (),
+ ;
+
+plan @Test ÷ 2;
+
+# the logical change
+sub l-and-r-oj( @a, @b ) { # oj ~ outer join
+ ((@a (-) @b).keys.sort.List // () ), # Empty is a Slip ?
+ ((@b (-) @a).keys.sort.List // () );
+}
+
+# the presentation
+sub delete-empty( @l-and-r is copy --> List) {
+ if @l-and-r[1] ~~ () { @l-and-r.pop }
+ if @l-and-r[0] ~~ () { @l-and-r.shift }
+ @l-and-r;
+}
+
+
+for @Test -> @a, @b, @exp, @exp-shortened {
+ is l-and-r-oj(@a, @b), @exp, 'test';
+ is delete-empty(l-and-r-oj(@a, @b)), @exp-shortened, 'test';
+}
+done-testing;
+
+my @arr1 = (1, 2, 3, 3);
+my @arr2 = (1, 1, 2, 2);
+say "\nInput: @arr1 = @arr1.raku()\n @arr2 = @arr2.raku()\nOutput = ",
+ delete-empty(l-and-r-oj(@arr1, @arr2));
+exit;
diff --git a/challenge-242/0rir/ch-2.raku b/challenge-242/0rir/ch-2.raku
new file mode 100644
index 0000000000..ac2a53bbf7
--- /dev/null
+++ b/challenge-242/0rir/ch-2.raku
@@ -0,0 +1,62 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉ ≡ ≢ «␤ » ∴
+use v6.d;
+use lib $?FILE.IO.cleanup.parent(2).add("lib");
+use Test;
+
+=begin comment
+242-2: Flip Matrix Submitted by: Mohammad S Anwar
+You are given n x n binary matrix.
+
+Write a script to flip the given matrix as below.
+
+
+1 1 0
+0 1 1
+0 0 1
+
+a) Reverse each row
+
+0 1 1
+1 1 0
+1 0 0
+
+b) Invert each member
+
+1 0 0
+0 0 1
+0 1 1
+
+Example 1
+Input: @matrix = ([1, 1, 0], [1, 0, 1], [0, 0, 0])
+Output: ([1, 0, 0], [0, 1, 0], [1, 1, 1])
+Example 2
+Input: @matrix = ([1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0])
+Output: ([1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0])
+=end comment
+
+my @Test =
+ [[1, 1, 0], [1, 0, 1], [0, 0, 0]],
+ [[1, 0, 0], [0, 1, 0], [1, 1, 1]],
+ [[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]],
+ [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0]],
+;
+plan @Test ÷ 2;
+
+subset Matrix of Array;
+
+sub reverse-n-not( @a is copy --> Matrix ) {
+ @a.map( *.map( (!*).Int ).reverse.Array).Array
+}
+
+for @Test -> @in, @exp {
+ is reverse-n-not(@in), @exp, "";
+}
+done-testing;
+
+my @matrix = [[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]];
+say "\nInput @matrix = @matrix.raku()\nOutput: &reverse-n-not(@matrix).raku()";
+
+
+exit;
+
diff --git a/challenge-242/adam-russell/blog.txt b/challenge-242/adam-russell/blog.txt
new file mode 100644
index 0000000000..7778ddfedd
--- /dev/null
+++ b/challenge-242/adam-russell/blog.txt
@@ -0,0 +1 @@
+http://rabbitfarm.com/cgi-bin/blosxom/perl/2023/11/11 \ No newline at end of file
diff --git a/challenge-242/adam-russell/blog1.txt b/challenge-242/adam-russell/blog1.txt
new file mode 100644
index 0000000000..6557439598
--- /dev/null
+++ b/challenge-242/adam-russell/blog1.txt
@@ -0,0 +1 @@
+http://rabbitfarm.com/cgi-bin/blosxom/prolog/2023/11/11 \ No newline at end of file
diff --git a/challenge-242/adam-russell/javascript/ch-1.js b/challenge-242/adam-russell/javascript/ch-1.js
new file mode 100644
index 0000000000..86f57321a5
--- /dev/null
+++ b/challenge-242/adam-russell/javascript/ch-1.js
@@ -0,0 +1,33 @@
+class Ch1{
+ missingMembers(a1, a2){
+ let r = [];
+ r.push(
+ a1.filter(function(x){
+ return a2.findIndex(function(y){
+ return x === y;
+ }) === -1;
+ })
+ );
+ r.push(
+ a2.filter(function(x){
+ return a1.findIndex(function(y){
+ return x === y;
+ }) === -1;
+ })
+ );
+ let s = [];
+ r.forEach(function(x){
+ if(x.length > 0){
+ s.push(Array.from(new Set(x)));
+ }
+ });
+ return s;
+ }
+}
+let ch1 = new Ch1();
+console.log(
+ ch1.missingMembers([1, 2, 3], [2, 4, 6])
+);
+console.log(
+ ch1.missingMembers([1, 2, 3, 3], [1, 1, 2, 2])
+); \ No newline at end of file
diff --git a/challenge-242/adam-russell/javascript/ch-2.js b/challenge-242/adam-russell/javascript/ch-2.js
new file mode 100644
index 0000000000..4a4641f9e1
--- /dev/null
+++ b/challenge-242/adam-russell/javascript/ch-2.js
@@ -0,0 +1,14 @@
+class Ch2{
+ flipMatrix(m){
+ return m.map(function(row){
+ return row.reverse().map(x => ~x & 1);
+ });
+ }
+}
+let ch2 = new Ch2();
+console.log(
+ ch2.flipMatrix([[1, 1, 0], [1, 0, 1], [0, 0, 0]])
+);
+console.log(
+ ch2.flipMatrix([[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]])
+); \ No newline at end of file
diff --git a/challenge-242/adam-russell/perl/ch-1.pl b/challenge-242/adam-russell/perl/ch-1.pl
new file mode 100644
index 0000000000..a6ee05cfcf
--- /dev/null
+++ b/challenge-242/adam-russell/perl/ch-1.pl
@@ -0,0 +1,58 @@
+use v5.38;
+##
+# You are given two arrays of integers.
+# Write a script to find out the missing members in each other arrays.
+##
+use boolean;
+use Data::Dump q/pp/;
+sub missing_members{
+ my @r;
+ my($a0, $a1) = @_;
+ my $missing0 = [];
+ missing_members_r([@{$a0}], [@{$a1}], $missing0);
+ my $missing1 = [];
+ missing_members_r([@{$a1}], [@{$a0}], $missing1);
+ push @r, $missing0 if @{$missing0} > 0;
+ push @r, $missing1 if @{$missing1} > 0;
+ return @r;
+}
+
+sub missing_members_r{
+ my($a0, $a1, $missing, $seen) = @_;
+ $seen = [] if !defined($seen);
+ my $x = shift @{$a0};
+ push @{$missing}, $x if missing_r($x, [@{$a1}]) && !seen_r($x, $seen);
+ push @{$seen}, $x;
+ missing_members_r($a0, $a1, $missing, $seen) if @{$a0} > 0;
+}
+
+sub missing_r{
+ my($x, $a0) = @_;
+ return true if @{$a0} == 0;
+ if(@{$a0}){
+ my $y = shift @{$a0};
+ if($x == $y){
+ return false;
+ }
+ }
+ return missing_r($x, $a0);
+}
+
+sub seen_r{
+ my($x, $seen) = @_;
+ return false if @{$seen} == 0;
+ my $y = shift @{$seen};
+ if($x == $y){
+ return true;
+ }
+ return seen_r($x, $seen);
+}
+
+MAIN:{
+ my @array1 = (1, 2, 3);
+ my @array2 = (2, 4, 6);
+ say pp missing_members \@array1, \@array2;
+ @array1 = (1, 2, 3, 3);
+ @array2 = (1, 1, 2, 2);
+ say pp missing_members \@array1, \@array2;
+} \ No newline at end of file
diff --git a/challenge-242/adam-russell/perl/ch-2.pl b/challenge-242/adam-russell/perl/ch-2.pl
new file mode 100644
index 0000000000..63a70ca188
--- /dev/null
+++ b/challenge-242/adam-russell/perl/ch-2.pl
@@ -0,0 +1,30 @@
+use v5.38;
+##
+# You are given n x n binary matrix.
+# Write a script to flip the given matrix as below.
+# 1 1 0
+# 0 1 1
+# 0 0 1
+# a) Reverse each row
+# 0 1 1
+# 1 1 0
+# 1 0 0
+# b) Invert each member
+# 1 0 0
+# 0 0 1
+# 0 1 1
+##
+use Data::Dump q/pp/;
+sub flip_matrix{
+ return map {
+ my $row = $_;
+ [map {~$_ & 1} reverse @{$row}]
+ } @_;
+}
+
+MAIN:{
+ my @matrix = ([1, 1, 0], [1, 0, 1], [0, 0, 0]);
+ say pp flip_matrix @matrix;
+ @matrix = ([1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]);
+ say pp flip_matrix @matrix;
+} \ No newline at end of file
diff --git a/challenge-242/adam-russell/prolog/ch-1.p b/challenge-242/adam-russell/prolog/ch-1.p
new file mode 100644
index 0000000000..9691230ace
--- /dev/null
+++ b/challenge-242/adam-russell/prolog/ch-1.p
@@ -0,0 +1,8 @@
+missing(L, E, Member):-
+ (member(E, L), Member = nil);
+ (\+ member(E, L), Member = E).
+missing_members([List1, List2], [Missing1, Missing2]):-
+ maplist(missing(List2), List1, Missing1Nil),
+ delete(Missing1Nil, nil, Missing1),
+ maplist(missing(List1), List2, Missing2Nil),