Skip to content

Commit

Permalink
chore(gmacario/solutions): cleanup day13
Browse files Browse the repository at this point in the history
  • Loading branch information
gmacario committed Dec 21, 2024
1 parent 82b6d36 commit a5b56c2
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 87 deletions.
147 changes: 60 additions & 87 deletions solutions/gmacario/day13/day13.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,34 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "6b7c6dc6-b77c-47e0-ac97-33f7f86c484c",
"id": "39f6e9a6",
"metadata": {},
"outputs": [],
"source": [
"from icecream import ic\n",
"import time"
"# Parameters\n",
"# \n",
"day = 13\n",
"\n",
"FILENAME = \"day13_test1.txt\"\n",
"#\n",
"FILENAME = \"day13_input_gmacario.txt\""
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6c8149a1-7aed-4bfb-8ec9-748c65077d45",
"id": "6b7c6dc6-b77c-47e0-ac97-33f7f86c484c",
"metadata": {},
"outputs": [],
"source": [
"use_test = True # Comment out for using actual puzzle input"
]
},
{
"cell_type": "markdown",
"id": "f3458754-aa32-44e5-b229-4f519108459e",
"metadata": {},
"source": [
"## Part 1"
"# Import\n",
"from icecream import ic\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b8ac6332-ebd1-424b-a781-df1771e81be8",
"metadata": {},
"outputs": [],
"source": [
"try:\n",
" use_test\n",
"except NameError:\n",
" use_test = False\n",
" ic(\"use_test was undefined - forcing to\", use_test)\n",
" \n",
"FILENAME = \"input_day13_gmacario.txt\"\n",
"# FILENAME = \"test_day13_gmacario.txt\""
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "3ab24fb1",
"metadata": {},
"outputs": [],
Expand All @@ -74,24 +56,24 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "6ac2a9c0-ef2f-496b-acd2-f8b47c89860b",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ic| time.ctime(): 'Fri Dec 13 19:23:01 2024'\n"
"ic| time.ctime(): 'Sat Dec 21 11:53:46 2024'\n"
]
},
{
"data": {
"text/plain": [
"'Fri Dec 13 19:23:01 2024'"
"'Sat Dec 21 11:53:46 2024'"
]
},
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -122,51 +104,50 @@
" again = False\n",
"\n",
"# _ = ic(num_machines, machines)\n",
"tm_begin = time.time()\n",
"ic(time.ctime())"
]
},
{
"cell_type": "markdown",
"id": "f3458754-aa32-44e5-b229-4f519108459e",
"metadata": {},
"source": [
"## Part 1"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "3405f4a9",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ic| mach: {'A': (42, 24), 'B': (23, 55), 'P': (18849, 8875)}\n",
"ic| 'After push(A):', cost: 3, pos: (42, 24)\n",
"ic| 'After push(B):', cost: 4, pos: (65, 79)\n"
]
}
],
"outputs": [],
"source": [
"# Try some movement on machines[0]\n",
"\n",
"mach = machines[0]\n",
"ic(mach)\n",
"pos = (0, 0)\n",
"cost = 0\n",
"\n",
"# push(\"A\")\n",
"cost += 3\n",
"new_x = pos[0] + mach['A'][0]\n",
"new_y = pos[1] + mach['A'][1]\n",
"pos = (new_x, new_y)\n",
"_ = ic(\"After push(A):\", cost, pos)\n",
"\n",
"# push(\"B\")\n",
"cost += 1\n",
"new_x = pos[0] + mach['B'][0]\n",
"new_y = pos[1] + mach['B'][1]\n",
"pos = (new_x, new_y)\n",
"_ = ic(\"After push(B):\", cost, pos)"
"# # Try some movement on machines[0]\n",
"\n",
"# mach = machines[0]\n",
"# ic(mach)\n",
"# pos = (0, 0)\n",
"# cost = 0\n",
"\n",
"# # push(\"A\")\n",
"# cost += 3\n",
"# new_x = pos[0] + mach['A'][0]\n",
"# new_y = pos[1] + mach['A'][1]\n",
"# pos = (new_x, new_y)\n",
"# _ = ic(\"After push(A):\", cost, pos)\n",
"\n",
"# # push(\"B\")\n",
"# cost += 1\n",
"# new_x = pos[0] + mach['B'][0]\n",
"# new_y = pos[1] + mach['B'][1]\n",
"# pos = (new_x, new_y)\n",
"# _ = ic(\"After push(B):\", cost, pos)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"id": "76af24cf",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -202,7 +183,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"id": "62b2751e",
"metadata": {},
"outputs": [],
Expand All @@ -213,7 +194,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"id": "a68adc94",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -266,7 +247,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"id": "abd745f8",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -302,7 +283,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 10,
"id": "15eda2ff",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -331,7 +312,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"id": "793a08d6-09b2-45be-86a8-96b2a41891e3",
"metadata": {},
"outputs": [
Expand All @@ -340,7 +321,7 @@
"output_type": "stream",
"text": [
"ic| \"elapsed=\": 'elapsed='\n",
" tm_end - tm_begin: 0.0007228851318359375\n",
" tm_end - tm_begin: 0.18650245666503906\n",
" \"result=\": 'result='\n",
" part1_result: 37680\n"
]
Expand All @@ -358,7 +339,7 @@
"def solve_part1():\n",
" return sum_cheapest_sequences(machines)\n",
"\n",
"tm_begin = time.time()\n",
"# tm_begin = time.time()\n",
"part1_result = solve_part1()\n",
"tm_end = time.time()\n",
"ic(\"elapsed=\", tm_end - tm_begin, \"result=\", part1_result)\n",
Expand All @@ -376,7 +357,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 12,
"id": "07549d49",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -413,7 +394,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 13,
"id": "9db4b5d8-8a95-4bd3-807b-1bf14d991d90",
"metadata": {},
"outputs": [
Expand All @@ -422,7 +403,7 @@
"output_type": "stream",
"text": [
"ic| \"elapsed=\": 'elapsed='\n",
" tm_end - tm_begin: 0.0009219646453857422\n",
" tm_end - tm_begin: 0.31586480140686035\n",
" \"result=\": 'result='\n",
" part2_result: 87550094242995\n"
]
Expand All @@ -440,26 +421,18 @@
"def solve_part2():\n",
" return sum_cheapest_sequences(machines_corrected, initial_pos)\n",
"\n",
"tm_begin = time.time()\n",
"# tm_begin = time.time()\n",
"part2_result = solve_part2()\n",
"tm_end = time.time()\n",
"ic(\"elapsed=\", tm_end - tm_begin, \"result=\", part2_result)\n",
"print(\"Day 13 Part 2 RESULT:\")\n",
"print(part2_result)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a720e89f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "aoc-2024-Uq7HKp2W-py3.12",
"display_name": "aoc-2024-9IjWec8A-py3.12",
"language": "python",
"name": "python3"
},
Expand Down
File renamed without changes.

0 comments on commit a5b56c2

Please sign in to comment.