From a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 5 Dec 2020 10:55:56 -0300 Subject: Add 2018 and 2017 --- 2018/day1.p6 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2018/day1.p6 (limited to '2018/day1.p6') diff --git a/2018/day1.p6 b/2018/day1.p6 new file mode 100644 index 0000000..5070a6c --- /dev/null +++ b/2018/day1.p6 @@ -0,0 +1,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); -- cgit v1.2.3-70-g09d2