aboutsummaryrefslogtreecommitdiff
path: root/2018/day1.p6
blob: 5070a6c70a2e53e9e82f0c6518ae5e6730ba8ced (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
sub day1(@input) {
    my $freq = @input.sum;
    say "Frequency: $freq";
}

sub day1-pt2(@input) {
    my $seen = SetHash.new;
    my $freq = 0;
    LOOP: loop {
        for @input -> $val {
            $freq += $val;
            if $freq$seen {
                last LOOP;
            }
            $seen{$freq} = True;
        }
    }
    say "Frequency: $freq";
                
}

my @input = $*IN.lines.map(*.Int);
day1(@input);
day1-pt2(@input);