From 5ff8fafcb57cf908dd18a893ca0448ee0dbd6668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Wed, 25 Sep 2024 19:44:09 +0200 Subject: [PATCH] Fixed typos in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61badee..d3dc008 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ The algorithm processes the numbers in the middle line and looks for additional ### Day 4: Scratchcards -:mag_right: Puzzle: , :white_check_mark: Solver: [`UScratchCards.pas`](solvers/UScratchCards.pas) +:mag_right: Puzzle: , :white_check_mark: Solver: [`UScratchcards.pas`](solvers/UScratchcards.pas) For part 1, the algorithm simply matches winning numbers against numbers we have, and multiplies the current line result by two for every match (except the first). @@ -152,7 +152,7 @@ The main modification to the classic algorithm here is that in order to calculat :star: :mag_right: Puzzle: , :white_check_mark: Solver: [`ULavaductLagoon.pas`](solvers/ULavaductLagoon.pas) -My first algorithm for part 1 was a simply tracking the trench in a top-view two-dimensional array and then flood-filling the outside of the trench to determine the full area. It worked, but there were two problems. Firstly, I had to iteratre over the list of digs twice in order to avoid resizing the array frequently. Secondly, the performance complexity of the algorthim depends largely on the size of the array, i.e. the length of the individual digs, so obviously it did not scale for part2. +My first algorithm for part 1 was a simply tracking the trench in a top-view two-dimensional array and then flood-filling the outside of the trench to determine the full area. It worked, but there were two problems. Firstly, I had to iteratre over the list of digs twice in order to avoid resizing the array frequently. Secondly, the performance complexity of the algorthim depends largely on the size of the array, i.e. the length of the individual digs, so obviously it did not scale for part 2. The final algorithm, uses the fact that either all right turns are convex or concave, locally, while all left turns are the opposite. That means that two consecutive turns in the same direction (a U-turn) enclose a rectangular area that is either inside or outside of the trench depending only on the direction of the two turns. So the algorthim simply collapses all U-turns it encounters into a straight dig instruction, thereby cutting of an area that is either added to or subtracted from the running area count.