diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-10-30 21:27:45 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-30 21:27:45 +0000 |
| commit | f02ad05338109f521572b76f37536325dbaa641f (patch) | |
| tree | 1b473bf050b39b6519a68f2c261b87350f6edbf3 | |
| parent | 3acb661908dceba0acb176f032487761f94a008f (diff) | |
| parent | 9ab53129c51a9dbb082a44b82c09b1cdadaf07b3 (diff) | |
| download | perlweeklychallenge-club-f02ad05338109f521572b76f37536325dbaa641f.tar.gz perlweeklychallenge-club-f02ad05338109f521572b76f37536325dbaa641f.tar.bz2 perlweeklychallenge-club-f02ad05338109f521572b76f37536325dbaa641f.zip | |
Merge pull request #6991 from arnesom/branch-for-challenge-188
Arne Sommer
| -rw-r--r-- | challenge-188/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-188/arne-sommer/raku/ch-1.raku | 37 | ||||
| -rwxr-xr-x | challenge-188/arne-sommer/raku/ch-2.raku | 29 | ||||
| -rwxr-xr-x | challenge-188/arne-sommer/raku/divisible-pairs | 37 | ||||
| -rwxr-xr-x | challenge-188/arne-sommer/raku/total-zero | 30 | ||||
| -rwxr-xr-x | challenge-188/arne-sommer/raku/total-zero2 | 29 |
6 files changed, 163 insertions, 0 deletions
diff --git a/challenge-188/arne-sommer/blog.txt b/challenge-188/arne-sommer/blog.txt new file mode 100644 index 0000000000..fe0c2e569a --- /dev/null +++ b/challenge-188/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/zero-divisibility.html diff --git a/challenge-188/arne-sommer/raku/ch-1.raku b/challenge-188/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..9f07f74310 --- /dev/null +++ b/challenge-188/arne-sommer/raku/ch-1.raku @@ -0,0 +1,37 @@ +#! /usr/bin/env raku + +unit sub MAIN (:v(:$verbose)); + +say dip( (4, 5, 1, 6), 2); +say dip( (1, 2, 3, 4), 2); +say dip( (1, 3, 4, 5), 3); +say dip( (5, 1, 2, 3), 4); +say dip( (7, 2, 4, 5), 4); + +sub dip (@list, $k) +{ + my @combinations = @list.combinations(2); + my $n = @list.elems; + my $count = 0; + + say ":I :[{ @list.join(",") }] K:$k N:$n" if $verbose; + + for @combinations -> @candidate + { + my ($i, $j) = @candidate; + + ($i, $j) = ($j, $i) if $i > $j; + + say ":Comb :[$i,$j]" if $verbose; + + next unless 0 <= $i < $j < $n; + say ":Less :[$i,$j] -> { @list[$i] },{ @list[$j] }" if $verbose; + next unless (@list[$i] + @list[$j]) %% $k; + + $count++; + say ":OK :[{ @candidate.join(",") }] | $count" if $verbose; + + } + + return $count; +} diff --git a/challenge-188/arne-sommer/raku/ch-2.raku b/challenge-188/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..0835df780c --- /dev/null +++ b/challenge-188/arne-sommer/raku/ch-2.raku @@ -0,0 +1,29 @@ +#! /usr/bin/env raku + +unit sub MAIN (:v(:$verbose)); + +say total-zero(5, 4); +say total-zero(4, 6); +say total-zero(2, 5); +say total-zero(3, 1); +say total-zero(7, 4); + +sub total-zero ($x is copy, $y is copy) +{ + my $count = 0; + + while $x + $y + { + my $x0 = $x; + my $y0 = $y; + + $x -= $y0 if $x0 >= $y0; + $y -= $x0 if $y0 >= $x0; + + $count++; + + say ": x:$x0 y:$y0 -> x:$x y:$y [#:$count]" if $verbose; + } + + return $count; +} diff --git a/challenge-188/arne-sommer/raku/divisible-pairs b/challenge-188/arne-sommer/raku/divisible-pairs new file mode 100755 index 0000000000..9f07f74310 --- /dev/null +++ b/challenge-188/arne-sommer/raku/divisible-pairs @@ -0,0 +1,37 @@ +#! /usr/bin/env raku + +unit sub MAIN (:v(:$verbose)); + +say dip( (4, 5, 1, 6), 2); +say dip( (1, 2, 3, 4), 2); +say dip( (1, 3, 4, 5), 3); +say dip( (5, 1, 2, 3), 4); +say dip( (7, 2, 4, 5), 4); + +sub dip (@list, $k) +{ + my @combinations = @list.combinations(2); + my $n = @list.elems; + my $count = 0; + + say ":I :[{ @list.join(",") }] K:$k N:$n" if $verbose; + + for @combinations -> @candidate + { + my ($i, $j) = @candidate; + + ($i, $j) = ($j, $i) if $i > $j; + + say ":Comb :[$i,$j]" if $verbose; + + next unless 0 <= $i < $j < $n; + say ":Less :[$i,$j] -> { @list[$i] },{ @list[$j] }" if $verbose; + next unless (@list[$i] + @list[$j]) %% $k; + + $count++; + say ":OK :[{ @candidate.join(",") }] | $count" if $verbose; + + } + + return $count; +} diff --git a/challenge-188/arne-sommer/raku/total-zero b/challenge-188/arne-sommer/raku/total-zero new file mode 100755 index 0000000000..6d5b2e1388 --- /dev/null +++ b/challenge-188/arne-sommer/raku/total-zero @@ -0,0 +1,30 @@ +#! /usr/bin/env raku + +unit sub MAIN (:v(:$verbose)); + +say total-zero(5, 4); +say total-zero(4, 6); +say total-zero(2, 5); +say total-zero(3, 1); +say total-zero(7, 4); + +sub total-zero ($x is copy, $y is copy) +{ + my $count = 0; + + while $x + $y + { + my $x0 = $x; + my $y0 = $y; + my $action = 0; + + if $x0 >= $y0 { $x -= $y0; $action++; } + if $y0 >= $x0 { $y -= $x0; $action++; } + + $count++ if $action; + + say ": x:$x0 y:$y0 -> x:$x y:$y [#:$count]" if $verbose; + } + + return $count; +} diff --git a/challenge-188/arne-sommer/raku/total-zero2 b/challenge-188/arne-sommer/raku/total-zero2 new file mode 100755 index 0000000000..0835df780c --- /dev/null +++ b/challenge-188/arne-sommer/raku/total-zero2 @@ -0,0 +1,29 @@ +#! /usr/bin/env raku + +unit sub MAIN (:v(:$verbose)); + +say total-zero(5, 4); +say total-zero(4, 6); +say total-zero(2, 5); +say total-zero(3, 1); +say total-zero(7, 4); + +sub total-zero ($x is copy, $y is copy) +{ + my $count = 0; + + while $x + $y + { + my $x0 = $x; + my $y0 = $y; + + $x -= $y0 if $x0 >= $y0; + $y -= $x0 if $y0 >= $x0; + + $count++; + + say ": x:$x0 y:$y0 -> x:$x y:$y [#:$count]" if $verbose; + } + + return $count; +} |
