Watch
1
0
Fork
You've already forked advent-of-code
0

2024 Day 13 Part 2

This commit is contained in:
Jeremy Kaplan 2024-12-12 22:05:55 -08:00
commit 18555d687d

View file

@ -21,6 +21,7 @@ pub fn main() !void {
const stdout = bw.writer();
try stdout.print("{d}\n", .{try part1(games.items)});
try stdout.print("{d}\n", .{try part2(games.items)});
try bw.flush();
}
@ -34,6 +35,17 @@ fn part1(games: []const Game) !i64 {
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 {
x: i64,
y: i64,
@ -161,6 +173,14 @@ const Game = struct {
.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 {