aboutsummaryrefslogtreecommitdiff
path: root/challenge-080/mark-anderson/raku/ch-2.raku
blob: e25ccaab563fcf04e4c78e3bbe7b5b6e06b23a02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# with help from https://www.youtube.com/watch?v=h6_lIwZYHQw

unit sub MAIN(*@N where .all ~~ Int);

my @L2R = candies(@N);
my @R2L = candies(@N.reverse);

say (@L2R Z @R2L.reverse).map(*.max).sum;

sub candies(@N) {
    my @candies = 1 xx @N;

    for @N.keys.skip -> $k {
        if @N[$k] > @N[$k-1] {
            @candies[$k] = @candies[$k-1] + 1;
        }
    }

    @candies;
}