Skip to content

Commit

Permalink
Refactor getting the day
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed-dash committed Dec 8, 2024
1 parent 885e3d0 commit 1410276
Showing 1 changed file with 135 additions and 19 deletions.
154 changes: 135 additions & 19 deletions src/AoC_2024/Dazbo's_Advent_of_Code_2024.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@
" else:\n",
" raise ValueError(f\"Unable to retrieve input data.\\n\" +\n",
" f\"HTTP response: {response.status_code}\\n\" +\n",
" f\"{response.reason}: {response.content.decode('utf-8').strip()}\")\n"
" f\"{response.reason}: {response.content.decode('utf-8').strip()}\")\n",
" \n",
"def show_day_link(day):\n",
" day_link = f\"#### See [Day {day}](https://adventofcode.com/{YEAR}/day/{day}).\"\n",
" display(Markdown(day_link))\n"
]
},
{
Expand Down Expand Up @@ -644,8 +648,7 @@
"outputs": [],
"source": [
"DAY = \"1\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -858,8 +861,7 @@
"outputs": [],
"source": [
"DAY = \"2\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -1060,8 +1062,7 @@
"outputs": [],
"source": [
"DAY = \"3\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -1249,8 +1250,7 @@
"outputs": [],
"source": [
"DAY = \"4\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -1504,8 +1504,7 @@
"outputs": [],
"source": [
"DAY = \"5\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -1891,8 +1890,7 @@
"outputs": [],
"source": [
"DAY = \"6\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -2388,8 +2386,7 @@
"outputs": [],
"source": [
"DAY = \"7\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -2654,8 +2651,7 @@
"outputs": [],
"source": [
"DAY = \"8\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down Expand Up @@ -2957,6 +2953,127 @@
"logger.info(f\"Part 2 soln={soln}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"## Day 9: title"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"DAY = \"9\" # replace with actual number (without leading digit)\n",
"show_day_link(DAY)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d_name = \"d\" + str(DAY).zfill(2) # e.g. d01\n",
"script_name = \"aoc\" + str(YEAR) + d_name # e.g. aoc2024d01\n",
"locations = dc.get_locations(d_name)\n",
"logger.setLevel(logging.DEBUG)\n",
"# td.setup_file_logging(logger, locations.output_dir)\n",
"\n",
"# Retrieve input and store in local file\n",
"try:\n",
" write_puzzle_input_file(YEAR, DAY, locations)\n",
" with open(locations.input_file, mode=\"rt\") as f:\n",
" input_data = f.read().splitlines()\n",
"\n",
" logger.info(\"Input data:\\n%s\", dc.top_and_tail(input_data))\n",
"except ValueError as e:\n",
" logger.error(e)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Day 9 Part 1\n",
"\n",
"Overview..."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def solve_part1(data):\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"sample_inputs = []\n",
"sample_inputs.append(\"\"\"abcdef\"\"\")\n",
"sample_answers = [\"uvwxyz\"]\n",
"\n",
"for curr_input, curr_ans in zip(sample_inputs, sample_answers):\n",
" validate(solve_part1(curr_input), curr_ans) # test with sample data\n",
" logger.info(\"Test passed\")\n",
"\n",
"logger.info(\"All tests passed!\")\n",
"\n",
"soln = solve_part1(input_data)\n",
"logger.info(f\"Part 1 soln={soln}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Day 9 Part 2\n",
"\n",
"Overview..."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def solve_part2(data):\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"sample_inputs = []\n",
"sample_inputs.append(\"\"\"abcdef\"\"\")\n",
"sample_answers = [\"uvwxyz\"]\n",
"\n",
"for curr_input, curr_ans in zip(sample_inputs, sample_answers):\n",
" validate(solve_part2(curr_input), curr_ans) # test with sample data\n",
" logger.info(\"Test passed\") \n",
"\n",
"logger.info(\"Tests passed!\")\n",
"\n",
"soln = solve_part2(input_data)\n",
"logger.info(f\"Part 2 soln={soln}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -2972,8 +3089,7 @@
"outputs": [],
"source": [
"DAY = \"n\" # replace with actual number (without leading digit)\n",
"day_link = f\"#### See [Day {DAY}](https://adventofcode.com/{YEAR}/day/{DAY}).\"\n",
"display(Markdown(day_link))"
"show_day_link(DAY)"
]
},
{
Expand Down

0 comments on commit 1410276

Please sign in to comment.