aboutsummaryrefslogtreecommitdiff
path: root/2018/day1.p6
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2020-12-05 10:55:56 -0300
committerMatias Linares <matiaslina@gmail.com>2020-12-05 10:55:56 -0300
commita0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e (patch)
treea663ee4f6a427e98db0878ca539c9288bfbc70d0 /2018/day1.p6
parent5fa17cd54a1170449a91da48a2fe88a99349daa2 (diff)
downloadadvent-of-code-a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e.tar.gz
Add 2018 and 2017
Diffstat (limited to '2018/day1.p6')
-rw-r--r--2018/day1.p625
1 files changed, 25 insertions, 0 deletions
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);