From b5583ca46effb46d3b9fcc3a7dc04b8a650f401f Mon Sep 17 00:00:00 2001 From: xeals Date: Sat, 9 Dec 2023 20:46:40 +1100 Subject: [PATCH] clean day09 --- src/day09.zig | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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;