const std = @import("std");
const PATH = "input/day25.txt";
const DENOMINATOR = 20201227;
pub fn first(allocator: ?std.mem.Allocator) anyerror!usize {
_ = allocator;
var lines = std.mem.tokenize(u8, @embedFile(PATH), "\n");
const pub1 = try std.fmt.parseUnsigned(usize, lines.next().?, 10);
const pub2 = try std.fmt.parseUnsigned(usize, lines.next().?, 10);
var pkey1: usize = 1;
var pkey2: usize = 1;
var ekey1: usize = 1;
var ekey2: usize = 1;
while (true) {
pkey1 = pkey1 * 7 % DENOMINATOR;
pkey2 = pkey2 * 7 % DENOMINATOR;
ekey1 = ekey1 * pub1 % DENOMINATOR;
ekey2 = ekey2 * pub2 % DENOMINATOR;
if (pkey1 == pub2) return ekey1;
if (pkey2 == pub1) return ekey2;
}
unreachable;
}
test "day25a" {
try std.testing.expectEqual(@as(usize, 16457981), try first(std.testing.allocator));
}
const test_input =
\\5764801
\\17807724
;