summary refs log tree commit diff stats
path: root/2020/day-13/day-13.raku
diff options
context:
space:
mode:
Diffstat (limited to '2020/day-13/day-13.raku')
-rwxr-xr-x2020/day-13/day-13.raku35
1 files changed, 35 insertions, 0 deletions
diff --git a/2020/day-13/day-13.raku b/2020/day-13/day-13.raku
new file mode 100755
index 0000000..e870af6
--- /dev/null
+++ b/2020/day-13/day-13.raku
@@ -0,0 +1,35 @@
+#!/usr/bin/env raku
+
+unit sub MAIN(
+    IO() $file = "input" #= input file
+);
+
+my @input = $file.IO.lines;
+
+{
+    my Int $start = @input[0].Int;
+    my Int @bus_ids = @input[1].split(",").grep(/\d+/)>>.Int;
+
+    stamp: for $start .. Inf -> $stamp {
+        for @bus_ids -> $id {
+            next unless $stamp %% $id;
+            say "Part 1: " ~ $id * ($stamp - $start);
+            last stamp;
+        }
+    }
+}
+
+{
+    my @bus_ids = @input[1].split(",");
+
+    my Int $stamp = 0;
+    my Int $step = @bus_ids.first.Int;
+
+    id: for @bus_ids.kv[2..*] -> $idx, $id {
+        next id if $id eq "x";
+        $stamp += $step until ($stamp + $idx) %% $id;
+        $step lcm= $id;
+    }
+
+    say "Part 2: " ~ $stamp;
+}