summary refs log tree commit diff stats
path: root/2021/day-01/day-01.raku
diff options
context:
space:
mode:
Diffstat (limited to '2021/day-01/day-01.raku')
-rw-r--r--2021/day-01/day-01.raku23
1 files changed, 23 insertions, 0 deletions
diff --git a/2021/day-01/day-01.raku b/2021/day-01/day-01.raku
new file mode 100644
index 0000000..ae77c28
--- /dev/null
+++ b/2021/day-01/day-01.raku
@@ -0,0 +1,23 @@
+#!/usr/bin/env raku
+
+my Int @inputs = "input".IO.lines>>.Int;
+
+{
+    my Int $larger-than-previous = 0;
+
+    for (^@inputs.elems).skip -> $idx {
+        $larger-than-previous++ if @inputs[$idx] > @inputs[$idx - 1];
+    }
+
+    put "Part 1: ", $larger-than-previous;
+}
+
+{
+    my Int $larger-than-previous = 0;
+
+    for (^@inputs.elems).skip(3) -> $idx {
+        $larger-than-previous++ if @inputs[$idx - 2 .. $idx].sum > @inputs[$idx - 3 .. $idx - 1].sum;
+    }
+
+    put "Part 2: ", $larger-than-previous;
+}