blob: e870af68f50aee1e334347f2040b7fd4050cf91a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
}
|