aboutsummaryrefslogtreecommitdiff
path: root/challenge-242
diff options
context:
space:
mode:
authorlibrasteve <40125330+librasteve@users.noreply.github.com>2023-11-07 20:11:22 +0000
committerGitHub <noreply@github.com>2023-11-07 20:11:22 +0000
commit89f6be07a89a98d25f352f18850f24bf0ff7d985 (patch)
tree032ab890354b0bc8b876ee9e0ba23cda7f244d1a /challenge-242
parentc9d5f2834f979267d8d5db8fdaba52504a0c0b95 (diff)
parentdb4d9fe6bf77ff58c31ec3e9d2f71d8acf7d58d4 (diff)
downloadperlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.tar.gz
perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.tar.bz2
perlweeklychallenge-club-89f6be07a89a98d25f352f18850f24bf0ff7d985.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-242')
-rw-r--r--challenge-242/clifton-wood/raku/ch-1.raku10
-rw-r--r--challenge-242/clifton-wood/raku/ch-2.raku4
-rwxr-xr-xchallenge-242/e-choroba/perl/ch-1.pl26
-rwxr-xr-xchallenge-242/e-choroba/perl/ch-2.pl26
-rwxr-xr-xchallenge-242/eric-cheung/python/ch-1.py20
-rwxr-xr-xchallenge-242/eric-cheung/python/ch-2.py11
-rw-r--r--challenge-242/jeanluc2020/blog-1.txt1
-rw-r--r--challenge-242/jeanluc2020/blog-2.txt1
-rwxr-xr-xchallenge-242/jeanluc2020/perl/ch-1.pl62
-rwxr-xr-xchallenge-242/jeanluc2020/perl/ch-2.pl74
-rwxr-xr-xchallenge-242/jeanluc2020/python/ch-1.py66
-rwxr-xr-xchallenge-242/jeanluc2020/python/ch-2.py71
-rw-r--r--challenge-242/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-242/laurent-rosenfeld/perl/ch-1.pl21
-rw-r--r--challenge-242/laurent-rosenfeld/raku/ch-1.raku8
-rw-r--r--challenge-242/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-242/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-242/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-242/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-242/luca-ferrari/blog-5.txt1
-rw-r--r--challenge-242/luca-ferrari/blog-6.txt1
-rw-r--r--challenge-242/luca-ferrari/blog-7.txt1
-rw-r--r--challenge-242/luca-ferrari/blog-8.txt1
-rw-r--r--challenge-242/luca-ferrari/postgresql/ch-1.plperl37
-rw-r--r--challenge-242/luca-ferrari/postgresql/ch-1.sql35
-rw-r--r--challenge-242/luca-ferrari/postgresql/ch-2.plperl33
-rw-r--r--challenge-242/luca-ferrari/postgresql/ch-2.sql59
-rw-r--r--challenge-242/luca-ferrari/python/ch-1.py45
-rw-r--r--challenge-242/luca-ferrari/python/ch-2.py51
-rw-r--r--challenge-242/luca-ferrari/raku/ch-1.p621
-rw-r--r--challenge-242/luca-ferrari/raku/ch-2.p624
-rw-r--r--challenge-242/mark-anderson/raku/ch-1.raku12
-rw-r--r--challenge-242/mark-anderson/raku/ch-2.raku35
-rwxr-xr-xchallenge-242/mattneleigh/perl/ch-1.pl100
-rwxr-xr-xchallenge-242/mattneleigh/perl/ch-2.pl103
-rw-r--r--challenge-242/packy-anderson/README.md83
-rw-r--r--challenge-242/packy-anderson/blog.txt1
-rwxr-xr-xchallenge-242/packy-anderson/perl/ch-1.pl58
-rwxr-xr-xchallenge-242/packy-anderson/perl/ch-2.pl32
-rwxr-xr-xchallenge-242/packy-anderson/python/ch-1.py53
-rwxr-xr-xchallenge-242/packy-anderson/python/ch-2.py28
-rwxr-xr-xchallenge-242/packy-anderson/raku/ch-1.raku54
-rwxr-xr-xchallenge-242/packy-anderson/raku/ch-2.raku29
-rw-r--r--challenge-242/paulo-custodio/Makefile2
-rw-r--r--challenge-242/paulo-custodio/perl/ch-1.pl63
-rw-r--r--challenge-242/paulo-custodio/perl/ch-2.pl65
-rw-r--r--challenge-242/paulo-custodio/t/test-1.yaml10
-rw-r--r--challenge-242/paulo-custodio/t/test-2.yaml10
-rwxr-xr-xchallenge-242/perlboy1967/perl/ch-1.pl54
-rwxr-xr-xchallenge-242/perlboy1967/perl/ch-2.pl33
-rw-r--r--challenge-242/peter-campbell-smith/blog.txt1
-rwxr-xr-xchallenge-242/peter-campbell-smith/perl/ch-1.pl44
-rwxr-xr-xchallenge-242/peter-campbell-smith/perl/ch-2.pl50
-rw-r--r--challenge-242/pokgopun/go/ch-1.go76
-rw-r--r--challenge-242/pokgopun/go/ch-2.go88
-rw-r--r--challenge-242/pokgopun/python/ch-1.py55
-rw-r--r--challenge-242/pokgopun/python/ch-2.py57
-rw-r--r--challenge-242/robbie-hatley/blog.txt1
-rwxr-xr-xchallenge-242/robbie-hatley/perl/ch-1.pl142
-rwxr-xr-xchallenge-242/robbie-hatley/perl/ch-2.pl133
-rwxr-xr-xchallenge-242/roger-bell-west/javascript/ch-1.js65
-rwxr-xr-xchallenge-242/roger-bell-west/javascript/ch-2.js53
-rw-r--r--challenge-242/roger-bell-west/kotlin/ch-1.kt26
-rw-r--r--challenge-242/roger-bell-west/kotlin/ch-2.kt20
-rwxr-xr-xchallenge-242/roger-bell-west/lua/ch-1.lua85
-rwxr-xr-xchallenge-242/roger-bell-west/lua/ch-2.lua57
-rwxr-xr-xchallenge-242/roger-bell-west/perl/ch-1.pl25
-rwxr-xr-xchallenge-242/roger-bell-west/perl/ch-2.pl14
-rw-r--r--challenge-242/roger-bell-west/postscript/ch-1.ps171
-rw-r--r--challenge-242/roger-bell-west/postscript/ch-2.ps132
-rwxr-xr-xchallenge-242/roger-bell-west/python/ch-1.py30
-rwxr-xr-xchallenge-242/roger-bell-west/python/ch-2.py19
-rwxr-xr-xchallenge-242/roger-bell-west/raku/ch-1.p621
-rwxr-xr-xchallenge-242/roger-bell-west/raku/ch-2.p612
-rwxr-xr-xchallenge-242/roger-bell-west/ruby/ch-1.rb30
-rwxr-xr-xchallenge-242/roger-bell-west/ruby/ch-2.rb19
-rwxr-xr-xchallenge-242/roger-bell-west/rust/ch-1.rs32
-rwxr-xr-xchallenge-242/roger-bell-west/rust/ch-2.rs38
-rw-r--r--challenge-242/roger-bell-west/scala/ch-1.scala26
-rw-r--r--challenge-242/roger-bell-west/scala/ch-2.scala21
-rw-r--r--challenge-242/roger-bell-west/tests.yaml85
-rw-r--r--challenge-242/simon-proctor/raku/ch-1.raku25
-rwxr-xr-xchallenge-242/ulrich-rieke/cpp/ch-1.cpp59
-rwxr-xr-xchallenge-242/ulrich-rieke/cpp/ch-2.cpp62
-rwxr-xr-xchallenge-242/ulrich-rieke/haskell/ch-1.hs21
-rwxr-xr-xchallenge-242/ulrich-rieke/haskell/ch-2.hs32
-rwxr-xr-xchallenge-242/ulrich-rieke/perl/ch-1.pl29
-rwxr-xr-xchallenge-242/ulrich-rieke/perl/ch-2.pl40
-rwxr-xr-xchallenge-242/ulrich-rieke/raku/ch-1.raku22
-rwxr-xr-xchallenge-242/ulrich-rieke/raku/ch-2.raku34
-rwxr-xr-xchallenge-242/ulrich-rieke/rust/ch-1.rs29
-rwxr-xr-xchallenge-242/ulrich-rieke/rust/ch-2.rs41
-rw-r--r--challenge-242/wlmb/blog.txt1
-rwxr-xr-xchallenge-242/wlmb/perl/ch-1.pl22
-rwxr-xr-xchallenge-242/wlmb/perl/ch-2.pl16
-rw-r--r--challenge-242/zapwai/perl/ch-1.pl33
-rw-r--r--challenge-242/zapwai/perl/ch-2.pl20
97 files changed, 3596 insertions, 58 deletions
diff --git a/challenge-242/clifton-wood/raku/ch-1.raku b/challenge-242/clifton-wood/raku/ch-1.raku
new file mode 100644
index 0000000000..de234fc88c
--- /dev/null
+++ b/challenge-242/clifton-wood/raku/ch-1.raku
@@ -0,0 +1,10 @@
+my %h;
+my @a = <a b c>;
+my @b = <b c f>; %h{ |@a, |@b } »=» 1;
+my (@m-a, @m-b);
+for %h.keys {
+ @m-a.push: $_ unless @a.first($_).defined;
+ @m-b.push: $_ unless @b.first($_).defined;
+}
+@m-a.gist.say;
+@m-b.gist.say;
diff --git a/challenge-242/clifton-wood/raku/ch-2.raku b/challenge-242/clifton-wood/raku/ch-2.raku
new file mode 100644
index 0000000000..1831ded48e
--- /dev/null
+++ b/challenge-242/clifton-wood/raku/ch-2.raku
@@ -0,0 +1,4 @@
+my @matrix = ([1, 1, 0], [1, 0, 1], [0, 0, 0]);
+@matrix.map( *.reverse.map( *.not.Int ) ).gist.say
+
+
diff --git a/challenge-242/e-choroba/perl/ch-1.pl b/challenge-242/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..93b46b9b45
--- /dev/null
+++ b/challenge-242/e-choroba/perl/ch-1.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use Tie::IxHash;
+
+sub missing_members($arr1, $arr2) {
+ tie my %seen, 'Tie::IxHash';
+ for my $i (0, 1) {
+ $seen{$_}[$i] = 1 for @{ ($arr1, $arr2)[$i] };
+ }
+ my @missing = ([], []);
+ for my $e (keys %seen) {
+ push @{ $missing[ ! $seen{$e}[0] ] }, $e
+ unless 2 == grep $_, @{ $seen{$e} };
+ }
+ return \@missing
+}
+
+use Test2::V0;
+plan 2 + 1;
+
+is missing_members([1, 2, 3], [2, 4, 6]), [[1, 3], [4, 6]], 'Example 1';
+is missing_members([1, 2, 3, 3], [1, 1, 2, 2]), [[3], []], 'Example 2';
+is missing_members([1, 1, 2, 2], [1, 2, 3, 3]), [[], [3]], 'First empty';
diff --git a/challenge-242/e-choroba/perl/ch-2.pl b/challenge-242/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..199eb685ce
--- /dev/null
+++ b/challenge-242/e-choroba/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+use PDL;
+
+sub flip_matrix($m) {
+ ! pdl($m)->slice('-1:0:0')
+}
+
+use Test::More tests => 3;
+
+is_deeply flip_matrix("[1 1 0]\n[0 1 1]\n[0 0 1]")->unpdl,
+ [[1, 0, 0], [0, 0, 1], [0, 1, 1]],
+ 'Unnamed example';
+
+is_deeply flip_matrix([[1, 1, 0], [1, 0, 1], [0, 0, 0]])->unpdl,
+ [[1, 0, 0], [0, 1, 0], [1, 1, 1]],
+ 'Example 1';
+
+is_deeply flip_matrix(
+ [[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]]
+)->unpdl,
+ [[1, 1, 0, 0], [0, 1, 1, 0], [0, 0, 0, 1], [1, 0, 1, 0]],
+ 'Example 2';
diff --git a/challenge-242/eric-cheung/python/ch-1.py b/challenge-242/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..b3d79cc846
--- /dev/null
+++ b/challenge-242/eric-cheung/python/ch-1.py
@@ -0,0 +1,20 @@
+
+## Example 1
+## arrNum_01 = [1, 2, 3]
+## arrNum_02 = [2, 4, 6]
+
+## Example 2
+arrNum_01 = [1, 2, 3, 3]
+arrNum_02 = [1, 1, 2, 2]
+
+arrOutput = []
+
+arrOutput_01 = [nLoop for nLoop in list(set(arrNum_01)) if nLoop not in list(set(arrNum_02))]
+if len(arrOutput_01) > 0:
+ arrOutput.append(arrOutput_01)
+
+arrOutput_02 = [nLoop for nLoop in list(set(arrNum_02)) if nLoop not in list(set(arrNum_01))]
+if len(arrOutput_02) > 0:
+ arrOutput.append(arrOutput_02)
+
+print (arrOutput)
diff --git a/challenge-242/eric-cheung/python/ch-2.py b/challenge-242/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..9d487ad23a
--- /dev/null
+++ b/challenge-242/eric-cheung/python/ch-2.py
@@ -0,0 +1,11 @@
+
+arrMatrix = [[1, 1, 0], [0, 1, 1], [0, 0, 1]] ## Example 0
+## arrMatrix = [[1, 1, 0], [1, 0, 1], [0, 0, 0]] ## Example 1
+## arrMatrix = [[1, 1, 0, 0], [1, 0, 0, 1], [0, 1, 1, 1], [1, 0, 1, 0]] ## Example 2
+
+arrOutput = []
+
+for arrLoop in arrMatrix:
+ arrOutput.append([1 - nLoop for nLoop in arrLoop[::-1]])
+
+print (arrOutput)
diff --git a/challenge-242/jeanluc2020/blog-1.txt b/challenge-242/jeanluc2020/blog-1.txt
new file mode 100644
index 0000000000..3609be466d
--- /dev/null
+++ b/challenge-242/jeanluc2020/blog-1.txt
@@ -0,0 +1 @@
+http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-242-1.html
diff --git a/challenge-242/jeanluc2020/blog-2.txt b/challenge-242/jeanluc2020/blog-2.txt
new file mode 100644
index 0000000000..97547946a0
--- /dev/null
+++ b/challenge-242/jeanluc2020/blog-2.txt
@@ -0,0 +1 @@
+http://gott-gehabt.de/800_wer_wir_sind/thomas/Homepage/Computer/perl/theweeklychallenge-242-2.html
diff --git a/challenge-242/jeanluc2020/perl/ch-1.pl b/challenge-242/jeanluc2020/perl/ch-1.pl
new file mode 100755
index 0000000000..d3b7aaf045
--- /dev/null
+++ b/challenge-242/jeanluc2020/perl/ch-1.pl
@@ -0,0 +1,62 @@
+#!/usr/bin/perl
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-242/#TASK1
+#
+# Task 1: Missing Members
+# =======================
+#
+# 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).
+#
+############################################################
+##
+## discussion
+##
+############################################################
+#
+# For each element of each array, if it is not in the other array,
+# save it for the output.
+# Example 2 has a caveat though, by not returning an empty array in
+# case of no missing elements it is unclear in which of the arrays
+# the element was originally. It's better to return an empty array
+# here, so let's just do that instead.
+
+missing_members( [ 1, 2, 3 ], [ 2, 4, 6 ] );
+missing_members( [ 1, 2, 3, 3 ], [ 1, 1, 2, 2 ] );
+
+sub missing_members {
+ my ($arr1, $arr2) = @_;
+ print "Input: (" . join(", ", @$arr1) . "), (" . join(", ", @$arr2) . ")\n";
+ my (@res1, @res2, %keys1, %keys2);
+ map { $keys1{$_} = 1; } @$arr1;
+ map { $keys2{$_} = 1; } @$arr2;
+ my %seen = ();
+ foreach my $elem (@$arr1) {
+ push @res1, $elem unless $keys2{$elem} or $seen{$elem};
+ $seen{$elem} = 1;
+ }
+ %seen = ();
+ foreach my $elem (@$arr2) {
+ push @res2, $elem unless $keys1{$elem} or $seen{$elem};
+ $seen{$elem} = 1;
+ }
+ print "Output: ([" . join(", ", @res1) . "], [" . join(", ", @res2) . "])\n";
+}
diff --git a/challenge-242/jeanluc2020/perl/ch-2.pl b/challenge-242/jeanluc2020/perl/ch-2.pl
new file mode 100755
index 0000000000..ed69f9eab7
--- /dev/null
+++ b/challenge-242/jeanluc2020/perl/ch-2.pl
@@ -0,0 +1,74 @@
+#!/usr/bin/perl
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-242/#TASK2