aboutsummaryrefslogtreecommitdiff
path: root/2018/day1.p6
diff options
context:
space:
mode:
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);