aboutsummaryrefslogtreecommitdiff
path: root/challenge-285
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-285')
-rw-r--r--challenge-285/0rir/raku/ch-1.raku63
-rw-r--r--challenge-285/0rir/raku/ch-2.raku95
-rw-r--r--challenge-285/arne-sommer/blog.txt1
-rwxr-xr-xchallenge-285/arne-sommer/raku/ch-1.raku25
-rwxr-xr-xchallenge-285/arne-sommer/raku/ch-2.raku68
-rwxr-xr-xchallenge-285/arne-sommer/raku/making-change55
-rwxr-xr-xchallenge-285/arne-sommer/raku/making-change-last68
-rwxr-xr-xchallenge-285/arne-sommer/raku/no-connection25
-rw-r--r--challenge-285/asherbhs/apl/ch-1.apl4
-rw-r--r--challenge-285/asherbhs/apl/ch-2.apl15
-rw-r--r--challenge-285/asherbhs/bqn/ch-1.bqn4
-rw-r--r--challenge-285/asherbhs/haskell/ch-1.hs16
-rw-r--r--challenge-285/asherbhs/hy/ch-1.hy10
-rw-r--r--challenge-285/asherbhs/j/ch-1.ijs5
-rw-r--r--challenge-285/asherbhs/k/ch-1.k4
-rw-r--r--challenge-285/asherbhs/raku/ch-1.raku6
-rw-r--r--challenge-285/athanasius/perl/ch-1.pl199
-rw-r--r--challenge-285/athanasius/perl/ch-2.pl233
-rw-r--r--challenge-285/athanasius/raku/ch-1.raku201
-rw-r--r--challenge-285/athanasius/raku/ch-2.raku218
-rw-r--r--challenge-285/atschneid/README.md10
-rw-r--r--challenge-285/atschneid/perl/ch-1.pl38
-rw-r--r--challenge-285/atschneid/perl/ch-2.pl40
-rw-r--r--challenge-285/barroff/julia/ch-1.jl16
-rw-r--r--challenge-285/barroff/raku/ch-1.p629
-rw-r--r--challenge-285/bob-lied/README6
-rw-r--r--challenge-285/bob-lied/perl/ch-1.pl60
-rw-r--r--challenge-285/bob-lied/perl/ch-2.pl113
-rwxr-xr-xchallenge-285/cheok-yin-fung/perl/ch-1.pl23
-rwxr-xr-xchallenge-285/cheok-yin-fung/perl/ch-2.pl48
-rwxr-xr-xchallenge-285/feng-chang/raku/ch-2.raku4
-rw-r--r--challenge-285/jo-37/blog.txt1
-rwxr-xr-xchallenge-285/jo-37/perl/ch-1.pl62
-rwxr-xr-xchallenge-285/jo-37/perl/ch-2.pl105
-rw-r--r--challenge-285/jtimothyking/csharp/ch-1.cs27
-rw-r--r--challenge-285/jtimothyking/csharp/ch-2.cs42
-rw-r--r--challenge-285/jtimothyking/perl/ch-1.pl23
-rw-r--r--challenge-285/jtimothyking/perl/ch-2.pl25
-rw-r--r--challenge-285/laurent-rosenfeld/blog1.txt1
-rw-r--r--challenge-285/laurent-rosenfeld/perl/ch-2.pl30
-rw-r--r--challenge-285/laurent-rosenfeld/raku/ch-2.raku24
-rw-r--r--challenge-285/matthias-muth/README.md122
-rwxr-xr-xchallenge-285/matthias-muth/perl/ch-1.pl11
-rwxr-xr-xchallenge-285/matthias-muth/perl/ch-2.pl70
-rwxr-xr-xchallenge-285/mattneleigh/perl/ch-1.pl88
-rwxr-xr-xchallenge-285/mattneleigh/perl/ch-2.pl75
-rw-r--r--challenge-285/nelo-tovar/perl/ch-1.pl40
-rw-r--r--challenge-285/nelo-tovar/perl/ch-2.pl39
-rw-r--r--challenge-285/ppentchev/README1
-rw-r--r--challenge-285/ppentchev/python/.gitignore7
-rw-r--r--challenge-285/ppentchev/python/LICENSES/BSD-2-Clause.txt9
-rw-r--r--challenge-285/ppentchev/python/README.md8
-rw-r--r--challenge-285/ppentchev/python/pyproject.toml86
-rw-r--r--challenge-285/ppentchev/python/requirements/install.txt2
-rw-r--r--challenge-285/ppentchev/python/requirements/ruff.txt4
-rw-r--r--challenge-285/ppentchev/python/requirements/test.txt6
-rw-r--r--challenge-285/ppentchev/python/ruff-base.toml39
-rw-r--r--challenge-285/ppentchev/python/src/perl_weekly_285/__init__.py3
-rw-r--r--challenge-285/ppentchev/python/src/perl_weekly_285/ch-1.py50
-rw-r--r--challenge-285/ppentchev/python/src/perl_weekly_285/ch-2.py88
-rw-r--r--challenge-285/ppentchev/python/src/perl_weekly_285/change.py88
-rw-r--r--challenge-285/ppentchev/python/src/perl_weekly_285/defs.py34
-rw-r--r--challenge-285/ppentchev/python/src/perl_weekly_285/routes.py50
-rw-r--r--challenge-285/ppentchev/python/tests/unit/__init__.py3
-rw-r--r--challenge-285/ppentchev/python/tests/unit/test_change.py133
-rw-r--r--challenge-285/ppentchev/python/tests/unit/test_metadata.py21
-rw-r--r--challenge-285/ppentchev/python/tests/unit/test_routes.py73
-rw-r--r--challenge-285/ppentchev/python/tox.ini106
-rw-r--r--challenge-285/ppentchev/rust/Cargo.lock512
-rw-r--r--challenge-285/ppentchev/rust/Cargo.toml25
-rwxr-xr-xchallenge-285/ppentchev/rust/run-clippy.sh70
-rw-r--r--challenge-285/ppentchev/rust/src/ch-1.rs49
-rw-r--r--challenge-285/ppentchev/rust/src/ch-2.rs188
-rw-r--r--challenge-285/ppentchev/rust/src/change.rs188
-rw-r--r--challenge-285/ppentchev/rust/src/defs.rs24
-rw-r--r--challenge-285/ppentchev/rust/src/lib.rs15
-rw-r--r--challenge-285/ppentchev/rust/src/routes.rs49
-rw-r--r--challenge-285/ppentchev/rust/src/tests/change.rs52
-rw-r--r--challenge-285/ppentchev/rust/src/tests/mod.rs9
-rw-r--r--challenge-285/ppentchev/rust/src/tests/routes.rs60
-rw-r--r--challenge-285/reinier-maliepaard/blog.txt1
-rw-r--r--challenge-285/reinier-maliepaard/perl/ch-1.pl26
-rw-r--r--challenge-285/robbie-hatley/blog.txt1
-rwxr-xr-xchallenge-285/robbie-hatley/perl/ch-1.pl75
-rwxr-xr-xchallenge-285/robbie-hatley/perl/ch-2.pl75
-rw-r--r--challenge-285/roger-bell-west/blog.txt1
-rw-r--r--challenge-285/sgreen/README.md4
-rw-r--r--challenge-285/sgreen/blog.txt1
-rwxr-xr-xchallenge-285/sgreen/perl/ch-1.pl40
-rwxr-xr-xchallenge-285/sgreen/perl/ch-2.pl36
-rwxr-xr-xchallenge-285/sgreen/python/ch-1.py35
-rwxr-xr-xchallenge-285/sgreen/python/ch-2.py30
-rwxr-xr-xchallenge-285/sgreen/python/test.py22
-rw-r--r--challenge-285/torgny-lyon/blog.txt1
-rwxr-xr-xchallenge-285/torgny-lyon/perl/ch-1.pl14
-rwxr-xr-xchallenge-285/torgny-lyon/perl/ch-2.pl44
-rw-r--r--challenge-285/wambash/elixir/ch-2.exs30
-rw-r--r--challenge-285/wambash/raku/ch-1.raku19
-rwxr-xr-xchallenge-285/wanderdoc/perl/ch-1.pl72
-rwxr-xr-xchallenge-285/wanderdoc/perl/ch-2.pl86
100 files changed, 5100 insertions, 52 deletions
diff --git a/challenge-285/0rir/raku/ch-1.raku b/challenge-285/0rir/raku/ch-1.raku
new file mode 100644
index 0000000000..4842962ddf
--- /dev/null
+++ b/challenge-285/0rir/raku/ch-1.raku
@@ -0,0 +1,63 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+285-1: No Connection Submitted by: Mohammad Sajid Anwar
+
+You are given a list of routes, @routes. Write a script to find the destination with no further outgoing connection.
+Example 1
+Input: @routes = (["B","C"], ["D","B"], ["C","A"])
+Output: "A"
+
+"D" -> "B" -> "C" -> "A".
+"B" -> "C" -> "A".
+"C" -> "A".
+"A".
+Example 2
+Input: @routes = (["A","Z"])
+Output: "Z"
+
+=end comment
+
+=begin comment
+The routes are not bidirectional or 'D' would be an answer in the
+first example.
+It is not clear that route lists are constrained to two elements.
+But the question suggests that any intersection of paths defines
+a end-point for all routes intersecting.
+=end comment
+
+my @Test =
+ (<B C>, <D B>, <C A>), ("A"),
+ (<A Z>,), ("Z"),
+ (<A a b c Z>,), ("Z"),
+ (<A D>, <B C>, <D B>, <C A>), (),
+ (< A>, < A>), (),
+ (<A Z>, <Z A>), (),
+ (<A Z>, <B Z>), "Z",
+ (<A Z>, <B C>), <Z C>.sort,
+ (<A B>, <B C>, <B D>, <B E>, <E F>),
+ <C D F>.sort,
+ ;
+
+plan @Test ÷ 2;
+
+only task( List:D $a --> List) {
+ my @head = @$a.map( *.[0]);
+ my @tail = @$a.map( *.[*-1]);
+ (@tail ∖ @head).keys.List;
+}
+
+for @Test -> $in, $exp {
+ is task($in).sort, $exp, "$exp <- $in.raku()";
+}
+
+done-testing;
+
+my @route = (["B","C"], ["D","D"], ["D","E"], ["F","G"]);
+
+say "\nInput: @routes = @route.raku()\nOutput: { task @route }";
+
+
diff --git a/challenge-285/0rir/raku/ch-2.raku b/challenge-285/0rir/raku/ch-2.raku
new file mode 100644
index 0000000000..fbb946f0bf
--- /dev/null
+++ b/challenge-285/0rir/raku/ch-2.raku
@@ -0,0 +1,95 @@
+#!/usr/bin/env raku
+# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
+use v6.d;
+use Test;
+
+=begin comment
+285-2: Making Change Submitted by: David Ferrone
+
+Compute the number of ways to make change for given amount in cents. By using the coins e.g. Penny, Nickel, Dime, Quarter and Half-dollar, in how many distinct ways can the total value equal to the given amount? Order of coin selection does not matter.
+
+A penny (P) is equal to 1 cent.
+A nickel (N) is equal to 5 cents.
+A dime (D) is equal to 10 cents.
+A quarter (Q) is equal to 25 cents.
+A half-dollar (HD) is equal to 50 cents.
+Example 1
+Input: $amount = 9
+Output: 2
+
+1: 9P
+2: N + 4P
+Example 2
+Input: $amount = 15
+Output: 6
+
+1: D + 5P
+2: D + N
+3: 3N
+4: 2N + 5P
+5: N + 10P
+6: 15P
+Example 3
+Input: $amount = 100
+Output: 292
+
+=end comment
+
+my @Test =
+ 0,0, $(1..4),1, $(5..9),2,
+ #$(10..14),4, $(15..19),6, $(20..24),9,
+ $(25..29),13, $(30..34),18, $(35..39),24,
+ #$(40..43),31, $(45..47),39, $(50..51),50,
+ $(55),62, $(60),77, $(69),93,
+ #$(70),112, $(75),134, $(84),159,
+ $(85),187, $(90),218, $(99),252,
+ #$(100),292, $(105),335, $(111),384,
+ #$(120),494, $(130),628, $(141),786,
+ #$(150),972, $(160),1190, $(171),1440,
+ #$(180),1730, $(190),2060,
+ 201,2435,
+ #211,2860,
+ #300,9590,
+ #504,59576,
+;
+plan 32;
+
+constant \P = 1;
+constant \N = 5;
+constant \D = 10;
+constant \Q = 25;
+constant \H = 50;
+
+multi task( UInt:D $n is copy --> UInt) {
+ return 0 if $n == 0;
+ return 1 if $n < 5;
+ $n -= $n % 5; # odd P change doesn't matter
+ my @P = 0, 5, 10 … $n; # P must be subbed as batch
+ my @N = 0, 5, 10 … $n;
+ my @D = 0, 10, 20 … $n - $n % D;
+ my @Q = 0, 25, 50 … $n - $n % Q;
+ my @H = 0, 50, 100 … $n - $n % H;
+ my $ret;
+ for @H -> \h {
+ for @Q -> \qu { # avoid q quoting construct
+ for @D -> \d {
+ for @N -> \n {
+ for @P -> \p {
+ if $n == sum p, n, d, qu, h {
+ ++ $ret;
+ last;
+ } } } } } }
+ return $ret;
+}
+
+for @Test -> $in, $exp {
+ for @$in -> \n {
+ my $a = task( n);
+ is $a, $exp, "$exp <- { n }";
+ }
+}
+
+done-testing;
+
+my $amount = 180;
+say "\nInput: \$amount = $amount\nOutput: { task $amount }";
diff --git a/challenge-285/arne-sommer/blog.txt b/challenge-285/arne-sommer/blog.txt
new file mode 100644
index 0000000000..563ffcf0db
--- /dev/null
+++ b/challenge-285/arne-sommer/blog.txt
@@ -0,0 +1 @@
+https://raku-musings.com/no-connection.html
diff --git a/challenge-285/arne-sommer/raku/ch-1.raku b/challenge-285/arne-sommer/raku/ch-1.raku
new file mode 100755
index 0000000000..d55e3a25d0
--- /dev/null
+++ b/challenge-285/arne-sommer/raku/ch-1.raku
@@ -0,0 +1,25 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (*@routes where @routes.elems > 0, :v(:$verbose));
+
+my %outgoing;
+
+for @routes -> $route
+{
+ my ($from, $to) = $route.split(/\s+/);
+
+ say ": Route from '$from' to '$to'" if $verbose;
+
+ %outgoing{$from}++;
+ %outgoing{$to} = 0 unless defined %outgoing{$to};
+}
+
+if $verbose
+{
+ for sort keys %outgoing -> $key
+ {
+ say ": '$key' has %outgoing{$key} outgoing connectiuon(s)" if $verbose;
+ }
+}
+
+say %outgoing.grep( *.value == 0 )>>.key.join(", ");
diff --git a/challenge-285/arne-sommer/raku/ch-2.raku b/challenge-285/arne-sommer/raku/ch-2.raku
new file mode 100755
index 0000000000..d99bfd95c5
--- /dev/null
+++ b/challenge-285/arne-sommer/raku/ch-2.raku
@@ -0,0 +1,68 @@
+#! /usr/bin/env raku
+
+unit sub MAIN (UInt $amount, :v(:$verbose));
+
+my %value;
+
+%value<penny> = 1;
+%value<nickel> = 5;
+%value<dime> = 10;
+%value<quarter> = 25;
+%value<half-dollar> = 50;
+
+my $ok = 0;
+
+for 0 .. $amount -> $penny
+{
+ my $sum-p = $penny * %value<penny>;
+
+ for 0 .. $amount -> $nickel
+ {
+ my $sum-pn = $sum-p + $nickel * %value<nickel>;
+
+ last if $sum-pn > $amount;
+
+ for 0 .. $amount -> $dime
+ {
+ my $sum-pnd = $sum-pn + $dime * %value<dime>;
+
+ last if $sum-pnd > $amount;
+
+ for 0 .. $amount -> $quarter
+ {
+ my $sum-pndq = $sum-pnd + $quarter * %value<quarter>;
+
+ last if $sum-pndq > $amount;
+
+ for 0 .. $amount -> $half-dollar
+ {
+ my $sum = $sum-pndq + $half-dollar * %value<half-dollar>;
+
+ last if $sum > $amount;
+
+ if $sum == $amount
+ {
+ $ok++;
+ say ": " ~
+ (
+ prettyish($penny, 'P'),
+ prettyish($nickel, 'N'),
+ prettyish($dime, 'D'),
+ prettyish($quarter, 'Q'),
+ prettyish($half-dollar, 'HD')
+ ).grep( *.defined ).join(" + ") if $verbose;
+ }
+ }
+ }
+ }