From 947be75a54cae5e5afbcb94f28318cb39982f529 Mon Sep 17 00:00:00 2001 From: rir Date: Fri, 20 Sep 2024 22:07:48 -0400 Subject: fix files' locations --- challenge-286/0rir/ch-1.raku | 11 ---- challenge-286/0rir/ch-2.raku | 118 -------------------------------------- challenge-286/0rir/raku/ch-1.raku | 11 ++++ challenge-286/0rir/raku/ch-2.raku | 118 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 129 deletions(-) delete mode 100755 challenge-286/0rir/ch-1.raku delete mode 100644 challenge-286/0rir/ch-2.raku create mode 100755 challenge-286/0rir/raku/ch-1.raku create mode 100644 challenge-286/0rir/raku/ch-2.raku diff --git a/challenge-286/0rir/ch-1.raku b/challenge-286/0rir/ch-1.raku deleted file mode 100755 index a4194bdb33..0000000000 --- a/challenge-286/0rir/ch-1.raku +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env raku -use v6.d; - -=begin comment -286-1: Self Spammer -Submitted by: David Ferrone -Write a program which outputs one word of its own script / source code at random. A word is anything between whitespace, including symbols. -… -=end comment - -say $*PROGRAM-NAME.IO.slurp.words.pick; diff --git a/challenge-286/0rir/ch-2.raku b/challenge-286/0rir/ch-2.raku deleted file mode 100644 index 7ea7b70d4f..0000000000 --- a/challenge-286/0rir/ch-2.raku +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env raku -# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ -use v6.d; -use lib $?FILE.IO.cleanup.parent(2).add("lib"); -use Test; - -=begin comment -Put a different way, go through an array halving its size by taking, -starting at index 0, two elements and replacing them with their min. -The next two elements are replaced by their max. Continue through the -array, alternating min and max. Repeat this on each derived array until -there is one element which is the solution. - - -286-2: Order Game -Submitted by: Mohammad Sajid Anwar -You are given an array of integers, @ints, whose length is a power of 2. - -Write a script to play the order game (min and max) and return the last element. - -Example 1 -Input: @ints = (2, 1, 4, 5, 6, 3, 0, 2) -Output: 1 - -Operation 1: - - min(2, 1) = 1 - max(4, 5) = 5 - min(6, 3) = 3 - max(0, 2) = 2 - -Operation 2: - - min(1, 5) = 1 - max(3, 2) = 3 - -Operation 3: - - min(1, 3) = 1 -Example 2 -Input: @ints = (0, 5, 3, 2) -Output: 0 - -Operation 1: - - min(0, 5) = 0 - max(3, 2) = 3 - -Operation 2: - - min(0, 3) = 0 -Example 3 -Input: @ints = (9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8) -Output: 2 - -Operation 1: - - min(9, 2) = 2 - max(1, 4) = 4 - min(5, 6) = 5 - max(0, 7) = 7 - min(3, 1) = 1 - max(3, 5) = 5 - min(7, 9) = 7 - max(0, 8) = 8 - -Operation 2: - - min(2, 4) = 2 - max(5, 7) = 7 - min(1, 5) = 1 - max(7, 8) = 8 - -Operation 3: - - min(2, 7) = 2 - max(1, 8) = 8 - -Operation 4: - - min(2, 8) = 2 - -=end comment - -constant @gtr-power-of-two = lazy 4, (* × 2) … 2**10; - -my @Test = - (2, 1, 4, 5, 6, 3, 0, 2), 1, - (9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8), 2, - (2, 2, 1, 2, 2, 2, 2, 1), 2, - (1,2), 1, - (2,1), 1, - (2,2), 2, - (5,), 5, - (), Int, - (0, 5, 3, 2), 0, -; - -plan @Test ÷ 2; - - -sub prefix:<≭>( Bool $a is rw ) { $a = !$a } # U-226D 'not equiv to' - -multi task( @a where *.elems ≤ 2) { @a.elems == 0 ?? Int !! @a.min } -multi task( @a ) { - my Bool $f; - my @b = @a.rotor(2).map({ ≭$f ?? $_.min !! $_.max }).Array; - task( @b.Array); -} - -for @Test -> $in, $exp { - is task($in), $exp, $exp // "Int" ~ " <- " ~ $in.raku; -} - -done-testing; - -my @int = (2, 2, 1, 2, 2, 2, 2, 1); -say "\nInput: @int = @int[]\nOutput: { task @int }"; diff --git a/challenge-286/0rir/raku/ch-1.raku b/challenge-286/0rir/raku/ch-1.raku new file mode 100755 index 0000000000..a4194bdb33 --- /dev/null +++ b/challenge-286/0rir/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku +use v6.d; + +=begin comment +286-1: Self Spammer +Submitted by: David Ferrone +Write a program which outputs one word of its own script / source code at random. A word is anything between whitespace, including symbols. +… +=end comment + +say $*PROGRAM-NAME.IO.slurp.words.pick; diff --git a/challenge-286/0rir/raku/ch-2.raku b/challenge-286/0rir/raku/ch-2.raku new file mode 100644 index 0000000000..7ea7b70d4f --- /dev/null +++ b/challenge-286/0rir/raku/ch-2.raku @@ -0,0 +1,118 @@ +#!/usr/bin/env raku +# :vim ft=raku sw=4 expandtab # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴ +use v6.d; +use lib $?FILE.IO.cleanup.parent(2).add("lib"); +use Test; + +=begin comment +Put a different way, go through an array halving its size by taking, +starting at index 0, two elements and replacing them with their min. +The next two elements are replaced by their max. Continue through the +array, alternating min and max. Repeat this on each derived array until +there is one element which is the solution. + + +286-2: Order Game +Submitted by: Mohammad Sajid Anwar +You are given an array of integers, @ints, whose length is a power of 2. + +Write a script to play the order game (min and max) and return the last element. + +Example 1 +Input: @ints = (2, 1, 4, 5, 6, 3, 0, 2) +Output: 1 + +Operation 1: + + min(2, 1) = 1 + max(4, 5) = 5 + min(6, 3) = 3 + max(0, 2) = 2 + +Operation 2: + + min(1, 5) = 1 + max(3, 2) = 3 + +Operation 3: + + min(1, 3) = 1 +Example 2 +Input: @ints = (0, 5, 3, 2) +Output: 0 + +Operation 1: + + min(0, 5) = 0 + max(3, 2) = 3 + +Operation 2: + + min(0, 3) = 0 +Example 3 +Input: @ints = (9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8) +Output: 2 + +Operation 1: + + min(9, 2) = 2 + max(1, 4) = 4 + min(5, 6) = 5 + max(0, 7) = 7 + min(3, 1) = 1 + max(3, 5) = 5 + min(7, 9) = 7 + max(0, 8) = 8 + +Operation 2: + + min(2, 4) = 2 + max(5, 7) = 7 + min(1, 5) = 1 + max(7, 8) = 8 + +Operation 3: + + min(2, 7) = 2 + max(1, 8) = 8 + +Operation 4: + + min(2, 8) = 2 + +=end comment + +constant @gtr-power-of-two = lazy 4, (* × 2) … 2**10; + +my @Test = + (2, 1, 4, 5, 6, 3, 0, 2), 1, + (9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8), 2, + (2, 2, 1, 2, 2, 2, 2, 1), 2, + (1,2), 1, + (2,1), 1, + (2,2), 2, + (5,), 5, + (), Int, + (0, 5, 3, 2), 0, +; + +plan @Test ÷ 2; + + +sub prefix:<≭>( Bool $a is rw ) { $a = !$a } # U-226D 'not equiv to' + +multi task( @a where *.elems ≤ 2) { @a.elems == 0 ?? Int !! @a.min } +multi task( @a ) { + my Bool $f; + my @b = @a.rotor(2).map({ ≭$f ?? $_.min !! $_.max }).Array; + task( @b.Array); +} + +for @Test -> $in, $exp { + is task($in), $exp, $exp // "Int" ~ " <- " ~ $in.raku; +} + +done-testing; + +my @int = (2, 2, 1, 2, 2, 2, 2, 1); +say "\nInput: @int = @int[]\nOutput: { task @int }"; -- cgit