forked from manwar/perlweeklychallenge-club
/
ch-1.raku
executable file
·52 lines (43 loc) · 945 Bytes
/
ch-1.raku
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
#!/usr/bin/raku
sub nochange {
say 'false';
exit(0);
}
sub MAIN(
*@bills
) {
my $fives = 0;
my $tens = 0;
my $twenties = 0;
for @bills -> $bill {
given $bill {
when 5 {
$fives++;
}
when 10 {
if $fives > 0 {
$fives--;
$tens++;
} else {
nochange();
}
}
when 20 {
if $tens > 0 && $fives > 0 {
$tens -= 1;
$fives -= 1;
$twenties += 1;
} elsif $fives > 2 {
$fives -= 3;
$twenties += 1;
} else {
nochange();
}
}
default {
die "illegal bill value\n";
}
}
}
say "true";
}