2024 Day 13 Part 2
This commit is contained in:
parent
9f8d43f97a
commit
18555d687d
1 changed files with 20 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ pub fn main() !void {
|
||||||
const stdout = bw.writer();
|
const stdout = bw.writer();
|
||||||
|
|
||||||
try stdout.print("{d}\n", .{try part1(games.items)});
|
try stdout.print("{d}\n", .{try part1(games.items)});
|
||||||
|
try stdout.print("{d}\n", .{try part2(games.items)});
|
||||||
try bw.flush();
|
try bw.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,6 +35,17 @@ fn part1(games: []const Game) !i64 {
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn part2(games: []const Game) !i64 {
|
||||||
|
var total: i64 = 0;
|
||||||
|
for (games) |game| {
|
||||||
|
const modded = game.mod(10000000000000);
|
||||||
|
const buttons = modded.solve() orelse continue;
|
||||||
|
const cost = 3 * buttons.a + 1 * buttons.b;
|
||||||
|
total += cost;
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
const Pos = struct {
|
const Pos = struct {
|
||||||
x: i64,
|
x: i64,
|
||||||
y: i64,
|
y: i64,
|
||||||
|
|
@ -161,6 +173,14 @@ const Game = struct {
|
||||||
.b = @intCast(nB),
|
.b = @intCast(nB),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mod(self: Game, delta: i64) Game {
|
||||||
|
return Game{
|
||||||
|
.a = self.a,
|
||||||
|
.b = self.b,
|
||||||
|
.prize = self.prize.add(Move.new(delta, delta)),
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fn takeLiteral(input: []const u8, want: []const u8) ?[]const u8 {
|
fn takeLiteral(input: []const u8, want: []const u8) ?[]const u8 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue