diff --git a/src/day09.zig b/src/day09.zig index f4ae708..25438f1 100644 --- a/src/day09.zig +++ b/src/day09.zig @@ -46,14 +46,10 @@ fn solve(alloc: mem.Allocator, input: []const u8) !Solution { // Extrapolate var next: isize = 0; var prev: isize = 0; - for (seqs.items) |seq| { - next += seq[seq.len - 1]; - } for (0..seqs.items.len) |i| { - prev = seqs.items[seqs.items.len - i - 1][0] - prev; - } - for (seqs.items) |seq| { - // Clean up + const seq = seqs.items[seqs.items.len - i - 1]; + prev = seq[0] - prev; + next += seq[seq.len - 1]; alloc.free(seq); } prev_sum += prev;