diff options
| author | Bob Lied <boblied+github@gmail.com> | 2023-01-14 06:30:38 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-14 06:30:38 -0600 |
| commit | a2fcd3539045b5ff54ea81bc6cbec004c0f1fea7 (patch) | |
| tree | 2891d52ef32c29b32d1b6ee5e40f879c74e1bd18 /challenge-199 | |
| parent | 060e309523bbbf50e6cb9684d858e7059344f31b (diff) | |
| parent | 70a1571ce4c48f53a1eebc84eddb5c035f88b987 (diff) | |
| download | perlweeklychallenge-club-a2fcd3539045b5ff54ea81bc6cbec004c0f1fea7.tar.gz perlweeklychallenge-club-a2fcd3539045b5ff54ea81bc6cbec004c0f1fea7.tar.bz2 perlweeklychallenge-club-a2fcd3539045b5ff54ea81bc6cbec004c0f1fea7.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-199')
115 files changed, 3462 insertions, 2 deletions
diff --git a/challenge-199/0rir/raku/ch-1.raku b/challenge-199/0rir/raku/ch-1.raku new file mode 100755 index 0000000000..867cc81695 --- /dev/null +++ b/challenge-199/0rir/raku/ch-1.raku @@ -0,0 +1,68 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅ ≡ ∩ ≢ ∈ «» +use v6.d; +use lib $?FILE.IO.parent(2).add("lib"); +use Test; + +=begin comment +199-1: Good Pairs Submitted by: Mohammad S Anwar +Given a list of integers, @list, find the total count of Good Pairs. +A pair (i, j) is called good if list[i] == list[j] and i < j. + +Example 1 +Input: @list = (1,2,3,1,1,3) +Output: 4 + +4 good pairs found: (0,3) (0,4) (3,4) (2,5) + +Example 2 +Input: @list = (1,2,3) +Output: 0 + +Example 3 +Input: @list = (1,1,1,1) +Output: 6 + +Good pairs are: (0,1) (0,2) (0,3) (1,2) (1,3) (2,3) +=end comment + +multi sub ct-good-pairs( Empty --> 0 ) {} +multi sub ct-good-pairs( @list --> Int) { + #A pair (i, j) is called good if list[i] == list[j] and i < j. + my $return = 0; + for 0..@list.end -> $i { + for $i^..@list.end -> $j { + ++ $return if @list[$i] == @list[$j]; + } + } + $return; +} + +multi MAIN ( ) { + my @Test = + [6,6,6,6] => 6, + [3,3,3] => 3, + [1,1] => 1, + [0,] => 0, + [0,2,3] => 0, + [1,2,1,2] => 2, + [1,2,3,1,2,3] => 3, + [1,2,9,1,2,9,1,2,9] => 9, + [3,4,5,3,4,5,1,2,12,1,2,12,1,2,12] => 12, + [12,11,10,3,4,5,3,4,5,1,2,9,1,2,9,1,2,9] => 12, + [12,11,10,6,7,8,3,4,5,3,4,5,1,2,9,1,2,9,1,2,9] => 12, + ; + plan 2 * @Test +1; + + is ct-good-pairs(Empty), 0, '0 <- ' ~ (Empty).raku; + for @Test -> $p { + is ct-good-pairs( $p.key), $p.value, "$p.value() <- $p.key().raku()"; + is ct-good-pairs( $p.key.pick(*)), $p.value, + "$p.value() <- $p.key().pick(*).Array.raku() shuffle"; + } + done-testing; + + my @list = [12,11,10,3,4,5,3,4,5,1,2,9,1,2,9,1,2,9]; + say "\nInput: \@list = @list.raku()\nOutput: &ct-good-pairs(@list)"; + exit; +} diff --git a/challenge-199/0rir/raku/ch-2.raku b/challenge-199/0rir/raku/ch-2.raku new file mode 100755 index 0000000000..562400e230 --- /dev/null +++ b/challenge-199/0rir/raku/ch-2.raku @@ -0,0 +1,94 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # |
