aboutsummaryrefslogtreecommitdiff
path: root/challenge-283/0rir/raku/ch-2.raku
blob: a1fc3e0926976d2343bf3e52c771bf662fc2cf4c (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
61
62
63
64
65
#!/usr/bin/env raku
# :vim ft=raku sw=4 expandtab  # 🦋 ∅∪∩∋∈∉⊆ ≡ ≢ «␤ » ∴
use v6.d;
use Test;

=begin comment
283-2: Digit Count Value            Submitted by: Mohammad Sajid Anwar
You are given an array of positive integers, @ints.

Write a script to return true if for every index i in the range
0 <= i < size of array, the digit i occurs exactly the $ints[$i] times
in the given array otherwise return false.

Example 1
Input: @ints = (1, 2, 1, 0)
Ouput: true

$ints[0] = 1, the digit 0 occurs exactly 1 time.
$ints[1] = 2, the digit 1 occurs exactly 2 times.
$ints[2] = 1, the digit 2 occurs exactly 1 time.
$ints[3] = 0, the digit 3 occurs 0 time.
Example 2
Input: @ints = (0, 3, 0)
Ouput: false

=end comment

my @Test =
    (1).comb.List,                  False,
    (0).comb.List,                  False,
    (10).comb.List,                 False,
    (212).comb.List,                False,
    (030).comb.List,                False,
    (3000).comb.List,               False,
    (40000).comb.List,              False,
    (31000).comb.List,              False,
    (3312000).comb.List,            False,
    (4301000).comb.List,            False,
    (9122000001).comb.List,         False,
    (1210.comb.List),               True,
    (2020.comb.List),               True,
    (21200.comb.List),              True,
    (3211000.comb.List),            True,
    (521001000.comb.List),          True,
    (6210001000.comb.List),         True,
    (72100001000.comb.List),        True,
    (821000001000.comb.List),       True,
    (9210000001000.comb.List),      True,
;
plan @Test ÷ 2;

sub task( $a) {
    for ^$a -> \i {
        return False unless  $a.grep( i ) == $a[ i];
    }
    True;
}

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

my @int = (4, 1, 0, 0, 0, 0);
say "\nInput: @ints = @int.raku()\nOuput: { task @int }";