diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2023-07-24 17:16:48 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2023-07-24 17:16:48 +0800 |
| commit | 4fda4a4a398e64921020704733556a2ec6dae78a (patch) | |
| tree | f2b70bccff1e2d183104042921d0726f7a8e5f40 /challenge-222/0rir | |
| parent | a296c2a161ce1fffe7c7c1108346c81f027af419 (diff) | |
| parent | e4bdf5dcb6e741f1fb8e1b145fd2111f05ed6445 (diff) | |
| download | perlweeklychallenge-club-4fda4a4a398e64921020704733556a2ec6dae78a.tar.gz perlweeklychallenge-club-4fda4a4a398e64921020704733556a2ec6dae78a.tar.bz2 perlweeklychallenge-club-4fda4a4a398e64921020704733556a2ec6dae78a.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-222/0rir')
| -rw-r--r-- | challenge-222/0rir/ch-1.raku | 49 | ||||
| -rw-r--r-- | challenge-222/0rir/ch-2.raku | 90 |
2 files changed, 0 insertions, 139 deletions
diff --git a/challenge-222/0rir/ch-1.raku b/challenge-222/0rir/ch-1.raku deleted file mode 100644 index 8bb35039b9..0000000000 --- a/challenge-222/0rir/ch-1.raku +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env raku -# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉ ≡ ≢ « » ∴ -use v6.d; -use Test; - -=begin comment -222-1: Matching Members Submitted by: Mohammad S Anwar - -Given a list of positive integers, @ints, find the total matching members -after sorting the list increasing order. - -Example 1 -Input: @ints = (1, 1, 4, 2, 1, 3) -Output: 3 - -Original list: (1, 1, 4, 2, 1, 2) -Sorted list : (1, 1, 1, 2, 3, 4) -Compare the two lists, we found 3 matching members (1, 1, 2). - -Example 2 -Input: @ints = (5, 1, 2, 3, 4) -Output: 0 - -Example 3 -Input: @ints = (1, 2, 3, 4, 5) -Output: 5 -=end comment - -my @Test = - (1, 1, 4, 2, 1, 3), 3, - (5, 1, 2, 3, 4), 0, - (1, 2, 3, 4, 5), 5, - (1,2,3,4,5,5,4,), 5, - (), 0, -; - -plan @Test ÷ 2; - -for @Test -> @in, $exp { - is ([Z==] @in, @in.sort).grep( *.Bool ).elems - , $exp - , 'count matches'; -} - -done-testing; -my @int = (1,2,3,4,5,5,4,); -say "\n\nInput: @ints = @int.raku()\nOutput: ", - ([Z==] @int, @int.sort).grep( *.Bool ).elems; - diff --git a/challenge-222/0rir/ch-2.raku b/challenge-222/0rir/ch-2.raku deleted file mode 100644 index 0f51ebd0c3..0000000000 --- a/challenge-222/0rir/ch-2.raku +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env raku -# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉ ≡ ≢ « » ∴ -use v6.d; -use Test; - -=begin comment -222-2: Last Member Submitted by: Mohammad S Anwar -Given rules and an array of positive integers, @ints, find the last member -if found otherwise return 0 by applying the follwoing rules. Each turn -pick 2 biggest members (x, y) then decide based on the following conditions, -continue this until you are left with 1 member or none. - -a) if x == y then remove both members - -b) if x != y then remove both members and add new member (y-x) - - -Example 1: -Input: @ints = (2, 7, 4, 1, 8, 1) -Output: 1 - -Step 1: pick 7 and 8, we remove both and add new member 1 => (2, 4, 1, 1, 1). -Step 2: pick 2 and 4, we remove both and add new member 2 => (2, 1, 1, 1). -Step 3: pick 2 and 1, we remove both and add new member 1 => (1, 1, 1). -Step 4: pick 1 and 1, we remove both => (1). - -Example 2: -Input: @ints = (1) -Output: 1 - -Example 3: -Input: @ints = (1, 1) -Output: 0 -=end comment - -my @Test = - (), 0, - (1,), 1, - (1,1), 0, - (1,1,1), 1, - [∞, ∞], 0, - (2,1,1), 0, - (2,1,1,1), 1, - (5,1), 1, - (5,5,5,5,), 0, - (5,5,5,5,5,), 1, - (6,6,5,5,5,), 1, - (2, 7, 4, 1, 8, 1), 1, - [2, 2, 2, 2, 2, 2, 1], 1, - [2, 2, 2, 2, 2, 2, 2, 1], 1, - [10, 15, 4], 1, - [10, 15, 2], 1, - [20, 15, 2], 1, -; - -plan @Test ÷ 2; - -sub func( @b ) { - my $b = BagHash.new: @b; - - loop { - # done? - return 0 if $b.total == 0; - return 1 if $b.total == 1; - - # elim even count max - if $b.max.value %% 2 { - $b{$b.max.key} = 0; - next; - } - - # resolve singular max - $b{$b.max.key} = 1; - return 1 if $b.total == 1; - my $super-max = $b.max.key; - $b.remove: $super-max; - my $max = $b.max.key; - $b.remove: $max; - $b.add: $super-max - $max; - } -} - -for @Test -> @in, $exp { - is func(@in), $exp, "$exp <- @in.sort.reverse()"; -} -done-testing; - -my @int = ( 20, 70, 70, 40, 10, 80 ).sort; -say "\n\nInput: @ints = @int[]\nOutput: ", func(@int); - |
