aboutsummaryrefslogtreecommitdiff
path: root/challenge-307/0rir/raku/ch-1.raku
blob: 28c320c3b227f1e9dd9c79b7b442e89adf78ab6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env raku
# :vim ft=raku sw=4 expandtab  # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
use v6.d;
use Test;

=begin comment
Task 1: Check Order
Submitted by: Mohammad Sajid Anwar
You are given an array of integers, @ints.

Write a script to re-arrange the given array in an increasing order and return the indices where it differs from the original array.

Example 1
Input: @ints = (5, 2, 4, 3, 1)
Output: (0, 2, 3, 4)

Before: (5, 2, 4, 3, 1)
After : (1, 2, 3, 4, 5)

Difference at indices: (0, 2, 3, 4)
Example 2
Input: @ints = (1, 2, 1, 1, 3)
Output: (1, 3)

Before: (1, 2, 1, 1, 3)
After : (1, 1, 1, 2, 3)

Difference at indices: (1, 3)
Example 3
Input: @ints = (3, 1, 3, 2, 3)
Output: (0, 1, 3)

Before: (3, 1, 3, 2, 3)
After : (1, 2, 3, 3, 3)

Difference at indices: (0, 1, 3)

=end comment

my @Test =
    (),                 (),
    (1,),               (),
    (1,2),              (),
    (2,1),              (0,1),
    (1, 2, 1, 1, 3),    (1, 3),
    (5, 2, 4, 3, 1),    (0, 2, 3, 4),
    (3, 1, 3, 2, 3),    (0, 1, 3),
    (1, 204, 9, 7, 172, 238, 727, 319, 102), (1, 3, 5, 6, 8),
;
plan @Test ÷ 2;

sub task( @in) {    (@in.sort Z== @in) .grep: !*, :k }

for @Test -> @in, $exp {
    is task( @in), $exp, "{$exp // $exp.^name()} <- @in.raku()"
}
done-testing;

my @int = 1, 204, 9,   7, 172, 238, 727, 102, 319;
print "\nInput: @int = ( ", @int, " )\nOutput: ", task(@int);