Skip to content

Commit

Permalink
Updating walkthroughs
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed-dash committed Dec 30, 2023
1 parent 6cf19f1 commit eb4dbb3
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/AoC_2023/Dazbo's_Advent_of_Code_2023.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit eb4dbb3

Please sign in to comment.