aboutsummaryrefslogtreecommitdiff
path: root/challenge-277
diff options
context:
space:
mode:
authorRyan Thompson <rjt-pl@users.noreply.github.com>2024-07-31 09:03:36 -0600
committerGitHub <noreply@github.com>2024-07-31 09:03:36 -0600
commit8ad894d37f0f4ef50a43241c4b2bf2a1cb6d37c1 (patch)
tree1c9f93dfd881614c5e29d50fdde54132ced01281 /challenge-277
parent7e59eae7a697c2d04e5b64fbef42b87e1a104544 (diff)
parente9916addb3e14008166982fce954d0dc8fd3bafa (diff)
downloadperlweeklychallenge-club-8ad894d37f0f4ef50a43241c4b2bf2a1cb6d37c1.tar.gz
perlweeklychallenge-club-8ad894d37f0f4ef50a43241c4b2bf2a1cb6d37c1.tar.bz2
perlweeklychallenge-club-8ad894d37f0f4ef50a43241c4b2bf2a1cb6d37c1.zip
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-277')
-rw-r--r--challenge-277/0rir/raku/ch-1.raku60
-rw-r--r--challenge-277/0rir/raku/ch-2.raku57
-rw-r--r--challenge-277/2colours/prolog/ch-1.p17
-rw-r--r--challenge-277/2colours/prolog/ch-2.p14
-rw-r--r--challenge-277/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-277/arne-sommer/raku/ch-1.raku20
-rwxr-xr-xchallenge-277/arne-sommer/raku/ch-2.raku20
-rwxr-xr-xchallenge-277/arne-sommer/raku/count-common20
-rwxr-xr-xchallenge-277/arne-sommer/raku/strong-pair20
-rw-r--r--challenge-277/athanasius/perl/ch-1.pl226
-rw-r--r--challenge-277/athanasius/perl/ch-2.pl283
-rw-r--r--challenge-277/athanasius/raku/ch-1.raku198
-rw-r--r--challenge-277/athanasius/raku/ch-2.raku234
-rw-r--r--challenge-277/atschneid/README.md462
-rw-r--r--challenge-277/atschneid/blog.txt1
-rwxr-xr-xchallenge-277/atschneid/c/ch-1.c154
-rw-r--r--challenge-277/atschneid/c/ch-2.c42
-rw-r--r--challenge-277/atschneid/c/makefile10
-rw-r--r--challenge-277/atschneid/erlang/ch_1.erl65
-rw-r--r--challenge-277/atschneid/erlang/ch_2.erl45
-rw-r--r--challenge-277/atschneid/perl/ch-1.pl41
-rw-r--r--challenge-277/atschneid/perl/ch-2.pl30
-rw-r--r--challenge-277/barroff/julia/ch-1.jl31
-rw-r--r--challenge-277/barroff/julia/ch-2.jl29
-rw-r--r--challenge-277/barroff/raku/ch-1.p625
-rw-r--r--challenge-277/barroff/raku/ch-2.p630
-rw-r--r--challenge-277/bob-lied/README6
-rw-r--r--challenge-277/bob-lied/perl/ch-1.pl73
-rw-r--r--challenge-277/bob-lied/perl/ch-2.pl74
-rw-r--r--challenge-277/bruce-gray/blog.txt1
-rw-r--r--challenge-277/bruce-gray/perl/ch-1.pl43
-rw-r--r--challenge-277/bruce-gray/perl/ch-2.pl94
-rw-r--r--challenge-277/bruce-gray/raku/ch-1.raku16
-rw-r--r--challenge-277/bruce-gray/raku/ch-2.raku174
-rwxr-xr-xchallenge-277/cheok-yin-fung/lisp/ch-2.lsp22
-rwxr-xr-xchallenge-277/cheok-yin-fung/perl/ch-1.pl26
-rwxr-xr-xchallenge-277/cheok-yin-fung/perl/ch-2.pl21
-rw-r--r--challenge-277/conor-hoekstra/bqn/ch-1.bqn (renamed from challenge-277/conor-hoekstra/ch-1.bqn)0
-rw-r--r--challenge-277/conor-hoekstra/bqn/ch-2.bqn (renamed from challenge-277/conor-hoekstra/ch-2.bqn)0
-rwxr-xr-xchallenge-277/feng-chang/raku/ch-1a.raku2
-rwxr-xr-xchallenge-277/feng-chang/raku/test.raku6
-rw-r--r--challenge-277/jaldhar-h-vyas/blog.txt1
-rwxr-xr-xchallenge-277/jaldhar-h-vyas/perl/ch-1.pl25
-rwxr-xr-xchallenge-277/jaldhar-h-vyas/perl/ch-2.pl43
-rwxr-xr-xchallenge-277/jaldhar-h-vyas/raku/ch-1.sh3
-rwxr-xr-xchallenge-277/jaldhar-h-vyas/raku/ch-2.sh3
-rw-r--r--challenge-277/jeanluc2020/blog-1.txt1
-rw-r--r--challenge-277/jeanluc2020/blog-2.txt1
-rwxr-xr-xchallenge-277/jeanluc2020/perl/ch-1.pl69
-rwxr-xr-xchallenge-277/jeanluc2020/perl/ch-2.pl69
-rw-r--r--challenge-277/jo-37/blog.txt1
-rwxr-xr-xchallenge-277/jo-37/perl/ch-1.pl87
-rwxr-xr-xchallenge-277/jo-37/perl/ch-2.pl71
-rw-r--r--challenge-277/kjetillll/perl/ch-1.pl26
-rw-r--r--challenge-277/kjetillll/perl/ch-2.pl16
-rw-r--r--challenge-277/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-10.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-3.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-4.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-5.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-6.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-7.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-8.txt1
-rw-r--r--challenge-277/luca-ferrari/blog-9.txt1
-rw-r--r--challenge-277/luca-ferrari/pljava/pom.xml6
-rw-r--r--challenge-277/luca-ferrari/pljava/src/main/java/Task1.java27
-rw-r--r--challenge-277/luca-ferrari/pljava/src/main/java/Task2.java15
-rw-r--r--challenge-277/luca-ferrari/plperl/ch-1.plperl28
-rw-r--r--challenge-277/luca-ferrari/plperl/ch-2.plperl30
-rw-r--r--challenge-277/luca-ferrari/plpgsql/ch-1.sql25
-rw-r--r--challenge-277/luca-ferrari/plpgsql/ch-2.sql28
-rw-r--r--challenge-277/luca-ferrari/python/ch-1.py41
-rw-r--r--challenge-277/luca-ferrari/python/ch-2.py21
-rw-r--r--challenge-277/luca-ferrari/raku/ch-1.raku12
-rw-r--r--challenge-277/luca-ferrari/raku/ch-2.raku11
-rw-r--r--challenge-277/matthias-muth/README.md2
-rw-r--r--challenge-277/matthias-muth/blog.txt1
-rwxr-xr-xchallenge-277/matthias-muth/perl/ch-1.pl63
-rwxr-xr-xchallenge-277/matthias-muth/perl/ch-2.pl43
-rwxr-xr-xchallenge-277/nelo-tovar/bash/ch-1.sh56
-rwxr-xr-xchallenge-277/nelo-tovar/bash/ch-2.sh75
-rw-r--r--challenge-277/nelo-tovar/perl/ch-1.pl42
-rw-r--r--challenge-277/nelo-tovar/perl/ch-2.pl43
-rw-r--r--challenge-277/robbie-hatley/blog.txt1
-rwxr-xr-xchallenge-277/robbie-hatley/perl/ch-1.pl117
-rwxr-xr-xchallenge-277/robbie-hatley/perl/ch-2.pl88
-rw-r--r--challenge-277/roger-bell-west/blog.txt1
-rwxr-xr-xchallenge-277/roger-bell-west/perl/ch-1.pl19
-rwxr-xr-xchallenge-277/roger-bell-west/perl/ch-2.pl25
-rw-r--r--challenge-277/roger-bell-west/postscript/ch-1.ps96
-rw-r--r--challenge-277/roger-bell-west/postscript/ch-2.ps219
-rwxr-xr-xchallenge-277/roger-bell-west/raku/ch-1.p619
-rwxr-xr-xchallenge-277/roger-bell-west/raku/ch-2.p613
-rwxr-xr-xchallenge-277/roger-bell-west/rust/ch-1.rs42
-rwxr-xr-xchallenge-277/roger-bell-west/rust/ch-2.rs23
-rw-r--r--challenge-277/roger-bell-west/tests.json40
-rw-r--r--challenge-277/sgreen/README.md4
-rw-r--r--challenge-277/sgreen/blog.txt1
-rwxr-xr-xchallenge-277/sgreen/perl/ch-1.pl33
-rwxr-xr-xchallenge-277/sgreen/perl/ch-2.pl26
-rwxr-xr-xchallenge-277/sgreen/python/ch-1.py32
-rwxr-xr-xchallenge-277/sgreen/python/ch-2.py27
-rwxr-xr-xchallenge-277/sgreen/python/test.py32
-rw-r--r--challenge-277/wambash/raku/ch-1.raku21
-rw-r--r--challenge-277/wambash/raku/ch-2.raku20
-rwxr-xr-xchallenge-277/wanderdoc/perl/ch-1.pl65
-rwxr-xr-xchallenge-277/wanderdoc/perl/ch-2.pl51
108 files changed, 4451 insertions, 252 deletions
diff --git a/challenge-277/0rir/raku/ch-1.raku b/challenge-277/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..dcdb976844
--- /dev/null
+++ b/challenge-277/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
+277-1: Count Common Submitted by: Mohammad Sajid Anwar
+You are given two array of strings, @words1 and @words2. Return the count
+of words that appears in both arrays exactly once.
+
+Example 1
+Input: @words1 = ("Perl", "is", "my", "friend")
+ @words2 = ("Perl", "and", "Raku", "are", "friend")
+Output: 2
+
+The words "Perl" and "friend" appear once in each array.
+Example 2
+Input: @words1 = ("Perl", "and", "Python", "are", "very", "similar")
+ @words2 = ("Python", "is", "top", "in", "guest", "languages")
+Output: 1
+Example 3
+Input: @words1 = ("Perl", "is", "imperative", "Lisp", "is", "functional")
+ @words2 = ("Crystal", "is", "similar", "to", "Ruby")
+Output: 0
+
+=end comment
+
+my @Test =
+ # exe list / list
+ 0, (), (),
+ 0, (), < Pi is positive and is long >,
+ 1, ('red',), ('Red', 'dog'),
+ 2, ("Perl", "is", "my", "friend"),
+ ("Perl", "and", "Raku", "are", "friend"),
+ 1, ("Perl", "and", "Python", "are", "very", "similar"),
+ ("Python", "is", "top", "in", "guest", "languages"),
+ 0, ("Perl", "is", "imperative", "Lisp", "is", "functional"),
+ ("Crystal", "is", "similar", "to", "Ruby"),
+;
+plan @Test ÷ 3;
+
+sub task( @a, @b --> Int) {
+ ( (@a».fc).BagHash.grep( *.value == 1 )
+ ∩
+ (@b».fc).BagHash.grep( *.value == 1 )
+ ).elems;
+}
+
+for @Test -> $exp, @a, @b, {
+ is task(@a, @b), $exp, "$exp <- @a[] +/+ @b[]";
+}
+
+done-testing;
+
+my @word1 = < I am positive>;
+my @word2 = < Pi is positive>;
+
+say "\nInput: @words1 = @word1.List.raku()"
+ ~ "\n @words2 = @word2.List.raku()"
+ ~ "\n Output: ", task(@word1, @word2);
diff --git a/challenge-277/0rir/raku/ch-2.raku b/challenge-277/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..beed29ebc8
--- /dev/null
+++ b/challenge-277/0rir/raku/ch-2.raku
@@ -0,0 +1,57 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+277-2: Strong Pair Submitted by: Mohammad Sajid Anwar
+Given an array of integers, @ints. Return the count of all strong
+pairs in the given array.
+
+A pair of integers x and y is called strong pair if it satisfies:
+ 0 < |x - y| < min(x, y).
+
+Example 1
+Input: @ints = (1, 2, 3, 4, 5)
+Ouput: 4
+
+Strong Pairs: (2, 3), (3, 4), (3, 5), (4, 5)
+Example 2
+Input: @ints = (5, 7, 1, 7)
+Ouput: 1
+
+Strong Pairs: (5, 7)
+=end comment
+
+my @Test =
+ # exp in
+ Int, List,
+ Int, Array,
+ 0, (),
+ 0, (1,),
+ 0, (1,-1),
+ 4, (1, 2, 3, 4, 5),
+ 1, (5, 7, 1, 7),
+ 1, (2, 3),
+ 0, (1, 2),
+ 0, (1, 30,),
+;
+plan @Test ÷ 2;
+
+only task( @in -->Int) {
+ return Int unless @in.defined;
+ my @a = @in.grep( * > 1).unique;
+ return 0 if +@a == (0,1).any;
+ +@a.combinations(2).grep( { 0 < ($_[0] - $_[1]).abs < $_.min});
+}
+
+for @Test -> $exp, @in {
+ is task(@in), $exp, "$exp.gist() <- @in.gist()";
+}
+
+done-testing;
+
+# 0 < |x - y| < min(x, y).
+my @int = ( -9, -7, -5, 0, 0, 1, 1, 2, 5, 7, 8, 8);
+say "\nInput: @ints = @int.raku()\nOuput: &task(@int)";
+
diff --git a/challenge-277/2colours/prolog/ch-1.p b/challenge-277/2colours/prolog/ch-1.p
new file mode 100644
index 0000000000..e02e5b8728
--- /dev/null
+++ b/challenge-277/2colours/prolog/ch-1.p
@@ -0,0 +1,17 @@
+build_uniq_assoc(Value, Assoc_Before, Assoc_After) :-
+ put_assoc(Value, Assoc_Before, Valid_After, Assoc_After),
+ (get_assoc(Value, Assoc_Before, _Valid_Before) ->
+ Valid_After = false ;
+ Valid_After = true).
+
+task1(Words1, Words2, Nr_Common_Once) :-
+ empty_assoc(E),
+ maplist([Words, Result_Assoc]>>foldl(build_uniq_assoc, Words, E, Result_Assoc), [Words1, Words2], [Unique_Assoc1, Unique_Assoc2]),
+ findall([Word], (
+ gen_assoc(Word, Unique_Assoc1, Valid1),
+ get_assoc(Word, Unique_Assoc2, Valid2),
+ Valid1 == true,
+ Valid2 == true</