From ab09b350494972da30f232be9e207140b1cd3b11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Da=CC=81vid=20Ne=CC=81meth=20Cs?= Date: Tue, 10 Dec 2024 08:46:44 +0100 Subject: [PATCH] 2024/09 writeup --- 2024/Day09/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/2024/Day09/README.md b/2024/Day09/README.md index 2ac04e9f..29d99b0d 100644 --- a/2024/Day09/README.md +++ b/2024/Day09/README.md @@ -4,3 +4,7 @@ Another push of the button leaves you in the familiar hallways of some friendly While The Historians quickly figure out how to pilot these things, you notice an amphipod in the corner struggling with his computer. He's trying to make more contiguous free space by compacting all of the files, but his program isn't working; you offer to help. Read the [full puzzle](https://adventofcode.com/2024/day/9). + +I'm taking a break from using LINQ today and turning my attention to the low-level world of linked lists instead. I discovered a way to express both paths using a single `CompactFs` function with a `fragmentsEnabled` parameter. `CompactFs` operates with two pointers, `i` and `j`, which define the scan range we’re working on. `i` starts at the beginning of the disk, while `j` starts at the end and moves backward. When `i` points to a free space and `j` points to a used space, we call `RelocateBlock`, which moves `j` (or parts of `j`, depending on whether fragmentation is enabled) to a free space found after `i`. + +The rest involves careful pointer arithmetic and linked list management, where I aim to avoid overwriting the data I’ll need in the next line. I find this surprisingly hard to get right when working with linked lists... \ No newline at end of file