From eb4dbb392e4afabb90fa1da507b5c63e6ef194eb Mon Sep 17 00:00:00 2001 From: Dazbo Date: Sat, 30 Dec 2023 10:55:25 +0000 Subject: [PATCH] Updating walkthroughs --- .../Dazbo's_Advent_of_Code_2023.ipynb | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb b/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb index 39e3991..820d5a3 100644 --- a/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb +++ b/src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb @@ -2314,7 +2314,7 @@ "Distance: 9 40 200\n", "```\n", "\n", - "Our boat starts at 0mm/ms. Charing of 1ms increases speed by 1mm/ms.\n", + "Our boat starts at 0mm/ms. Charging of 1ms increases speed by 1mm/ms.\n", "\n", "**Determine the number of ways you could beat the record in each race. What do you get if you multiply these numbers together?**\n", "\n", @@ -2335,17 +2335,15 @@ "outputs": [], "source": [ "def solve_part1(data):\n", - " _, durations_part = data[0].split(\":\")\n", - " _, distances_part = data[1].split(\":\")\n", - " durations = [int(x) for x in durations_part.split()]\n", - " distances = [int(x) for x in distances_part.split()]\n", - " \n", + " durations = [int(x) for x in data[0].split(\":\")[1].split()]\n", + " distances = [int(x) for x in data[1].split(\":\")[1].split()]\n", " logger.debug(f\"{durations=}\")\n", " logger.debug(f\"{distances=}\")\n", " \n", " wins = defaultdict(dict) # { race_num: { hold_time: distance, hold_time: distance, ...} }\n", " for i, duration in enumerate(durations): # e.g. 0, 7\n", " for hold_time in range(1, duration): # e.g. 0-7\n", + " # d = (t - h) * h\n", " d = (duration - hold_time) * hold_time\n", " if d > distances[i]: # did we win?\n", " wins[i][hold_time] = d\n", @@ -2385,7 +2383,7 @@ "source": [ "### Day 6 Part 2\n", "\n", - "Uh oh, there's only one race and the spaces should be ignored. E.g.\n", + "Uh oh, there's only one race and the spaces should be ignored. So we reinterpret the input like this:\n", "\n", "```text\n", "Time: 71530\n", @@ -2420,10 +2418,14 @@ "Remember the quadratic formula?\n", "\n", "$$\n", - "x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}\n", + "\\begin{align}\n", + "\\text{For: } ah^2 + bh + c &= 0 \\\\\n", + "\\notag \\\\\n", + "h &= \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}\n", + "\\end{align}\n", "$$\n", "\n", - "So we can use this to obtain the two roots, i.e. the hold times where where our distance is equal to the record distance. Using the sample data we were given:\n", + "So we can use this to obtain the two roots, i.e. the hold times where where our distance is equal to the record distance. We're given distance $d$ and one duration $t$ in our input. (And we know $a$ is `1`.) Using the sample data we were given:\n", "\n", "$$\n", "h^2 - 71530h + 940200 = 0 \\\\\n", @@ -9873,9 +9875,9 @@ "toc_visible": true }, "kernelspec": { - "display_name": "aca_aoc", + "display_name": "ana-aoc", "language": "python", - "name": "aca_aoc" + "name": "python3" }, "language_info": { "codemirror_mode": {