Compare commits
No commits in common. "2023" and "main" have entirely different histories.
72 changed files with 151778 additions and 3214 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
yarn-*.cjs
|
8
AdventOfCode.code-workspace
Normal file
8
AdventOfCode.code-workspace
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
],
|
||||
"settings": {}
|
||||
}
|
1
Python/day1/input
Normal file
1
Python/day1/input
Normal file
File diff suppressed because one or more lines are too long
132
Python/day1/solution.ipynb
Normal file
132
Python/day1/solution.ipynb
Normal file
|
@ -0,0 +1,132 @@
|
|||
{
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6-final"
|
||||
},
|
||||
"orig_nbformat": 2,
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3.8.6 64-bit",
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "1ddf53fa84779e14f0db18342168679c9c165a81c5f324dac828befab228d68d"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get puzzle input from input file\n",
|
||||
"\n",
|
||||
"puzzle_input = open(\"input\").read()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 1 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"ups = puzzle_input.count(\"(\")\n",
|
||||
"downs = puzzle_input.count(\")\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"end_floor = ups - downs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"print(end_floor)"
|
||||
],
|
||||
"cell_type": "code",
|
||||
"metadata": {},
|
||||
"execution_count": 13,
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"138\n"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 2 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"current_floor = 0"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"index = 0\n",
|
||||
"while current_floor >= 0 and index < len(puzzle_input):\n",
|
||||
" if puzzle_input[index] == \"(\":\n",
|
||||
" current_floor += 1\n",
|
||||
" elif puzzle_input[index] == \")\":\n",
|
||||
" current_floor -= 1\n",
|
||||
" index += 1"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"1771\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"print(index)"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
1000
Python/day2/input
Normal file
1000
Python/day2/input
Normal file
File diff suppressed because it is too large
Load diff
104
Python/day2/solution.ipynb
Normal file
104
Python/day2/solution.ipynb
Normal file
|
@ -0,0 +1,104 @@
|
|||
{
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6-final"
|
||||
},
|
||||
"orig_nbformat": 2,
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3.8.6 64-bit",
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "1ddf53fa84779e14f0db18342168679c9c165a81c5f324dac828befab228d68d"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get puzzle input from input file\n",
|
||||
"\n",
|
||||
"puzzle_input = open(\"input\").read().split(\"\\n\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 1 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"1606483\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"wrapping_paper = 0\n",
|
||||
"for packet in puzzle_input:\n",
|
||||
" l, w, h = map(lambda val: int(val), packet.split(\"x\"))\n",
|
||||
" # the surface area of the box, which is 2*l*w + 2*w*h + 2*h*l\n",
|
||||
" sides = [l*w*2, w*h*2, l*h*2]\n",
|
||||
" # extra paper for each present: the area of the smallest side.\n",
|
||||
" wrapping_paper += sum(sides) + int(min(sides)/2)\n",
|
||||
"print(wrapping_paper)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 2 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"3842356\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"ribbon = 0\n",
|
||||
"for packet in puzzle_input:\n",
|
||||
" l, w, h = map(lambda val: int(val), packet.split(\"x\"))\n",
|
||||
" # the feet of ribbon required for the perfect bow is equal to the cubic feet of volume of the present\n",
|
||||
" ribbon += l*w*h\n",
|
||||
" # The ribbon required to wrap a present is the shortest distance around its sides, or the smallest perimeter of any one face\n",
|
||||
" x, y = sorted([l, w, h])[0:2]\n",
|
||||
" ribbon += 2*x + 2*y\n",
|
||||
"print(ribbon)"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
1
Python/day3/input
Normal file
1
Python/day3/input
Normal file
File diff suppressed because one or more lines are too long
123
Python/day3/solution.ipynb
Normal file
123
Python/day3/solution.ipynb
Normal file
|
@ -0,0 +1,123 @@
|
|||
{
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6-final"
|
||||
},
|
||||
"orig_nbformat": 2,
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3.8.6 64-bit",
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "1ddf53fa84779e14f0db18342168679c9c165a81c5f324dac828befab228d68d"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get puzzle input from input file\n",
|
||||
"\n",
|
||||
"puzzle_input = open(\"input\").read()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 1 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"2572\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"delivered = {(0,0)}\n",
|
||||
"\n",
|
||||
"x, y = 0, 0\n",
|
||||
"ops = {\n",
|
||||
" \"^\": [+0, +1],\n",
|
||||
" \"v\": [-0, -1],\n",
|
||||
" \"<\": [-1, -0],\n",
|
||||
" \">\": [+1, +0]\n",
|
||||
"}\n",
|
||||
"for char in puzzle_input:\n",
|
||||
" dx, dy = ops[char]\n",
|
||||
" x += dx\n",
|
||||
" y += dy\n",
|
||||
" delivered.add((x, y))\n",
|
||||
"print(len(delivered))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 2 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"2631\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"delivered = {(0,0)}\n",
|
||||
"\n",
|
||||
"santa = (0, 0)\n",
|
||||
"robo_santa = (0, 0)\n",
|
||||
"ops = {\n",
|
||||
" \"^\": [+0, +1],\n",
|
||||
" \"v\": [-0, -1],\n",
|
||||
" \"<\": [-1, -0],\n",
|
||||
" \">\": [+1, +0]\n",
|
||||
"}\n",
|
||||
"robot = False\n",
|
||||
"for char in puzzle_input:\n",
|
||||
" dx, dy = ops[char]\n",
|
||||
" if robot:\n",
|
||||
" robo_santa = (robo_santa[0]+dx, robo_santa[1]+dy)\n",
|
||||
" delivered.add(robo_santa)\n",
|
||||
" else:\n",
|
||||
" santa = (santa[0]+dx, santa[1]+dy)\n",
|
||||
" delivered.add(santa)\n",
|
||||
" robot = not robot\n",
|
||||
"print(len(delivered))"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
1
Python/day4/input
Normal file
1
Python/day4/input
Normal file
|
@ -0,0 +1 @@
|
|||
yzbqklnj
|
112
Python/day4/solution.ipynb
Normal file
112
Python/day4/solution.ipynb
Normal file
|
@ -0,0 +1,112 @@
|
|||
{
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6-final"
|
||||
},
|
||||
"orig_nbformat": 2,
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3.8.6 64-bit",
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "1ddf53fa84779e14f0db18342168679c9c165a81c5f324dac828befab228d68d"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import hashlib"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get puzzle input from input file\n",
|
||||
"\n",
|
||||
"puzzle_input = open(\"input\").read()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 1 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"282749\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"current_hash = \"\"\n",
|
||||
"i = 0\n",
|
||||
"while not current_hash[0:5] == \"00000\":\n",
|
||||
" i += 1\n",
|
||||
" md5 = hashlib.md5(f\"{puzzle_input}{i}\".encode(\"utf-8\"))\n",
|
||||
" current_hash = md5.hexdigest()\n",
|
||||
"print(i)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 2 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"output_type": "stream",
|
||||
"name": "stdout",
|
||||
"text": [
|
||||
"9962624\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"current_hash = \"\"\n",
|
||||
"i = 0\n",
|
||||
"while not current_hash[0:6] == \"000000\":\n",
|
||||
" i += 1\n",
|
||||
" md5 = hashlib.md5(f\"{puzzle_input}{i}\".encode(\"utf-8\"))\n",
|
||||
" current_hash = md5.hexdigest()\n",
|
||||
"print(i)"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
1000
Python/day5/input
Normal file
1000
Python/day5/input
Normal file
File diff suppressed because it is too large
Load diff
119
Python/day5/solution.ipynb
Normal file
119
Python/day5/solution.ipynb
Normal file
|
@ -0,0 +1,119 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import re"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get puzzle input from input file\n",
|
||||
"\n",
|
||||
"puzzle_input = open(\"input\").read().split(\"\\n\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Part 1 #"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"238\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"double_letter_test = re.compile(r\"(.)\\1\", re.IGNORECASE)\n",
|
||||
"unnice_test = re.compile(r\"ab|cd|pq|xy\", re.IGNORECASE)\n",
|
||||
"\n",
|
||||
"def filter_function_part_one(line: str) -> bool:\n",
|
||||
" return (sum(map(line.lower().count, \"aeiou\")) >= 3) and bool(not unnice_test.search(line)) and bool(double_letter_test.search(line))\n",
|
||||
"\n",
|
||||
"filtered_lines = list(filter(\n",
|
||||
" filter_function_part_one,\n",
|
||||
" puzzle_input\n",
|
||||
"))\n",
|
||||
"print(len(filtered_lines))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Part 2 #"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"69\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def filter_function_part_two(line: str) -> bool:\n",
|
||||
" return re.findall(r\"(..).*\\1\", line) and re.findall(r\"(.).\\1\", line)\n",
|
||||
"\n",
|
||||
"filtered_lines = filter(\n",
|
||||
" filter_function_part_two,\n",
|
||||
" puzzle_input\n",
|
||||
")\n",
|
||||
"print(len(list(filtered_lines)))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
300
Python/day6/input
Normal file
300
Python/day6/input
Normal file
|
@ -0,0 +1,300 @@
|
|||
turn off 660,55 through 986,197
|
||||
turn off 341,304 through 638,850
|
||||
turn off 199,133 through 461,193
|
||||
toggle 322,558 through 977,958
|
||||
toggle 537,781 through 687,941
|
||||
turn on 226,196 through 599,390
|
||||
turn on 240,129 through 703,297
|
||||
turn on 317,329 through 451,798
|
||||
turn on 957,736 through 977,890
|
||||
turn on 263,530 through 559,664
|
||||
turn on 158,270 through 243,802
|
||||
toggle 223,39 through 454,511
|
||||
toggle 544,218 through 979,872
|
||||
turn on 313,306 through 363,621
|
||||
toggle 173,401 through 496,407
|
||||
toggle 333,60 through 748,159
|
||||
turn off 87,577 through 484,608
|
||||
turn on 809,648 through 826,999
|
||||
toggle 352,432 through 628,550
|
||||
turn off 197,408 through 579,569
|
||||
turn off 1,629 through 802,633
|
||||
turn off 61,44 through 567,111
|
||||
toggle 880,25 through 903,973
|
||||
turn on 347,123 through 864,746
|
||||
toggle 728,877 through 996,975
|
||||
turn on 121,895 through 349,906
|
||||
turn on 888,547 through 931,628
|
||||
toggle 398,782 through 834,882
|
||||
turn on 966,850 through 989,953
|
||||
turn off 891,543 through 914,991
|
||||
toggle 908,77 through 916,117
|
||||
turn on 576,900 through 943,934
|
||||
turn off 580,170 through 963,206
|
||||
turn on 184,638 through 192,944
|
||||
toggle 940,147 through 978,730
|
||||
turn off 854,56 through 965,591
|
||||
toggle 717,172 through 947,995
|
||||
toggle 426,987 through 705,998
|
||||
turn on 987,157 through 992,278
|
||||
toggle 995,774 through 997,784
|
||||
turn off 796,96 through 845,182
|
||||
turn off 451,87 through 711,655
|
||||
turn off 380,93 through 968,676
|
||||
turn on 263,468 through 343,534
|
||||
turn on 917,936 through 928,959
|
||||
toggle 478,7 through 573,148
|
||||
turn off 428,339 through 603,624
|
||||
turn off 400,880 through 914,953
|
||||
toggle 679,428 through 752,779
|
||||
turn off 697,981 through 709,986
|
||||
toggle 482,566 through 505,725
|
||||
turn off 956,368 through 993,516
|
||||
toggle 735,823 through 783,883
|
||||
turn off 48,487 through 892,496
|
||||
turn off 116,680 through 564,819
|
||||
turn on 633,865 through 729,930
|
||||
turn off 314,618 through 571,922
|
||||
toggle 138,166 through 936,266
|
||||
turn on 444,732 through 664,960
|
||||
turn off 109,337 through 972,497
|
||||
turn off 51,432 through 77,996
|
||||
turn off 259,297 through 366,744
|
||||
toggle 801,130 through 917,544
|
||||
toggle 767,982 through 847,996
|
||||
turn on 216,507 through 863,885
|
||||
turn off 61,441 through 465,731
|
||||
turn on 849,970 through 944,987
|
||||
toggle 845,76 through 852,951
|
||||
toggle 732,615 through 851,936
|
||||
toggle 251,128 through 454,778
|
||||
turn on 324,429 through 352,539
|
||||
toggle 52,450 through 932,863
|
||||
turn off 449,379 through 789,490
|
||||
turn on 317,319 through 936,449
|
||||
toggle 887,670 through 957,838
|
||||
toggle 671,613 through 856,664
|
||||
turn off 186,648 through 985,991
|
||||
turn off 471,689 through 731,717
|
||||
toggle 91,331 through 750,758
|
||||
toggle 201,73 through 956,524
|
||||
toggle 82,614 through 520,686
|
||||
toggle 84,287 through 467,734
|
||||
turn off 132,367 through 208,838
|
||||
toggle 558,684 through 663,920
|
||||
turn on 237,952 through 265,997
|
||||
turn on 694,713 through 714,754
|
||||
turn on 632,523 through 862,827
|
||||
turn on 918,780 through 948,916
|
||||
turn on 349,586 through 663,976
|
||||
toggle 231,29 through 257,589
|
||||
toggle 886,428 through 902,993
|
||||
turn on 106,353 through 236,374
|
||||
turn on 734,577 through 759,684
|
||||
turn off 347,843 through 696,912
|
||||
turn on 286,699 through 964,883
|
||||
turn on 605,875 through 960,987
|
||||
turn off 328,286 through 869,461
|
||||
turn off 472,569 through 980,848
|
||||
toggle 673,573 through 702,884
|
||||
turn off 398,284 through 738,332
|
||||
turn on 158,50 through 284,411
|
||||
turn off 390,284 through 585,663
|
||||
turn on 156,579 through 646,581
|
||||
turn on 875,493 through 989,980
|
||||
toggle 486,391 through 924,539
|
||||
turn on 236,722 through 272,964
|
||||
toggle 228,282 through 470,581
|
||||
toggle 584,389 through 750,761
|
||||
turn off 899,516 through 900,925
|
||||
turn on 105,229 through 822,846
|
||||
turn off 253,77 through 371,877
|
||||
turn on 826,987 through 906,992
|
||||
turn off 13,152 through 615,931
|
||||
turn on 835,320 through 942,399
|
||||
turn on 463,504 through 536,720
|
||||
toggle 746,942 through 786,998
|
||||
turn off 867,333 through 965,403
|
||||
turn on 591,477 through 743,692
|
||||
turn off 403,437 through 508,908
|
||||
turn on 26,723 through 368,814
|
||||
turn on 409,485 through 799,809
|
||||
turn on 115,630 through 704,705
|
||||
turn off 228,183 through 317,220
|
||||
toggle 300,649 through 382,842
|
||||
turn off 495,365 through 745,562
|
||||
turn on 698,346 through 744,873
|
||||
turn on 822,932 through 951,934
|
||||
toggle 805,30 through 925,421
|
||||
toggle 441,152 through 653,274
|
||||
toggle 160,81 through 257,587
|
||||
turn off 350,781 through 532,917
|
||||
toggle 40,583 through 348,636
|
||||
turn on 280,306 through 483,395
|
||||
toggle 392,936 through 880,955
|
||||
toggle 496,591 through 851,934
|
||||
turn off 780,887 through 946,994
|
||||
turn off 205,735 through 281,863
|
||||
toggle 100,876 through 937,915
|
||||
turn on 392,393 through 702,878
|
||||
turn on 956,374 through 976,636
|
||||
toggle 478,262 through 894,775
|
||||
turn off 279,65 through 451,677
|
||||
turn on 397,541 through 809,847
|
||||
turn on 444,291 through 451,586
|
||||
toggle 721,408 through 861,598
|
||||
turn on 275,365 through 609,382
|
||||
turn on 736,24 through 839,72
|
||||
turn off 86,492 through 582,712
|
||||
turn on 676,676 through 709,703
|
||||
turn off 105,710 through 374,817
|
||||
toggle 328,748 through 845,757
|
||||
toggle 335,79 through 394,326
|
||||
toggle 193,157 through 633,885
|
||||
turn on 227,48 through 769,743
|
||||
toggle 148,333 through 614,568
|
||||
toggle 22,30 through 436,263
|
||||
toggle 547,447 through 688,969
|
||||
toggle 576,621 through 987,740
|
||||
turn on 711,334 through 799,515
|
||||
turn on 541,448 through 654,951
|
||||
toggle 792,199 through 798,990
|
||||
turn on 89,956 through 609,960
|
||||
toggle 724,433 through 929,630
|
||||
toggle 144,895 through 201,916
|
||||
toggle 226,730 through 632,871
|
||||
turn off 760,819 through 828,974
|
||||
toggle 887,180 through 940,310
|
||||
toggle 222,327 through 805,590
|
||||
turn off 630,824 through 885,963
|
||||
turn on 940,740 through 954,946
|
||||
turn on 193,373 through 779,515
|
||||
toggle 304,955 through 469,975
|
||||
turn off 405,480 through 546,960
|
||||
turn on 662,123 through 690,669
|
||||
turn off 615,238 through 750,714
|
||||
turn on 423,220 through 930,353
|
||||
turn on 329,769 through 358,970
|
||||
toggle 590,151 through 704,722
|
||||
turn off 884,539 through 894,671
|
||||
toggle 449,241 through 984,549
|
||||
toggle 449,260 through 496,464
|
||||
turn off 306,448 through 602,924
|
||||
turn on 286,805 through 555,901
|
||||
toggle 722,177 through 922,298
|
||||
toggle 491,554 through 723,753
|
||||
turn on 80,849 through 174,996
|
||||
turn off 296,561 through 530,856
|
||||
toggle 653,10 through 972,284
|
||||
toggle 529,236 through 672,614
|
||||
toggle 791,598 through 989,695
|
||||
turn on 19,45 through 575,757
|
||||
toggle 111,55 through 880,871
|
||||
turn off 197,897 through 943,982
|
||||
turn on 912,336 through 977,605
|
||||
toggle 101,221 through 537,450
|
||||
turn on 101,104 through 969,447
|
||||
toggle 71,527 through 587,717
|
||||
toggle 336,445 through 593,889
|
||||
toggle 214,179 through 575,699
|
||||
turn on 86,313 through 96,674
|
||||
toggle 566,427 through 906,888
|
||||
turn off 641,597 through 850,845
|
||||
turn on 606,524 through 883,704
|
||||
turn on 835,775 through 867,887
|
||||
toggle 547,301 through 897,515
|
||||
toggle 289,930 through 413,979
|
||||
turn on 361,122 through 457,226
|
||||
turn on 162,187 through 374,746
|
||||
turn on 348,461 through 454,675
|
||||
turn off 966,532 through 985,537
|
||||
turn on 172,354 through 630,606
|
||||
turn off 501,880 through 680,993
|
||||
turn off 8,70 through 566,592
|
||||
toggle 433,73 through 690,651
|
||||
toggle 840,798 through 902,971
|
||||
toggle 822,204 through 893,760
|
||||
turn off 453,496 through 649,795
|
||||
turn off 969,549 through 990,942
|
||||
turn off 789,28 through 930,267
|
||||
toggle 880,98 through 932,434
|
||||
toggle 568,674 through 669,753
|
||||
turn on 686,228 through 903,271
|
||||
turn on 263,995 through 478,999
|
||||
toggle 534,675 through 687,955
|
||||
turn off 342,434 through 592,986
|
||||
toggle 404,768 through 677,867
|
||||
toggle 126,723 through 978,987
|
||||
toggle 749,675 through 978,959
|
||||
turn off 445,330 through 446,885
|
||||
turn off 463,205 through 924,815
|
||||
turn off 417,430 through 915,472
|
||||
turn on 544,990 through 912,999
|
||||
turn off 201,255 through 834,789
|
||||
turn off 261,142 through 537,862
|
||||
turn off 562,934 through 832,984
|
||||
turn off 459,978 through 691,980
|
||||
turn off 73,911 through 971,972
|
||||
turn on 560,448 through 723,810
|
||||
turn on 204,630 through 217,854
|
||||
turn off 91,259 through 611,607
|
||||
turn on 877,32 through 978,815
|
||||
turn off 950,438 through 974,746
|
||||
toggle 426,30 through 609,917
|
||||
toggle 696,37 through 859,201
|
||||
toggle 242,417 through 682,572
|
||||
turn off 388,401 through 979,528
|
||||
turn off 79,345 through 848,685
|
||||
turn off 98,91 through 800,434
|
||||
toggle 650,700 through 972,843
|
||||
turn off 530,450 through 538,926
|
||||
turn on 428,559 through 962,909
|
||||
turn on 78,138 through 92,940
|
||||
toggle 194,117 through 867,157
|
||||
toggle 785,355 through 860,617
|
||||
turn off 379,441 through 935,708
|
||||
turn off 605,133 through 644,911
|
||||
toggle 10,963 through 484,975
|
||||
turn off 359,988 through 525,991
|
||||
turn off 509,138 through 787,411
|
||||
toggle 556,467 through 562,773
|
||||
turn on 119,486 through 246,900
|
||||
turn on 445,561 through 794,673
|
||||
turn off 598,681 through 978,921
|
||||
turn off 974,230 through 995,641
|
||||
turn off 760,75 through 800,275
|
||||
toggle 441,215 through 528,680
|
||||
turn off 701,636 through 928,877
|
||||
turn on 165,753 through 202,780
|
||||
toggle 501,412 through 998,516
|
||||
toggle 161,105 through 657,395
|
||||
turn on 113,340 through 472,972
|
||||
toggle 384,994 through 663,999
|
||||
turn on 969,994 through 983,997
|
||||
turn on 519,600 through 750,615
|
||||
turn off 363,899 through 948,935
|
||||
turn on 271,845 through 454,882
|
||||
turn off 376,528 through 779,640
|
||||
toggle 767,98 through 854,853
|
||||
toggle 107,322 through 378,688
|
||||
turn off 235,899 through 818,932
|
||||
turn on 445,611 through 532,705
|
||||
toggle 629,387 through 814,577
|
||||
toggle 112,414 through 387,421
|
||||
toggle 319,184 through 382,203
|
||||
turn on 627,796 through 973,940
|
||||
toggle 602,45 through 763,151
|
||||
turn off 441,375 through 974,545
|
||||
toggle 871,952 through 989,998
|
||||
turn on 717,272 through 850,817
|
||||
toggle 475,711 through 921,882
|
||||
toggle 66,191 through 757,481
|
||||
turn off 50,197 through 733,656
|
||||
toggle 83,575 through 915,728
|
||||
turn on 777,812 through 837,912
|
||||
turn on 20,984 through 571,994
|
||||
turn off 446,432 through 458,648
|
||||
turn on 715,871 through 722,890
|
||||
toggle 424,675 through 740,862
|
||||
toggle 580,592 through 671,900
|
||||
toggle 296,687 through 906,775
|
152
Python/day6/solution.ipynb
Normal file
152
Python/day6/solution.ipynb
Normal file
|
@ -0,0 +1,152 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import re"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get puzzle input from input file\n",
|
||||
"\n",
|
||||
"puzzle_input = open(\"input\").read()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def toggle(val: bool) -> bool:\n",
|
||||
" return not val\n",
|
||||
"\n",
|
||||
"def turn_off(val: bool) -> bool:\n",
|
||||
" return False\n",
|
||||
"\n",
|
||||
"def turn_on(val: bool) -> bool:\n",
|
||||
" return True"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Part 1 #"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"400410\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"lights = [[False]*1000 for i in range(1000)]\n",
|
||||
"for command in puzzle_input.split(\"\\n\"):\n",
|
||||
" if re.search(\"toggle\", command):\n",
|
||||
" method = toggle\n",
|
||||
" elif re.search(\"on\", command):\n",
|
||||
" method = turn_on\n",
|
||||
" else:\n",
|
||||
" method = turn_off\n",
|
||||
" \n",
|
||||
" points = re.search(r\"(\\d+,\\d+) through (\\d+,\\d+)\", command)\n",
|
||||
" point_a = tuple(map(int, points.group(1).split(\",\")))\n",
|
||||
" point_b = tuple(map(int, points.group(2).split(\",\")))\n",
|
||||
" \n",
|
||||
" for a in range(point_a[0], point_b[0]+1):\n",
|
||||
" for b in range(point_a[1], point_b[1]+1):\n",
|
||||
" lights[a][b] = method(lights[a][b])\n",
|
||||
"\n",
|
||||
"print(list(item for sublist in lights for item in sublist).count(True))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Part 2 #"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"15343601\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def toggle(val: bool) -> bool:\n",
|
||||
" return val+2\n",
|
||||
"\n",
|
||||
"def turn_off(val: bool) -> bool:\n",
|
||||
" return max(val-1, 0)\n",
|
||||
"\n",
|
||||
"def turn_on(val: bool) -> bool:\n",
|
||||
" return val+1\n",
|
||||
"\n",
|
||||
"lights = [[0]*1000 for i in range(1000)]\n",
|
||||
"for command in puzzle_input.split(\"\\n\"):\n",
|
||||
" if re.search(\"toggle\", command):\n",
|
||||
" method = toggle\n",
|
||||
" elif re.search(\"on\", command):\n",
|
||||
" method = turn_on\n",
|
||||
" else:\n",
|
||||
" method = turn_off\n",
|
||||
" \n",
|
||||
" points = re.search(r\"(\\d+,\\d+) through (\\d+,\\d+)\", command)\n",
|
||||
" point_a = tuple(map(int, points.group(1).split(\",\")))\n",
|
||||
" point_b = tuple(map(int, points.group(2).split(\",\")))\n",
|
||||
" \n",
|
||||
" for a in range(point_a[0], point_b[0]+1):\n",
|
||||
" for b in range(point_a[1], point_b[1]+1):\n",
|
||||
" lights[a][b] = method(lights[a][b])\n",
|
||||
"\n",
|
||||
"print(sum(list(item for sublist in lights for item in sublist)))"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 4
|
||||
}
|
55
Python/template/solution.ipynb
Normal file
55
Python/template/solution.ipynb
Normal file
|
@ -0,0 +1,55 @@
|
|||
{
|
||||
"metadata": {
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.8.6-final"
|
||||
},
|
||||
"orig_nbformat": 2,
|
||||
"kernelspec": {
|
||||
"name": "python3",
|
||||
"display_name": "Python 3.8.6 64-bit",
|
||||
"metadata": {
|
||||
"interpreter": {
|
||||
"hash": "1ddf53fa84779e14f0db18342168679c9c165a81c5f324dac828befab228d68d"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2,
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# Get puzzle input from input file\n",
|
||||
"\n",
|
||||
"puzzle_input = open(\"input\").read()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 1 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
},
|
||||
{
|
||||
"source": [
|
||||
"# Part 2 #"
|
||||
],
|
||||
"cell_type": "markdown",
|
||||
"metadata": {}
|
||||
}
|
||||
]
|
||||
}
|
5
TypeScript/day7/.yarnrc
Normal file
5
TypeScript/day7/.yarnrc
Normal file
|
@ -0,0 +1,5 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
yarn-path ".yarn/releases/yarn-1.22.10.cjs"
|
339
TypeScript/day7/input
Normal file
339
TypeScript/day7/input
Normal file
|
@ -0,0 +1,339 @@
|
|||
bn RSHIFT 2 -> bo
|
||||
lf RSHIFT 1 -> ly
|
||||
fo RSHIFT 3 -> fq
|
||||
cj OR cp -> cq
|
||||
fo OR fz -> ga
|
||||
t OR s -> u
|
||||
lx -> a
|
||||
NOT ax -> ay
|
||||
he RSHIFT 2 -> hf
|
||||
lf OR lq -> lr
|
||||
lr AND lt -> lu
|
||||
dy OR ej -> ek
|
||||
1 AND cx -> cy
|
||||
hb LSHIFT 1 -> hv
|
||||
1 AND bh -> bi
|
||||
ih AND ij -> ik
|
||||
c LSHIFT 1 -> t
|
||||
ea AND eb -> ed
|
||||
km OR kn -> ko
|
||||
NOT bw -> bx
|
||||
ci OR ct -> cu
|
||||
NOT p -> q
|
||||
lw OR lv -> lx
|
||||
NOT lo -> lp
|
||||
fp OR fv -> fw
|
||||
o AND q -> r
|
||||
dh AND dj -> dk
|
||||
ap LSHIFT 1 -> bj
|
||||
bk LSHIFT 1 -> ce
|
||||
NOT ii -> ij
|
||||
gh OR gi -> gj
|
||||
kk RSHIFT 1 -> ld
|
||||
lc LSHIFT 1 -> lw
|
||||
lb OR la -> lc
|
||||
1 AND am -> an
|
||||
gn AND gp -> gq
|
||||
lf RSHIFT 3 -> lh
|
||||
e OR f -> g
|
||||
lg AND lm -> lo
|
||||
ci RSHIFT 1 -> db
|
||||
cf LSHIFT 1 -> cz
|
||||
bn RSHIFT 1 -> cg
|
||||
et AND fe -> fg
|
||||
is OR it -> iu
|
||||
kw AND ky -> kz
|
||||
ck AND cl -> cn
|
||||
bj OR bi -> bk
|
||||
gj RSHIFT 1 -> hc
|
||||
iu AND jf -> jh
|
||||
NOT bs -> bt
|
||||
kk OR kv -> kw
|
||||
ks AND ku -> kv
|
||||
hz OR ik -> il
|
||||
b RSHIFT 1 -> v
|
||||
iu RSHIFT 1 -> jn
|
||||
fo RSHIFT 5 -> fr
|
||||
be AND bg -> bh
|
||||
ga AND gc -> gd
|
||||
hf OR hl -> hm
|
||||
ld OR le -> lf
|
||||
as RSHIFT 5 -> av
|
||||
fm OR fn -> fo
|
||||
hm AND ho -> hp
|
||||
lg OR lm -> ln
|
||||
NOT kx -> ky
|
||||
kk RSHIFT 3 -> km
|
||||
ek AND em -> en
|
||||
NOT ft -> fu
|
||||
NOT jh -> ji
|
||||
jn OR jo -> jp
|
||||
gj AND gu -> gw
|
||||
d AND j -> l
|
||||
et RSHIFT 1 -> fm
|
||||
jq OR jw -> jx
|
||||
ep OR eo -> eq
|
||||
lv LSHIFT 15 -> lz
|
||||
NOT ey -> ez
|
||||
jp RSHIFT 2 -> jq
|
||||
eg AND ei -> ej
|
||||
NOT dm -> dn
|
||||
jp AND ka -> kc
|
||||
as AND bd -> bf
|
||||
fk OR fj -> fl
|
||||
dw OR dx -> dy
|
||||
lj AND ll -> lm
|
||||
ec AND ee -> ef
|
||||
fq AND fr -> ft
|
||||
NOT kp -> kq
|
||||
ki OR kj -> kk
|
||||
cz OR cy -> da
|
||||
as RSHIFT 3 -> au
|
||||
an LSHIFT 15 -> ar
|
||||
fj LSHIFT 15 -> fn
|
||||
1 AND fi -> fj
|
||||
he RSHIFT 1 -> hx
|
||||
lf RSHIFT 2 -> lg
|
||||
kf LSHIFT 15 -> kj
|
||||
dz AND ef -> eh
|
||||
ib OR ic -> id
|
||||
lf RSHIFT 5 -> li
|
||||
bp OR bq -> br
|
||||
NOT gs -> gt
|
||||
fo RSHIFT 1 -> gh
|
||||
bz AND cb -> cc
|
||||
ea OR eb -> ec
|
||||
lf AND lq -> ls
|
||||
NOT l -> m
|
||||
hz RSHIFT 3 -> ib
|
||||
NOT di -> dj
|
||||
NOT lk -> ll
|
||||
jp RSHIFT 3 -> jr
|
||||
jp RSHIFT 5 -> js
|
||||
NOT bf -> bg
|
||||
s LSHIFT 15 -> w
|
||||
eq LSHIFT 1 -> fk
|
||||
jl OR jk -> jm
|
||||
hz AND ik -> im
|
||||
dz OR ef -> eg
|
||||
1 AND gy -> gz
|
||||
la LSHIFT 15 -> le
|
||||
br AND bt -> bu
|
||||
NOT cn -> co
|
||||
v OR w -> x
|
||||
d OR j -> k
|
||||
1 AND gd -> ge
|
||||
ia OR ig -> ih
|
||||
NOT go -> gp
|
||||
NOT ed -> ee
|
||||
jq AND jw -> jy
|
||||
et OR fe -> ff
|
||||
aw AND ay -> az
|
||||
ff AND fh -> fi
|
||||
ir LSHIFT 1 -> jl
|
||||
gg LSHIFT 1 -> ha
|
||||
x RSHIFT 2 -> y
|
||||
db OR dc -> dd
|
||||
bl OR bm -> bn
|
||||
ib AND ic -> ie
|
||||
x RSHIFT 3 -> z
|
||||
lh AND li -> lk
|
||||
ce OR cd -> cf
|
||||
NOT bb -> bc
|
||||
hi AND hk -> hl
|
||||
NOT gb -> gc
|
||||
1 AND r -> s
|
||||
fw AND fy -> fz
|
||||
fb AND fd -> fe
|
||||
1 AND en -> eo
|
||||
z OR aa -> ab
|
||||
bi LSHIFT 15 -> bm
|
||||
hg OR hh -> hi
|
||||
kh LSHIFT 1 -> lb
|
||||
cg OR ch -> ci
|
||||
1 AND kz -> la
|
||||
gf OR ge -> gg
|
||||
gj RSHIFT 2 -> gk
|
||||
dd RSHIFT 2 -> de
|
||||
NOT ls -> lt
|
||||
lh OR li -> lj
|
||||
jr OR js -> jt
|
||||
au AND av -> ax
|
||||
0 -> c
|
||||
he AND hp -> hr
|
||||
id AND if -> ig
|
||||
et RSHIFT 5 -> ew
|
||||
bp AND bq -> bs
|
||||
e AND f -> h
|
||||
ly OR lz -> ma
|
||||
1 AND lu -> lv
|
||||
NOT jd -> je
|
||||
ha OR gz -> hb
|
||||
dy RSHIFT 1 -> er
|
||||
iu RSHIFT 2 -> iv
|
||||
NOT hr -> hs
|
||||
as RSHIFT 1 -> bl
|
||||
kk RSHIFT 2 -> kl
|
||||
b AND n -> p
|
||||
ln AND lp -> lq
|
||||
cj AND cp -> cr
|
||||
dl AND dn -> do
|
||||
ci RSHIFT 2 -> cj
|
||||
as OR bd -> be
|
||||
ge LSHIFT 15 -> gi
|
||||
hz RSHIFT 5 -> ic
|
||||
dv LSHIFT 1 -> ep
|
||||
kl OR kr -> ks
|
||||
gj OR gu -> gv
|
||||
he RSHIFT 5 -> hh
|
||||
NOT fg -> fh
|
||||
hg AND hh -> hj
|
||||
b OR n -> o
|
||||
jk LSHIFT 15 -> jo
|
||||
gz LSHIFT 15 -> hd
|
||||
cy LSHIFT 15 -> dc
|
||||
kk RSHIFT 5 -> kn
|
||||
ci RSHIFT 3 -> ck
|
||||
at OR az -> ba
|
||||
iu RSHIFT 3 -> iw
|
||||
ko AND kq -> kr
|
||||
NOT eh -> ei
|
||||
aq OR ar -> as
|
||||
iy AND ja -> jb
|
||||
dd RSHIFT 3 -> df
|
||||
bn RSHIFT 3 -> bp
|
||||
1 AND cc -> cd
|
||||
at AND az -> bb
|
||||
x OR ai -> aj
|
||||
kk AND kv -> kx
|
||||
ao OR an -> ap
|
||||
dy RSHIFT 3 -> ea
|
||||
x RSHIFT 1 -> aq
|
||||
eu AND fa -> fc
|
||||
kl AND kr -> kt
|
||||
ia AND ig -> ii
|
||||
df AND dg -> di
|
||||
NOT fx -> fy
|
||||
k AND m -> n
|
||||
bn RSHIFT 5 -> bq
|
||||
km AND kn -> kp
|
||||
dt LSHIFT 15 -> dx
|
||||
hz RSHIFT 2 -> ia
|
||||
aj AND al -> am
|
||||
cd LSHIFT 15 -> ch
|
||||
hc OR hd -> he
|
||||
he RSHIFT 3 -> hg
|
||||
bn OR by -> bz
|
||||
NOT kt -> ku
|
||||
z AND aa -> ac
|
||||
NOT ak -> al
|
||||
cu AND cw -> cx
|
||||
NOT ie -> if
|
||||
dy RSHIFT 2 -> dz
|
||||
ip LSHIFT 15 -> it
|
||||
de OR dk -> dl
|
||||
au OR av -> aw
|
||||
jg AND ji -> jj
|
||||
ci AND ct -> cv
|
||||
dy RSHIFT 5 -> eb
|
||||
hx OR hy -> hz
|
||||
eu OR fa -> fb
|
||||
gj RSHIFT 3 -> gl
|
||||
fo AND fz -> gb
|
||||
1 AND jj -> jk
|
||||
jp OR ka -> kb
|
||||
de AND dk -> dm
|
||||
ex AND ez -> fa
|
||||
df OR dg -> dh
|
||||
iv OR jb -> jc
|
||||
x RSHIFT 5 -> aa
|
||||
NOT hj -> hk
|
||||
NOT im -> in
|
||||
fl LSHIFT 1 -> gf
|
||||
hu LSHIFT 15 -> hy
|
||||
iq OR ip -> ir
|
||||
iu RSHIFT 5 -> ix
|
||||
NOT fc -> fd
|
||||
NOT el -> em
|
||||
ck OR cl -> cm
|
||||
et RSHIFT 3 -> ev
|
||||
hw LSHIFT 1 -> iq
|
||||
ci RSHIFT 5 -> cl
|
||||
iv AND jb -> jd
|
||||
dd RSHIFT 5 -> dg
|
||||
as RSHIFT 2 -> at
|
||||
NOT jy -> jz
|
||||
af AND ah -> ai
|
||||
1 AND ds -> dt
|
||||
jx AND jz -> ka
|
||||
da LSHIFT 1 -> du
|
||||
fs AND fu -> fv
|
||||
jp RSHIFT 1 -> ki
|
||||
iw AND ix -> iz
|
||||
iw OR ix -> iy
|
||||
eo LSHIFT 15 -> es
|
||||
ev AND ew -> ey
|
||||
ba AND bc -> bd
|
||||
fp AND fv -> fx
|
||||
jc AND je -> jf
|
||||
et RSHIFT 2 -> eu
|
||||
kg OR kf -> kh
|
||||
iu OR jf -> jg
|
||||
er OR es -> et
|
||||
fo RSHIFT 2 -> fp
|
||||
NOT ca -> cb
|
||||
bv AND bx -> by
|
||||
u LSHIFT 1 -> ao
|
||||
cm AND co -> cp
|
||||
y OR ae -> af
|
||||
bn AND by -> ca
|
||||
1 AND ke -> kf
|
||||
jt AND jv -> jw
|
||||
fq OR fr -> fs
|
||||
dy AND ej -> el
|
||||
NOT kc -> kd
|
||||
ev OR ew -> ex
|
||||
dd OR do -> dp
|
||||
NOT cv -> cw
|
||||
gr AND gt -> gu
|
||||
dd RSHIFT 1 -> dw
|
||||
NOT gw -> gx
|
||||
NOT iz -> ja
|
||||
1 AND io -> ip
|
||||
NOT ag -> ah
|
||||
b RSHIFT 5 -> f
|
||||
NOT cr -> cs
|
||||
kb AND kd -> ke
|
||||
jr AND js -> ju
|
||||
cq AND cs -> ct
|
||||
il AND in -> io
|
||||
NOT ju -> jv
|
||||
du OR dt -> dv
|
||||
dd AND do -> dq
|
||||
b RSHIFT 2 -> d
|
||||
jm LSHIFT 1 -> kg
|
||||
NOT dq -> dr
|
||||
bo OR bu -> bv
|
||||
gk OR gq -> gr
|
||||
he OR hp -> hq
|
||||
NOT h -> i
|
||||
hf AND hl -> hn
|
||||
gv AND gx -> gy
|
||||
x AND ai -> ak
|
||||
bo AND bu -> bw
|
||||
hq AND hs -> ht
|
||||
hz RSHIFT 1 -> is
|
||||
gj RSHIFT 5 -> gm
|
||||
g AND i -> j
|
||||
gk AND gq -> gs
|
||||
dp AND dr -> ds
|
||||
b RSHIFT 3 -> e
|
||||
gl AND gm -> go
|
||||
gl OR gm -> gn
|
||||
y AND ae -> ag
|
||||
hv OR hu -> hw
|
||||
1674 -> b
|
||||
ab AND ad -> ae
|
||||
NOT ac -> ad
|
||||
1 AND ht -> hu
|
||||
NOT hn -> ho
|
16
TypeScript/day7/package.json
Normal file
16
TypeScript/day7/package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"scripts": {
|
||||
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=180",
|
||||
"a": "ts-node solution_a.ts",
|
||||
"b": "ts-node solution_b.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^14.14.8",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5"
|
||||
},
|
||||
"license": "WTFPL"
|
||||
}
|
64
TypeScript/day7/solution_a.ts
Normal file
64
TypeScript/day7/solution_a.ts
Normal file
|
@ -0,0 +1,64 @@
|
|||
import fs from "fs";
|
||||
const input = fs.readFileSync("input").toString().split("\n");
|
||||
const COMMAND_REGEX = /[A-Z]+/g;
|
||||
const ARGUMENTS_REGEX = /[a-z0-9]+/g;
|
||||
|
||||
// Dictionary of our bitwise methods
|
||||
const BITWISE_METHODS = {
|
||||
AND: (a: number, b: number) => a & b,
|
||||
OR: (a: number, b: number) => a | b,
|
||||
NOT: (a: number, b?: number) => ~a,
|
||||
LSHIFT: (a: number, b: number) => a << b,
|
||||
RSHIFT: (a: number, b: number) => a >> b,
|
||||
};
|
||||
|
||||
// Parse instruction from input and return object with command, arguments and destination wire
|
||||
function parseInstruction(instruction: string): Instruction & { destination: string } {
|
||||
const raw_command = instruction.match(COMMAND_REGEX);
|
||||
const args = instruction.match(ARGUMENTS_REGEX) ?? [];
|
||||
const destination = args.pop()!;
|
||||
const command = raw_command === null ? raw_command : (raw_command[0] as keyof typeof BITWISE_METHODS);
|
||||
|
||||
return {
|
||||
command,
|
||||
args: args.map((arg) => (isNaN(Number(arg)) ? arg : Number(arg))) as [Wire | number, Wire | number | undefined],
|
||||
destination,
|
||||
};
|
||||
}
|
||||
|
||||
type Wire = string;
|
||||
type Instruction = {
|
||||
command: keyof typeof BITWISE_METHODS | null;
|
||||
args: [Wire | number, Wire | number | undefined];
|
||||
};
|
||||
|
||||
// Calculate value for one of the wires (recursively)
|
||||
function calculateWire(wireName: Wire, wires: Map<Wire, any>) {
|
||||
const wire = wires.get(wireName);
|
||||
|
||||
if (typeof wireName === "number") return wireName;
|
||||
if (typeof wire === "number") return wire;
|
||||
if (typeof wire === "undefined") return undefined;
|
||||
|
||||
if (!wire.command) {
|
||||
wires.set(wireName, calculateWire(wire.args[0], wires));
|
||||
} else if (Object.keys(BITWISE_METHODS).includes(wire.command)) {
|
||||
wires.set(wireName, BITWISE_METHODS[wire.command as keyof typeof BITWISE_METHODS](calculateWire(wire.args[0], wires), calculateWire(wire.args[1], wires)));
|
||||
}
|
||||
|
||||
return wires.get(wireName);
|
||||
}
|
||||
async function main() {
|
||||
// Our parsed wires in format {wire: value} or {wire: instruction}
|
||||
const wires = new Map<Wire, Instruction>();
|
||||
|
||||
// Fill WIRES with parsed instructions and their future values
|
||||
input.forEach((instruction) => {
|
||||
const parsedInstruction = parseInstruction(instruction.trim());
|
||||
wires.set(parsedInstruction.destination, { command: parsedInstruction.command, args: parsedInstruction.args });
|
||||
});
|
||||
|
||||
return calculateWire("a", wires);
|
||||
}
|
||||
|
||||
main().then(console.log).catch(console.error);
|
66
TypeScript/day7/solution_b.ts
Normal file
66
TypeScript/day7/solution_b.ts
Normal file
|
@ -0,0 +1,66 @@
|
|||
import fs from "fs";
|
||||
const input = fs.readFileSync("input").toString().split("\n");
|
||||
const COMMAND_REGEX = /[A-Z]+/g;
|
||||
const ARGUMENTS_REGEX = /[a-z0-9]+/g;
|
||||
|
||||
// Dictionary of our bitwise methods
|
||||
const BITWISE_METHODS = {
|
||||
AND: (a: number, b: number) => a & b,
|
||||
OR: (a: number, b: number) => a | b,
|
||||
NOT: (a: number, b?: number) => ~a,
|
||||
LSHIFT: (a: number, b: number) => a << b,
|
||||
RSHIFT: (a: number, b: number) => a >> b,
|
||||
};
|
||||
|
||||
// Parse instruction from input and return object with command, arguments and destination wire
|
||||
function parseInstruction(instruction: string): Instruction & { destination: string } {
|
||||
const raw_command = instruction.match(COMMAND_REGEX);
|
||||
const args = instruction.match(ARGUMENTS_REGEX) ?? [];
|
||||
const destination = args.pop()!;
|
||||
const command = raw_command === null ? raw_command : (raw_command[0] as keyof typeof BITWISE_METHODS);
|
||||
|
||||
return {
|
||||
command,
|
||||
args: args.map((arg) => (isNaN(Number(arg)) ? arg : Number(arg))) as [Wire | number, Wire | number | undefined],
|
||||
destination,
|
||||
};
|
||||
}
|
||||
|
||||
type Wire = string;
|
||||
type Instruction = {
|
||||
command: keyof typeof BITWISE_METHODS | null;
|
||||
args: [Wire | number, Wire | number | undefined];
|
||||
};
|
||||
|
||||
// Calculate value for one of the wires (recursively)
|
||||
function calculateWire(wireName: Wire, wires: Map<Wire, any>) {
|
||||
const wire = wires.get(wireName);
|
||||
|
||||
if (typeof wireName === "number") return wireName;
|
||||
if (typeof wire === "number") return wire;
|
||||
if (typeof wire === "undefined") return undefined;
|
||||
|
||||
if (!wire.command) {
|
||||
wires.set(wireName, calculateWire(wire.args[0], wires));
|
||||
} else if (Object.keys(BITWISE_METHODS).includes(wire.command)) {
|
||||
wires.set(wireName, BITWISE_METHODS[wire.command as keyof typeof BITWISE_METHODS](calculateWire(wire.args[0], wires), calculateWire(wire.args[1], wires)));
|
||||
}
|
||||
|
||||
return wires.get(wireName);
|
||||
}
|
||||
async function main() {
|
||||
// Our parsed wires in format {wire: value} or {wire: instruction}
|
||||
const wires = new Map<Wire, Instruction>();
|
||||
|
||||
// Fill WIRES with parsed instructions and their future values
|
||||
input.forEach((instruction) => {
|
||||
const parsedInstruction = parseInstruction(instruction.trim());
|
||||
wires.set(parsedInstruction.destination, { command: parsedInstruction.command, args: parsedInstruction.args });
|
||||
});
|
||||
const parsedInstruction = parseInstruction("46065 -> b");
|
||||
wires.set(parsedInstruction.destination, { command: parsedInstruction.command, args: parsedInstruction.args });
|
||||
|
||||
return calculateWire("a", wires);
|
||||
}
|
||||
|
||||
main().then(console.log).catch(console.error);
|
69
TypeScript/day7/tsconfig.json
Normal file
69
TypeScript/day7/tsconfig.json
Normal file
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": false, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
"noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
}
|
67
TypeScript/day7/yarn.lock
Normal file
67
TypeScript/day7/yarn.lock
Normal file
|
@ -0,0 +1,67 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node@^14.14.8":
|
||||
version "14.14.8"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
|
||||
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
|
||||
|
||||
arg@^4.1.0:
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
||||
|
||||
buffer-from@^1.0.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
|
||||
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
|
||||
|
||||
diff@^4.0.1:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
|
||||
|
||||
make-error@^1.1.1:
|
||||
version "1.3.6"
|
||||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
|
||||
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
|
||||
|
||||
prettier@^2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
|
||||
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
|
||||
|
||||
source-map-support@^0.5.17:
|
||||
version "0.5.19"
|
||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
|
||||
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
|
||||
dependencies:
|
||||
buffer-from "^1.0.0"
|
||||
source-map "^0.6.0"
|
||||
|
||||
source-map@^0.6.0:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
||||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
||||
|
||||
ts-node@^9.0.0:
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
|
||||
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
|
||||
dependencies:
|
||||
arg "^4.1.0"
|
||||
diff "^4.0.1"
|
||||
make-error "^1.1.1"
|
||||
source-map-support "^0.5.17"
|
||||
yn "3.1.1"
|
||||
|
||||
typescript@^4.0.5:
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
|
||||
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
|
||||
|
||||
yn@3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
|
||||
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
|
5
TypeScript/day8/.yarnrc
Normal file
5
TypeScript/day8/.yarnrc
Normal file
|
@ -0,0 +1,5 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
yarn-path ".yarn/releases/yarn-1.22.10.cjs"
|
300
TypeScript/day8/input
Normal file
300
TypeScript/day8/input
Normal file
|
@ -0,0 +1,300 @@
|
|||
"azlgxdbljwygyttzkfwuxv"
|
||||
"v\xfb\"lgs\"kvjfywmut\x9cr"
|
||||
"merxdhj"
|
||||
"dwz"
|
||||
"d\\gkbqo\\fwukyxab\"u"
|
||||
"k\xd4cfixejvkicryipucwurq\x7eq"
|
||||
"nvtidemacj\"hppfopvpr"
|
||||
"kbngyfvvsdismznhar\\p\"\"gpryt\"jaeh"
|
||||
"khre\"o\x0elqfrbktzn"
|
||||
"nugkdmqwdq\x50amallrskmrxoyo"
|
||||
"jcrkptrsasjp\\\"cwigzynjgspxxv\\vyb"
|
||||
"ramf\"skhcmenhbpujbqwkltmplxygfcy"
|
||||
"aqjqgbfqaxga\\fkdcahlfi\"pvods"
|
||||
"pcrtfb"
|
||||
"\x83qg\"nwgugfmfpzlrvty\"ryoxm"
|
||||
"fvhvvokdnl\\eap"
|
||||
"kugdkrat"
|
||||
"seuxwc"
|
||||
"vhioftcosshaqtnz"
|
||||
"gzkxqrdq\\uko\"mrtst"
|
||||
"znjcomvy\x16hhsenmroswr"
|
||||
"clowmtra"
|
||||
"\xc4"
|
||||
"jpavsevmziklydtqqm"
|
||||
"egxjqytcttr\\ecfedmmovkyn\"m"
|
||||
"mjulrvqgmsvmwf"
|
||||
"o\\prxtlfbatxerhev\xf9hcl\x44rzmvklviv"
|
||||
"lregjexqaqgwloydxdsc\\o\"dnjfmjcu"
|
||||
"lnxluajtk\x8desue\\k\x7abhwokfhh"
|
||||
"wrssfvzzn\"llrysjgiu\"npjtdli"
|
||||
"\x67lwkks"
|
||||
"bifw\"ybvmwiyi\"vhol\"vol\xd4"
|
||||
"aywdqhvtvcpvbewtwuyxrix"
|
||||
"gc\xd3\"caukdgfdywj"
|
||||
"uczy\\fk"
|
||||
"bnlxkjvl\x7docehufkj\\\"qoyhag"
|
||||
"bidsptalmoicyorbv\\"
|
||||
"jorscv\"mufcvvfmcv\"ga"
|
||||
"sofpwfal\\a"
|
||||
"kcuqtbboaly\"uj\"k"
|
||||
"n\\c"
|
||||
"x\"\xcaj\\xwwvpdldz"
|
||||
"eyukphh"
|
||||
"wcyjq"
|
||||
"vjx\"\"hjroj\"l\x4cjwbr"
|
||||
"xcodsxzfqw\\rowqtuwvjnxupjnrh"
|
||||
"yc"
|
||||
"fpvzldgbdtca\"hqwa"
|
||||
"ymjq\x8ahohvafubra\"hgqoknkuyph"
|
||||
"kx\\mkaaklvcup"
|
||||
"belddrzegcsxsyfhzyz"
|
||||
"fuyswi"
|
||||
"\\hubzebo\"ha\\qyr\"dv\\"
|
||||
"mxvlz\"fwuvx\"cyk\""
|
||||
"ftbh\"ro\\tmcpnpvh\"xx"
|
||||
"ygi"
|
||||
"rw\"\"wwn\\fgbjumq\"vgvoh\xd0\"mm"
|
||||
"\"pat\"\x63kpfc\"\x2ckhfvxk\"uwqzlx"
|
||||
"o"
|
||||
"d\"hqtsfp\xceaswe\"\xc0lw"
|
||||
"zajpvfawqntvoveal\"\"trcdarjua"
|
||||
"xzapq"
|
||||
"rkmhm"
|
||||
"byuq"
|
||||
"rwwmt\xe8jg\xc2\"omt"
|
||||
"nfljgdmgefvlh\"x"
|
||||
"rpjxcexisualz"
|
||||
"doxcycmgaiptvd"
|
||||
"rq\\\"mohnjdf\\xv\\hrnosdtmvxot"
|
||||
"oqvbcenib\"uhy\\npjxg"
|
||||
"pkvgnm\\ruayuvpbpd"
|
||||
"kknmzpxqfbcdgng"
|
||||
"piduhbmaympxdexz"
|
||||
"vapczawekhoa\\or"
|
||||
"tlwn\"avc\"bycg\"\"xuxea"
|
||||
"\xcdvryveteqzxrgopmdmihkcgsuozips"
|
||||
"kpzziqt"
|
||||
"sdy\\s\"cjq"
|
||||
"yujs"
|
||||
"qte\"q"
|
||||
"qyvpnkhjcqjv\"cclvv\"pclgtg\xeak\"tno"
|
||||
"xwx"
|
||||
"vibuvv"
|
||||
"qq\""
|
||||
"wwjduomtbkbdtorhpyalxswisq\"r"
|
||||
"afuw\\mfjzctcivwesutxbk\"lk"
|
||||
"e\xcef\\hkiu"
|
||||
"ftdrgzvygcw\"jwsrcmgxj"
|
||||
"zrddqfkx\x21dr\"ju\"elybk\"powj\"\"kpryz"
|
||||
"dttdkfvbodkma\""
|
||||
"lzygktugpqw"
|
||||
"qu\x83tes\\u\"tnid\"ryuz"
|
||||
"\\o\"pe\\vqwlsizjklwrjofg\xe2oau\\rd"
|
||||
"mikevjzhnwgx\"fozrj\"h\""
|
||||
"ligxmxznzvtachvvbahnff"
|
||||
"d\\kq"
|
||||
"tnbkxpzmcakqhaa"
|
||||
"g\\yeakebeyv"
|
||||
"cqkcnd\"sxjxfnawy\x31zax\x6ceha"
|
||||
"m\x0dtqotffzdnetujtsgjqgwddc"
|
||||
"masnugb\"etgmxul\x3bqd\\tmtddnvcy"
|
||||
"floediikodfgre\x23wyoxlswxflwecdjpt"
|
||||
"zu"
|
||||
"r"
|
||||
"\"ashzdbd\"pdvba\xeeumkr\\amnj"
|
||||
"ckslmuwbtfouwpfwtuiqmeozgspwnhx"
|
||||
"t\\qjsjek\xf9gjcxsyco\"r"
|
||||
"hoed\x1b\\tcmaqch\"epdy"
|
||||
"mgjiojwzc\\ypqcn\xb1njmp\"aeeblxt"
|
||||
"\xdf\"h\x5enfracj"
|
||||
"\x6fpbpocrb"
|
||||
"jbmhrswyyq\\"
|
||||
"wtyqtenfwatji\"ls\\"
|
||||
"voy"
|
||||
"awj"
|
||||
"rtbj\"j"
|
||||
"hynl"
|
||||
"orqqeuaat\\xu\\havsgr\xc5qdk"
|
||||
"g\"npyzjfq\"rjefwsk"
|
||||
"rk\\kkcirjbixr\\zelndx\"bsnqvqj\""
|
||||
"tecoz"
|
||||
"dn\"uswngbdk\""
|
||||
"qb\\"
|
||||
"wpyis\\ebq"
|
||||
"ppwue\\airoxzjjdqbvyurhaabetv"
|
||||
"fxlvt"
|
||||
"ql\"oqsmsvpxcg\"k"
|
||||
"vqlhuec\\adw"
|
||||
"qzmi\xffberakqqkk"
|
||||
"tisjqff\"wf"
|
||||
"yhnpudoaybwucvppj"
|
||||
"xhfuf\\ehsrhsnfxcwtibd\"ubfpz"
|
||||
"ihgjquzhf\""
|
||||
"ff\x66dsupesrnusrtqnywoqcn\\"
|
||||
"z\x77zpubbjmd"
|
||||
"\"vhzlbwq\"xeimjt\\xe\x85umho\"m\"\"bmy"
|
||||
"mmuvkioocmzjjysi\"mkfbec\""
|
||||
"rpgghowbduw\x2fayslubajinoik\xd0hcfy"
|
||||
"xrkyjqul\xdexlojgdphczp\"jfk"
|
||||
"mg\x07cnr\x8b\x67xdgszmgiktpjhawho"
|
||||
"kdgufhaoab"
|
||||
"rlhela\"nldr"
|
||||
"wzye\x87u"
|
||||
"yif\x75bjhnitgoarmfgqwpmopu"
|
||||
"pvlbyez\"wyy\x3dpgr"
|
||||
"ezdm\"ovkruthkvdwtqwr\"ibdoawzgu"
|
||||
"qubp"
|
||||
"b\\kcpegcn\\zgdemgorjnk"
|
||||
"gjsva\\kzaor\"\"gtpd"
|
||||
"\"kt"
|
||||
"rlymwlcodix"
|
||||
"qqtmswowxca\"jvv"
|
||||
"jni\xebwhozb"
|
||||
"zhino\"kzjtmgxpi\"zzexijg"
|
||||
"tyrbat\\mejgzplufxixkyg"
|
||||
"lhmopxiao\x09\"p\xebl"
|
||||
"xefioorxvate"
|
||||
"nmcgd\x46xfujt\"w"
|
||||
"\xe3wnwpat\"gtimrb"
|
||||
"wpq\"xkjuw\xebbohgcagppb"
|
||||
"fmvpwaca"
|
||||
"mlsw"
|
||||
"fdan\\\x9e"
|
||||
"\"f\"fmdlzc"
|
||||
"nyuj\\jnnfzdnrqmhvjrahlvzl"
|
||||
"zn\"f\xcfsshcdaukkimfwk"
|
||||
"uayugezzo\\\"e\"blnrgjaupqhik"
|
||||
"efd\"apkndelkuvfvwyyatyttkehc"
|
||||
"ufxq\\\"m\"bwkh\x93kapbqrvxxzbzp\\"
|
||||
"fgypsbgjak\x79qblbeidavqtddfacq\\i\"h"
|
||||
"kcfgpiysdxlgejjvgndb\\dovfpqodw"
|
||||
"\"onpqnssmighipuqgwx\"nrokzgvg"
|
||||
"vhjrrhfrba\"jebdanzsrdusut\\wbs"
|
||||
"o\xdakymbaxakys"
|
||||
"uwxhhzz\\mtmhghjn\\\\tnhzbejj"
|
||||
"yd\\"
|
||||
"bpgztp\\lzwpdqju\"it\x35qjhihjv"
|
||||
"\\my\\b\"klnnto\\\xb3mbtsh"
|
||||
"ezyvknv\"l\x2bdhhfjcvwzhjgmhwbqd\"\\"
|
||||
"ftkz\"amoncbsohtaumhl\"wsodemopodq"
|
||||
"ifv"
|
||||
"dmzfxvzq"
|
||||
"sped\"bvmf\"mmevl\"zydannpfny"
|
||||
"fjxcjwlv\"pnqyrzatsjwsqfidb"
|
||||
"muc\xfdqouwwnmuixru\\zlhjintplvtee"
|
||||
"mraqgvmj"
|
||||
"njopq\"ftcsryo"
|
||||
"enoh\"n"
|
||||
"t\"ntjhjc\"nzqh\xf7dcohhlsja\x7dtr"
|
||||
"flbqcmcoun"
|
||||
"dxkiysrn\\dyuqoaig"
|
||||
"nehkzi\"h\"syktzfufotng\xdafqo"
|
||||
"dzkjg\\hqjk\\\"zfegssjhn"
|
||||
"sadlsjv"
|
||||
"vmfnrdb\""
|
||||
"ac\\bdp\"n"
|
||||
"qt\x89h"
|
||||
"lsndeugwvijwde\\vjapbm\\k\\nljuva"
|
||||
"twpmltdzyynqt\\z\\tnund\x64hm"
|
||||
"hpcyata\"ocylbkzdnhujh"
|
||||
"hskzq\"knntuhscex\"q\\y\\vqj\x3an"
|
||||
"eekwyufvji\\mqgeroekxeyrmymq"
|
||||
"hl\"durthetvri\xebw\\jxu\"rcmiuy"
|
||||
"\"fxdnmvnftxwesmvvq\"sjnf\xaabpg\"iary"
|
||||
"\"\"nksqso"
|
||||
"ruq\xbezugge\"d\"hwvoxmy\"iawikddxn\"x"
|
||||
"rxxnlfay"
|
||||
"stcu\"mv\xabcqts\\fasff"
|
||||
"yrnvwfkfuzuoysfdzl\x02bk"
|
||||
"qbdsmlwdbfknivtwijbwtatqfe"
|
||||
"\"erqh\\csjph"
|
||||
"ikfv"
|
||||
"\xd2cuhowmtsxepzsivsvnvsb"
|
||||
"vj"
|
||||
"d"
|
||||
"\\g"
|
||||
"porvg\x62qghorthnc\"\\"
|
||||
"tiks\\kr\"\x0fuejvuxzswnwdjscrk"
|
||||
"xmgfel\"atma\\zaxmlgfjx\"ajmqf"
|
||||
"oz\\rnxwljc\\\"umhymtwh"
|
||||
"wlsxxhm\x7fqx\\gjoyrvccfiner\\qloluqv"
|
||||
"k\\ieq"
|
||||
"xidjj\"ksnlgnwxlddf\\s\\kuuleb"
|
||||
"wjpnzgprzv\\maub\x0cj"
|
||||
"r"
|
||||
"y"
|
||||
"\"yecqiei\"ire\\jdhlnnlde\xc5u"
|
||||
"drvdiycqib"
|
||||
"egnrbefezcrhgldrtb"
|
||||
"plqodxv\\zm\"uodwjdocri\x55ucaezutm"
|
||||
"f\"wexcw\x02ekewx\"alyzn"
|
||||
"pqajwuk\\\\oatkfqdyspnrupo"
|
||||
"rkczj\"fzntabpnygrhamk\\km\x68xfkmr"
|
||||
"wejam\xbac\x37kns"
|
||||
"qqmlwjk\"gh"
|
||||
"fdcjsxlgx"
|
||||
"\\cxvxy\"kb\"\"unubvrsq\\y\\awfhbmarj\\"
|
||||
"geunceaqr"
|
||||
"tpkg\"svvngk\\sizlsyaqwf"
|
||||
"\"pa\\x\x18od\\emgje\\"
|
||||
"ffiizogjjptubzqfuh\"cctieqcdh"
|
||||
"yikhiyyrpgglpos"
|
||||
"h\\"
|
||||
"jotqojodcv"
|
||||
"ervsz\x87ade\"fevq\\tcqowt"
|
||||
"\\y\"fgrxtppkcseeg\\onxjarx\\hyhfn\x5fi"
|
||||
"kxndlabn\\wwumctuzdcfiitrbnn"
|
||||
"eoosynwhwm"
|
||||
"\"c\x04"
|
||||
"ny\xf6vuwlec"
|
||||
"ubgxxcvnltzaucrzg\\xcez"
|
||||
"pnocjvo\\yt"
|
||||
"fcabrtqog\"a\"zj"
|
||||
"o\\bha\\mzxmrfltnflv\xea"
|
||||
"tbfvzwhexsdxjmxejwqqngzixcx"
|
||||
"wdptrakok\"rgymturdmwfiwu"
|
||||
"reffmj"
|
||||
"lqm"
|
||||
"\\oc"
|
||||
"p\""
|
||||
"ygkdnhcuehlx"
|
||||
"vsqmv\"bqay\"olimtkewedzm"
|
||||
"isos\x6azbnkojhxoopzetbj\xe1yd"
|
||||
"yo\\pgayjcyhshztnbdv"
|
||||
"fg\"h"
|
||||
"vcmcojolfcf\\\\oxveua"
|
||||
"w\"vyszhbrr\"jpeddpnrjlca\x69bdbopd\\z"
|
||||
"jikeqv"
|
||||
"\"dkjdfrtj"
|
||||
"is"
|
||||
"hgzx"
|
||||
"z\""
|
||||
"woubquq\\ag\""
|
||||
"xvclriqa\xe6ltt"
|
||||
"tfxinifmd"
|
||||
"mvywzf\"jz"
|
||||
"vlle"
|
||||
"c\"rf\"wynhye\x25vccvb\""
|
||||
"zvuxm"
|
||||
"\xf2\"jdstiwqer\"h"
|
||||
"kyogyogcknbzv\x9f\\\\e"
|
||||
"kspodj\"edpeqgypc"
|
||||
"oh\\x\\h"
|
||||
"julb"
|
||||
"bmcfkidxyilgoy\\xmu\"ig\\qg"
|
||||
"veqww\"ea"
|
||||
"fkdbemtgtkpqisrwlxutllxc\"mbelhs"
|
||||
"e"
|
||||
"ecn\x50ooprbstnq"
|
||||
"\"\xe8\"ec\xeah\"qo\\g\"iuqxy\"e\"y\xe7xk\xc6d"
|
||||
"lwj\"aftrcqj"
|
||||
"jduij\x97zk\"rftjrixzgscxxllpqx\"bwwb"
|
||||
"fqcditz"
|
||||
"f\x19azclj\"rsvaokgvty\"aeq"
|
||||
"erse\x9etmzhlmhy\x67yftoti"
|
||||
"lsdw\xb3dmiy\\od"
|
||||
"x\x6fxbljsjdgd\xaau"
|
||||
"hjg\\w\"\x78uoqbsdikbjxpip\"w\"jnhzec"
|
||||
"gk"
|
||||
"\\zrs\\syur"
|
16
TypeScript/day8/package.json
Normal file
16
TypeScript/day8/package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"scripts": {
|
||||
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=120",
|
||||
"a": "ts-node solution_a.ts",
|
||||
"b": "ts-node solution_b.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^14.14.8",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5"
|
||||
},
|
||||
"license": "WTFPL"
|
||||
}
|
9
TypeScript/day8/solution_a.ts
Normal file
9
TypeScript/day8/solution_a.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import * as fs from "fs";
|
||||
const input = fs.readFileSync("input").toString();
|
||||
|
||||
async function main() {
|
||||
const lines = input.split("\n").map((line) => line.trim());
|
||||
return lines.reduce((prev, line) => prev + (line.length - eval(line).length), 0);
|
||||
}
|
||||
|
||||
main().then(console.log).catch(console.error);
|
15
TypeScript/day8/solution_b.ts
Normal file
15
TypeScript/day8/solution_b.ts
Normal file
|
@ -0,0 +1,15 @@
|
|||
import * as fs from "fs";
|
||||
const input = fs.readFileSync("input").toString();
|
||||
|
||||
async function main() {
|
||||
const lines = input.split("\n").map((line) => line.trim());
|
||||
let result = 0;
|
||||
for (const line of lines) {
|
||||
const replaced = '"' + line.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
|
||||
result += replaced.length - line.length;
|
||||
console.log(line, replaced);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
main().then(console.log).catch(console.error);
|
69
TypeScript/day8/tsconfig.json
Normal file
69
TypeScript/day8/tsconfig.json
Normal file
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": false, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
"noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
}
|
67
TypeScript/day8/yarn.lock
Normal file
67
TypeScript/day8/yarn.lock
Normal file
|
@ -0,0 +1,67 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node@^14.14.8":
|
||||
version "14.14.8"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
|
||||
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
|
||||
|
||||
arg@^4.1.0:
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
||||
|
||||
buffer-from@^1.0.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
|
||||
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
|
||||
|
||||
diff@^4.0.1:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
|
||||
|
||||
make-error@^1.1.1:
|
||||
version "1.3.6"
|
||||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
|
||||
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
|
||||
|
||||
prettier@^2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
|
||||
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
|
||||
|
||||
source-map-support@^0.5.17:
|
||||
version "0.5.19"
|
||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
|
||||
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
|
||||
dependencies:
|
||||
buffer-from "^1.0.0"
|
||||
source-map "^0.6.0"
|
||||
|
||||
source-map@^0.6.0:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
||||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
||||
|
||||
ts-node@^9.0.0:
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
|
||||
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
|
||||
dependencies:
|
||||
arg "^4.1.0"
|
||||
diff "^4.0.1"
|
||||
make-error "^1.1.1"
|
||||
source-map-support "^0.5.17"
|
||||
yn "3.1.1"
|
||||
|
||||
typescript@^4.0.5:
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
|
||||
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
|
||||
|
||||
yn@3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
|
||||
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
|
147392
TypeScript/template/.yarn/releases/yarn-1.22.10.cjs
vendored
Normal file
147392
TypeScript/template/.yarn/releases/yarn-1.22.10.cjs
vendored
Normal file
File diff suppressed because one or more lines are too long
5
TypeScript/template/.yarnrc
Normal file
5
TypeScript/template/.yarnrc
Normal file
|
@ -0,0 +1,5 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
yarn-path ".yarn/releases/yarn-1.22.10.cjs"
|
16
TypeScript/template/package.json
Normal file
16
TypeScript/template/package.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"scripts": {
|
||||
"lint": "prettier solution_a.ts solution_b.ts --write --print-width=120",
|
||||
"a": "ts-node solution_a.ts",
|
||||
"b": "ts-node solution_b.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"prettier": "^2.1.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/node": "^14.14.8",
|
||||
"ts-node": "^9.0.0",
|
||||
"typescript": "^4.0.5"
|
||||
},
|
||||
"license": "WTFPL"
|
||||
}
|
6
TypeScript/template/solution_a.ts
Normal file
6
TypeScript/template/solution_a.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import * as fs from "fs";
|
||||
const input = fs.readFileSync("input").toString();
|
||||
|
||||
async function main() {}
|
||||
|
||||
main().then(console.log).catch(console.error);
|
6
TypeScript/template/solution_b.ts
Normal file
6
TypeScript/template/solution_b.ts
Normal file
|
@ -0,0 +1,6 @@
|
|||
import * as fs from "fs";
|
||||
const input = fs.readFileSync("input").toString();
|
||||
|
||||
async function main() {}
|
||||
|
||||
main().then(console.log).catch(console.error);
|
69
TypeScript/template/tsconfig.json
Normal file
69
TypeScript/template/tsconfig.json
Normal file
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig.json to read more about this file */
|
||||
|
||||
/* Basic Options */
|
||||
// "incremental": true, /* Enable incremental compilation */
|
||||
"target": "ES2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
|
||||
"module": "CommonJS", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
|
||||
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||
// "checkJs": true, /* Report errors in .js files. */
|
||||
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||
"sourceMap": false, /* Generates corresponding '.map' file. */
|
||||
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||
// "outDir": "./", /* Redirect output structure to the directory. */
|
||||
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
// "composite": true, /* Enable project compilation */
|
||||
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||
// "removeComments": true, /* Do not emit comments to output. */
|
||||
"noEmit": true, /* Do not emit outputs. */
|
||||
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||
|
||||
/* Additional Checks */
|
||||
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||
|
||||
/* Module Resolution Options */
|
||||
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||
// "types": [], /* Type declaration files to be included in compilation. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
|
||||
/* Source Map Options */
|
||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||
|
||||
/* Advanced Options */
|
||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||
}
|
||||
}
|
67
TypeScript/template/yarn.lock
Normal file
67
TypeScript/template/yarn.lock
Normal file
|
@ -0,0 +1,67 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node@^14.14.8":
|
||||
version "14.14.8"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.8.tgz#2127bd81949a95c8b7d3240f3254352d72563aec"
|
||||
integrity sha512-z/5Yd59dCKI5kbxauAJgw6dLPzW+TNOItNE00PkpzNwUIEwdj/Lsqwq94H5DdYBX7C13aRA0CY32BK76+neEUA==
|
||||
|
||||
arg@^4.1.0:
|
||||
version "4.1.3"
|
||||
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
|
||||
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
|
||||
|
||||
buffer-from@^1.0.0:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
|
||||
integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
|
||||
|
||||
diff@^4.0.1:
|
||||
version "4.0.2"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
|
||||
integrity sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==
|
||||
|
||||
make-error@^1.1.1:
|
||||
version "1.3.6"
|
||||
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
|
||||
integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==
|
||||
|
||||
prettier@^2.1.2:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
|
||||
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
|
||||
|
||||
source-map-support@^0.5.17:
|
||||
version "0.5.19"
|
||||
resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
|
||||
integrity sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==
|
||||
dependencies:
|
||||
buffer-from "^1.0.0"
|
||||
source-map "^0.6.0"
|
||||
|
||||
source-map@^0.6.0:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
|
||||
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
|
||||
|
||||
ts-node@^9.0.0:
|
||||
version "9.0.0"
|
||||
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-9.0.0.tgz#e7699d2a110cc8c0d3b831715e417688683460b3"
|
||||
integrity sha512-/TqB4SnererCDR/vb4S/QvSZvzQMJN8daAslg7MeaiHvD8rDZsSfXmNeNumyZZzMned72Xoq/isQljYSt8Ynfg==
|
||||
dependencies:
|
||||
arg "^4.1.0"
|
||||
diff "^4.0.1"
|
||||
make-error "^1.1.1"
|
||||
source-map-support "^0.5.17"
|
||||
yn "3.1.1"
|
||||
|
||||
typescript@^4.0.5:
|
||||
version "4.0.5"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
|
||||
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
|
||||
|
||||
yn@3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/yn/-/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
|
||||
integrity sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==
|
|
@ -1,11 +0,0 @@
|
|||
[build]
|
||||
rustc-wrapper = "/usr/bin/sccache"
|
||||
|
||||
[target.x86_64-unknown-linux-gnu]
|
||||
linker = "clang"
|
||||
rustflags = [
|
||||
"-C",
|
||||
"link-arg=-fuse-ld=/usr/bin/mold",
|
||||
"-C",
|
||||
"target-cpu=native",
|
||||
] # , "-Z", "threads=16"
|
1
rust/.gitignore
vendored
1
rust/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
/target
|
|
@ -1,2 +0,0 @@
|
|||
[editor.file-picker]
|
||||
git-ignore = true
|
7
rust/Cargo.lock
generated
7
rust/Cargo.lock
generated
|
@ -1,7 +0,0 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "advent-of-code"
|
||||
version = "23.5.1"
|
|
@ -1,46 +0,0 @@
|
|||
[package]
|
||||
name = "advent-of-code"
|
||||
version = "23.5.1"
|
||||
edition = "2021"
|
||||
default-run = "day05"
|
||||
|
||||
[profile.release]
|
||||
strip = "symbols"
|
||||
lto = true
|
||||
opt-level = 3
|
||||
codegen-units = 1
|
||||
|
||||
[profile.dev.package."*"]
|
||||
opt-level = 3
|
||||
codegen-units = 1
|
||||
[profile.release.package."*"]
|
||||
opt-level = 3
|
||||
codegen-units = 1
|
||||
[profile.release.build-override]
|
||||
codegen-units = 1
|
||||
|
||||
[[bin]]
|
||||
name = "template"
|
||||
# day00 for alphabetic sorting
|
||||
path = "src/day00/main.rs"
|
||||
test = false
|
||||
|
||||
[[bin]]
|
||||
name = "day01"
|
||||
path = "src/day01/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "day02"
|
||||
path = "src/day02/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "day03"
|
||||
path = "src/day03/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "day04"
|
||||
path = "src/day04/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "day05"
|
||||
path = "src/day05/main.rs"
|
|
@ -1,11 +0,0 @@
|
|||
const INPUT: &str = include_str!("input.txt");
|
||||
|
||||
mod part_1;
|
||||
use part_1::part_1;
|
||||
mod part_2;
|
||||
use part_2::part_2;
|
||||
|
||||
fn main() {
|
||||
println!("{}", part_1(INPUT));
|
||||
println!("{}", part_2(INPUT));
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
pub(crate) fn part_1(_input: &'static str) -> u64 {
|
||||
todo!("Part 1")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(
|
||||
super::part_1(SAMPLE_INPUT),
|
||||
todo!("Add result from example part 1")
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(
|
||||
super::part_1(crate::INPUT),
|
||||
todo!("Add result for solved part 1")
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
pub(crate) fn part_2(_input: &'static str) -> u64 {
|
||||
todo!("Part 2")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(
|
||||
super::part_2(SAMPLE_INPUT),
|
||||
todo!("Add result from example part 2")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(
|
||||
super::part_2(crate::INPUT),
|
||||
todo!("Add result for solved part 2")
|
||||
);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,11 +0,0 @@
|
|||
const INPUT: &str = include_str!("input.txt");
|
||||
|
||||
mod part_1;
|
||||
use part_1::part_1;
|
||||
mod part_2;
|
||||
use part_2::part_2;
|
||||
|
||||
fn main() {
|
||||
println!("{}", part_1(INPUT));
|
||||
println!("{}", part_2(INPUT));
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
pub(crate) fn part_1(input: &'static str) -> u32 {
|
||||
input
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let mut digits = line.chars().filter(char::is_ascii_digit);
|
||||
let first_digit = digits.next().expect("At least 1 digit should be present");
|
||||
let last_digit = digits.last().unwrap_or(first_digit);
|
||||
|
||||
(((first_digit as u32) - ('0' as u32)) * 10) + ((last_digit as u32) - ('0' as u32))
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input_part_1.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_1(SAMPLE_INPUT), 142)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_1(crate::INPUT), 55488);
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
use std::cmp::Reverse;
|
||||
|
||||
const DIGIT_PATTERNS: [(char, &str); 10] = [
|
||||
('0', "zero"),
|
||||
('1', "one"),
|
||||
('2', "two"),
|
||||
('3', "three"),
|
||||
('4', "four"),
|
||||
('5', "five"),
|
||||
('6', "six"),
|
||||
('7', "seven"),
|
||||
('8', "eight"),
|
||||
('9', "nine"),
|
||||
];
|
||||
|
||||
#[cfg_attr(test, derive(Debug))]
|
||||
struct DigitIndices {
|
||||
digit: u8,
|
||||
first_index: usize,
|
||||
last_index: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn part_2(input: &'static str) -> u32 {
|
||||
input
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let digit_indices = DIGIT_PATTERNS
|
||||
.iter()
|
||||
.filter_map(|(digit, pattern)| {
|
||||
let first_index_digit = line.find(*digit).map(Reverse);
|
||||
let first_index_str = line.find(pattern).map(Reverse);
|
||||
let Reverse(first_index) = Option::max(first_index_digit, first_index_str)?;
|
||||
|
||||
let last_index_digit = line.rfind(*digit);
|
||||
let last_index_str = line.rfind(pattern);
|
||||
let last_index = Option::max(last_index_digit, last_index_str)?;
|
||||
|
||||
Some(DigitIndices {
|
||||
digit: unsafe { digit.to_digit(10).unwrap_unchecked() } as u8,
|
||||
first_index,
|
||||
last_index,
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
// SAFETY: Each line is guaranteed to have at least one digit
|
||||
let first_digit = unsafe {
|
||||
digit_indices
|
||||
.iter()
|
||||
.min_by_key(|val| val.first_index)
|
||||
.unwrap_unchecked()
|
||||
}
|
||||
.digit;
|
||||
let last_digit = unsafe {
|
||||
digit_indices
|
||||
.iter()
|
||||
.max_by_key(|val| val.last_index)
|
||||
.unwrap_unchecked()
|
||||
}
|
||||
.digit;
|
||||
|
||||
(first_digit as u32 * 10) + last_digit as u32
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input_part_2.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_2(SAMPLE_INPUT), 281);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_2(crate::INPUT), 55614);
|
||||
}
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
1bc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
|
@ -1,7 +0,0 @@
|
|||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
|
@ -1,100 +0,0 @@
|
|||
Game 1: 13 red, 18 green; 5 green, 3 red, 5 blue; 5 green, 9 red, 6 blue; 3 blue, 3 green
|
||||
Game 2: 2 green, 3 blue, 5 red; 9 green, 4 red, 2 blue; 4 green, 3 blue; 2 blue, 3 red; 5 red, 3 blue, 9 green; 9 green, 5 red, 2 blue
|
||||
Game 3: 12 green, 3 red, 3 blue; 2 blue, 5 green, 2 red; 2 red, 3 blue, 11 green; 2 red, 8 green, 7 blue
|
||||
Game 4: 1 green, 2 blue; 7 green, 13 red; 2 blue, 5 green, 7 red; 6 green, 2 red
|
||||
Game 5: 6 blue, 4 green; 8 blue, 7 green; 1 red, 10 blue
|
||||
Game 6: 4 red, 4 blue, 2 green; 8 green, 1 blue, 8 red; 9 green, 1 red, 3 blue
|
||||
Game 7: 3 red, 12 green, 4 blue; 1 blue, 3 red, 6 green; 4 blue, 3 red, 15 green; 11 green, 2 blue, 2 red
|
||||
Game 8: 13 blue, 7 green, 8 red; 5 green, 8 blue, 2 red; 5 red, 6 blue, 7 green; 6 green, 6 red, 3 blue; 7 blue, 8 red, 6 green
|
||||
Game 9: 4 blue, 1 green, 4 red; 16 red, 1 green, 7 blue; 11 red, 3 green, 7 blue
|
||||
Game 10: 5 green, 1 red; 5 green, 3 blue; 1 red, 7 green, 3 blue; 1 blue, 6 green; 2 green, 4 blue
|
||||
Game 11: 10 green, 2 blue, 2 red; 14 green, 1 blue, 3 red; 13 green; 3 green, 2 red; 3 red, 1 blue, 2 green; 1 red, 10 green, 2 blue
|
||||
Game 12: 9 green, 2 blue; 11 green, 1 blue; 2 red, 1 blue; 1 blue, 2 red, 3 green; 1 blue, 2 red, 3 green
|
||||
Game 13: 11 blue, 3 red, 8 green; 9 red, 7 blue; 7 blue, 4 red
|
||||
Game 14: 17 blue, 2 red; 1 green, 13 blue, 1 red; 4 blue, 1 red, 4 green; 2 blue, 5 red, 13 green; 3 blue, 4 green, 6 red; 9 green, 14 blue, 6 red
|
||||
Game 15: 7 green, 2 blue, 3 red; 4 red, 18 green; 8 green, 1 blue; 3 red, 15 green, 2 blue; 1 red, 15 green; 9 green, 3 red, 1 blue
|
||||
Game 16: 10 red, 19 blue, 5 green; 12 red, 5 blue; 6 red, 3 green, 14 blue; 8 red, 10 blue, 6 green; 7 green, 10 red, 17 blue
|
||||
Game 17: 3 green, 3 red, 1 blue; 3 blue, 1 green, 2 red; 4 green, 3 red, 2 blue
|
||||
Game 18: 1 red, 2 blue; 1 green, 4 blue; 1 blue; 5 blue; 1 green, 3 red, 6 blue
|
||||
Game 19: 3 blue, 5 red, 8 green; 10 red, 6 blue, 11 green; 5 blue, 7 red, 8 green; 9 blue, 6 green, 5 red; 8 red, 12 green, 8 blue; 1 blue, 5 green, 10 red
|
||||
Game 20: 16 blue, 2 green; 10 green, 1 red, 4 blue; 13 green, 5 red, 9 blue
|
||||
Game 21: 1 blue, 1 green, 14 red; 2 blue; 5 green, 1 blue; 2 green, 11 red; 2 red, 4 green; 2 green, 16 red
|
||||
Game 22: 1 green, 10 red, 4 blue; 1 green, 4 blue, 8 red; 2 blue, 8 red; 4 green, 14 red; 1 blue, 5 red, 2 green
|
||||
Game 23: 17 green, 3 red, 16 blue; 9 green, 15 red; 3 red, 8 blue, 15 green
|
||||
Game 24: 1 green, 1 blue; 2 blue, 1 green, 2 red; 3 green, 1 blue, 1 red; 3 blue, 1 red; 2 green, 5 blue
|
||||
Game 25: 11 red, 2 green; 7 red, 6 green; 10 red, 1 blue, 8 green; 8 green, 4 red; 6 green, 10 red; 2 blue, 7 red
|
||||
Game 26: 2 green, 2 blue, 8 red; 1 blue, 1 red, 6 green; 9 red, 6 green, 2 blue
|
||||
Game 27: 5 red, 7 blue, 3 green; 3 blue, 1 red; 1 green, 1 red, 9 blue
|
||||
Game 28: 17 red, 5 green, 10 blue; 3 red, 14 blue, 1 green; 11 blue, 11 green
|
||||
Game 29: 16 red, 4 green, 4 blue; 3 green, 5 blue, 11 red; 7 blue, 8 red, 1 green; 1 green, 10 red, 4 blue; 2 green, 4 blue, 8 red
|
||||
Game 30: 3 green, 6 blue; 18 green, 3 blue; 14 green, 11 blue; 7 blue, 2 red, 17 green; 1 red, 12 green, 7 blue
|
||||
Game 31: 11 red, 2 green, 3 blue; 10 green, 11 blue, 15 red; 12 green, 17 blue, 5 red; 5 green, 2 red, 12 blue; 13 blue, 13 green, 4 red
|
||||
Game 32: 4 red, 2 blue, 5 green; 7 blue, 15 red; 11 blue, 4 green, 8 red
|
||||
Game 33: 18 blue, 3 green, 3 red; 3 green, 6 red; 2 blue, 4 red, 1 green; 3 green, 5 red, 3 blue
|
||||
Game 34: 5 red, 2 blue, 16 green; 9 red, 10 blue, 3 green; 8 red, 10 green, 13 blue
|
||||
Game 35: 7 blue, 5 red; 3 red, 1 blue; 4 blue, 7 red, 1 green; 4 red, 4 blue, 1 green; 3 blue, 7 red; 4 red, 1 green, 3 blue
|
||||
Game 36: 14 blue; 10 blue, 1 green; 10 blue, 4 green; 4 blue, 1 green, 1 red; 1 red, 6 blue, 4 green; 1 green, 1 red, 11 blue
|
||||
Game 37: 8 red, 13 green, 5 blue; 11 red, 16 green, 8 blue; 2 green, 10 blue, 11 red
|
||||
Game 38: 2 red, 1 blue, 10 green; 7 red, 6 blue, 14 green; 18 red, 1 blue, 5 green; 5 green, 5 blue, 13 red; 14 red, 5 green; 15 green, 13 red, 2 blue
|
||||
Game 39: 1 blue, 5 red; 9 red, 9 green; 4 blue, 10 green, 4 red; 3 green, 11 red, 1 blue; 2 green, 11 red, 4 blue
|
||||
Game 40: 9 blue, 4 green; 12 green, 1 red; 2 red, 15 green, 10 blue
|
||||
Game 41: 1 blue, 14 red, 12 green; 16 green, 2 blue, 3 red; 6 green, 9 red
|
||||
Game 42: 4 green, 13 red, 9 blue; 9 green, 9 red, 4 blue; 7 blue, 10 red, 9 green; 4 green, 18 blue, 14 red; 9 blue, 7 green, 2 red
|
||||
Game 43: 7 red, 6 blue; 4 green; 3 red, 6 green; 7 blue, 6 green, 8 red; 9 green, 7 blue, 7 red; 5 blue, 5 green, 6 red
|
||||
Game 44: 5 red, 8 blue; 2 red, 5 green; 6 green, 11 blue, 2 red; 1 green, 1 blue, 2 red
|
||||
Game 45: 3 blue, 7 green, 1 red; 5 red, 1 blue; 2 blue, 3 red; 8 green, 5 red
|
||||
Game 46: 4 red, 4 blue, 17 green; 1 blue, 5 green, 1 red; 1 red, 1 blue, 7 green; 18 green, 7 blue
|
||||
Game 47: 14 red, 3 green, 2 blue; 4 green, 4 red, 2 blue; 13 red, 1 blue
|
||||
Game 48: 5 red, 12 blue, 2 green; 3 blue, 1 red, 2 green; 10 blue, 7 red
|
||||
Game 49: 6 blue, 11 red; 11 red, 17 blue, 11 green; 16 blue, 12 green, 6 red
|
||||
Game 50: 12 blue, 3 green, 1 red; 3 green, 10 blue, 3 red; 11 blue, 3 red
|
||||
Game 51: 12 green, 1 blue, 8 red; 6 blue, 1 green, 9 red; 17 red, 5 blue; 7 blue, 9 green, 9 red; 13 green, 10 red, 2 blue
|
||||
Game 52: 5 blue, 1 green; 1 red, 1 green, 3 blue; 8 blue, 1 green; 1 green, 7 blue; 3 blue; 1 red, 6 blue
|
||||
Game 53: 11 green, 5 red; 16 green, 6 blue; 4 red, 19 green, 4 blue
|
||||
Game 54: 6 green, 4 blue, 8 red; 7 red, 6 green, 5 blue; 5 blue, 4 red; 5 blue, 14 red
|
||||
Game 55: 11 blue, 1 green; 2 red, 5 blue, 1 green; 10 blue, 1 green; 11 blue; 2 green, 2 red, 5 blue
|
||||
Game 56: 1 red, 9 blue, 1 green; 2 red, 8 blue; 1 green, 9 blue, 10 red; 5 blue, 1 green; 15 blue, 1 red; 12 blue, 4 red
|
||||
Game 57: 1 green, 17 blue; 10 blue, 2 green; 2 red, 16 blue; 6 green, 15 blue; 5 green; 2 red, 1 green
|
||||
Game 58: 2 blue, 4 green, 2 red; 5 blue; 5 red, 3 green, 2 blue; 5 red, 2 green, 5 blue; 7 green, 3 red, 4 blue; 4 red
|
||||
Game 59: 8 blue, 2 red, 2 green; 15 blue, 1 green, 4 red; 9 blue, 1 red; 3 green, 5 red, 5 blue
|
||||
Game 60: 3 red, 2 blue, 6 green; 1 red, 5 green; 2 blue, 10 green; 6 green, 2 red
|
||||
Game 61: 6 green, 4 blue; 1 red, 4 blue, 15 green; 1 blue, 16 green, 3 red; 6 red, 12 green, 2 blue; 3 red, 14 green, 1 blue; 3 red, 2 blue, 9 green
|
||||
Game 62: 1 green, 2 red; 4 red; 1 green, 4 red, 1 blue; 1 red, 1 blue, 1 green
|
||||
Game 63: 8 green, 4 red, 4 blue; 5 red, 4 blue, 8 green; 3 green, 1 blue
|
||||
Game 64: 5 blue, 2 green, 5 red; 3 green, 2 blue, 1 red; 6 blue, 2 red, 1 green; 2 green, 2 blue, 3 red; 3 blue, 1 red
|
||||
Game 65: 2 red, 7 green, 5 blue; 8 blue, 3 green, 4 red; 1 red, 6 green, 1 blue
|
||||
Game 66: 1 green, 6 red; 5 red, 1 green, 1 blue; 4 red, 1 blue, 1 green; 1 blue, 2 red, 1 green; 1 blue, 5 red; 1 blue, 8 red
|
||||
Game 67: 6 red, 8 blue, 8 green; 5 green, 2 red, 10 blue; 4 red, 1 green; 7 blue, 2 green
|
||||
Game 68: 7 green, 9 red, 15 blue; 4 green, 6 red, 3 blue; 1 blue, 5 green, 4 red; 9 green, 14 red, 6 blue; 8 blue, 15 red, 4 green; 7 green, 14 blue, 6 red
|
||||
Game 69: 4 green; 2 blue; 4 green, 8 blue, 11 red; 3 green, 9 red, 4 blue; 1 red, 2 blue; 2 green, 5 blue, 11 red
|
||||
Game 70: 6 blue, 16 green, 4 red; 6 green, 13 red, 2 blue; 7 green, 1 red, 2 blue; 8 green, 4 blue, 1 red; 10 red, 11 green
|
||||
Game 71: 6 blue, 7 red; 10 blue, 2 green, 4 red; 12 red, 10 blue, 1 green
|
||||
Game 72: 13 red, 13 blue; 6 red, 10 blue, 7 green; 3 blue, 5 green, 4 red; 8 green, 9 blue
|
||||
Game 73: 1 red, 1 green, 8 blue; 1 green, 8 blue; 2 green, 6 blue; 2 blue; 1 red, 12 blue; 12 blue, 3 green
|
||||
Game 74: 2 blue, 1 green, 1 red; 3 blue, 1 red, 1 green; 3 blue, 2 red; 3 blue, 1 red; 1 green
|
||||
Game 75: 10 red, 1 green, 4 blue; 12 red, 11 blue, 9 green; 18 green, 14 red, 5 blue
|
||||
Game 76: 4 blue, 3 green, 11 red; 4 blue, 1 green, 12 red; 11 blue, 2 green, 4 red; 2 blue, 2 green, 11 red; 12 red, 1 blue; 4 red, 2 green, 15 blue
|
||||
Game 77: 2 red, 10 blue, 6 green; 6 blue, 2 red, 8 green; 1 red, 9 green, 7 blue
|
||||
Game 78: 3 green, 10 red; 2 blue, 4 red, 3 green; 8 red, 3 blue, 4 green; 1 blue, 7 red
|
||||
Game 79: 4 green, 2 red; 2 red, 14 green; 1 blue, 5 green, 8 red; 4 red, 20 green; 3 green, 1 blue, 8 red; 4 green, 1 blue
|
||||
Game 80: 2 green; 3 green, 13 red, 10 blue; 6 blue, 10 red, 1 green; 10 green, 12 red, 3 blue; 10 blue, 17 red, 5 green; 8 red, 2 blue, 6 green
|
||||
Game 81: 4 green, 2 blue, 4 red; 16 red, 1 blue, 20 green; 7 blue, 10 red, 9 green; 7 blue, 2 green, 14 red
|
||||
Game 82: 4 blue, 8 green, 5 red; 14 red, 8 blue, 1 green; 11 red, 13 green
|
||||
Game 83: 2 blue, 2 green, 10 red; 10 green, 4 red, 3 blue; 11 green, 14 red, 4 blue; 2 blue, 11 red; 3 blue, 1 green, 4 red
|
||||
Game 84: 12 blue, 9 green, 10 red; 1 red, 6 green, 4 blue; 7 red, 3 green, 16 blue; 3 green, 3 blue
|
||||
Game 85: 2 red, 4 blue; 4 blue, 1 green, 6 red; 9 blue, 1 red; 1 green, 4 blue, 10 red; 5 green, 7 red, 17 blue
|
||||
Game 86: 2 red, 3 blue, 1 green; 2 blue, 2 red, 2 green; 10 blue, 2 green; 5 green, 4 red, 6 blue
|
||||
Game 87: 1 red, 7 blue, 9 green; 3 green, 2 blue; 1 red, 4 blue, 10 green; 10 green, 7 blue, 1 red; 6 blue, 9 green; 9 blue, 7 green, 1 red
|
||||
Game 88: 1 blue, 14 red, 9 green; 4 green, 9 red; 8 green, 1 blue, 10 red
|
||||
Game 89: 13 red, 1 green; 2 blue, 10 red; 1 green, 3 blue, 13 red; 1 green, 14 red, 3 blue; 2 green, 6 red; 1 green, 12 red
|
||||
Game 90: 1 red, 2 blue, 9 green; 1 blue, 3 red, 2 green; 10 green, 9 red; 1 red, 9 green, 4 blue; 3 blue, 13 green, 13 red
|
||||
Game 91: 2 red, 8 green, 8 blue; 3 green, 2 red, 6 blue; 5 green, 4 red
|
||||
Game 92: 8 green, 12 blue, 4 red; 7 red, 4 green; 4 blue, 7 green, 7 red; 7 blue, 5 green
|
||||
Game 93: 1 green, 1 red, 2 blue; 3 green, 1 red, 3 blue; 1 red, 8 blue; 1 green, 13 blue; 1 red, 4 blue, 4 green
|
||||
Game 94: 2 blue, 7 red, 17 green; 2 green, 1 blue, 5 red; 3 blue, 7 green, 1 red; 6 red, 1 blue, 1 green; 1 green, 1 blue, 1 red
|
||||
Game 95: 4 blue, 3 green, 4 red; 17 red, 2 blue; 6 blue, 16 green, 15 red; 7 blue, 17 green; 1 red, 3 green, 3 blue; 7 red, 14 green, 4 blue
|
||||
Game 96: 6 red, 3 blue; 7 green, 5 blue, 10 red; 9 green, 1 blue; 6 blue, 1 red, 12 green; 3 blue, 10 green
|
||||
Game 97: 3 green, 1 red, 13 blue; 1 red, 8 green, 2 blue; 1 green, 2 blue, 2 red; 1 red, 4 green, 9 blue
|
||||
Game 98: 1 green, 8 red, 7 blue; 8 blue, 8 red, 3 green; 1 blue, 2 red; 4 red, 7 blue; 3 green, 3 blue, 3 red
|
||||
Game 99: 9 blue, 14 red; 3 blue, 10 red, 5 green; 3 blue, 3 green, 6 red
|
||||
Game 100: 12 blue, 2 green; 2 green, 4 red, 13 blue; 9 blue, 1 red, 2 green; 2 green, 3 red, 1 blue
|
|
@ -1,77 +0,0 @@
|
|||
const INPUT: &str = include_str!("input.txt");
|
||||
|
||||
mod part_1;
|
||||
use part_1::part_1;
|
||||
mod part_2;
|
||||
use part_2::part_2;
|
||||
|
||||
pub(crate) struct CubeCounts {
|
||||
red: u16,
|
||||
green: u16,
|
||||
blue: u16,
|
||||
}
|
||||
impl CubeCounts {
|
||||
#[must_use]
|
||||
const fn power(&self) -> u16 {
|
||||
self.red * self.green * self.blue
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
const fn zero() -> Self {
|
||||
Self {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
const fn red(red: u16) -> Self {
|
||||
Self {
|
||||
red,
|
||||
green: 0,
|
||||
blue: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
const fn green(green: u16) -> Self {
|
||||
Self {
|
||||
red: 0,
|
||||
green,
|
||||
blue: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
const fn blue(blue: u16) -> Self {
|
||||
Self {
|
||||
red: 0,
|
||||
green: 0,
|
||||
blue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Add<CubeCounts> for CubeCounts {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: CubeCounts) -> Self::Output {
|
||||
Self {
|
||||
red: self.red + rhs.red,
|
||||
green: self.green + rhs.green,
|
||||
blue: self.blue + rhs.blue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::iter::Sum<CubeCounts> for CubeCounts {
|
||||
fn sum<I: Iterator<Item = CubeCounts>>(iter: I) -> Self {
|
||||
iter.fold(CubeCounts::zero(), |acc, x| acc + x)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("{}", part_1(INPUT));
|
||||
println!("{}", part_2(INPUT));
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
use crate::CubeCounts;
|
||||
|
||||
impl CubeCounts {
|
||||
const fn exceeds_limits(&self) -> bool {
|
||||
self.red > 12 || self.green > 13 || self.blue > 14
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn part_1(input: &'static str) -> usize {
|
||||
let id_sum = input
|
||||
.lines()
|
||||
.enumerate()
|
||||
.filter_map(|(game_id, line)| {
|
||||
let game_start_index = line.find(":").expect("Every line should have a ': '") + 2;
|
||||
|
||||
let game = &line[game_start_index..];
|
||||
|
||||
let groups = game.split("; ");
|
||||
|
||||
for group in groups {
|
||||
let color_counts = group.split(", ");
|
||||
|
||||
let group_counts = color_counts.map(|color_count| {
|
||||
let (count, color) = color_count
|
||||
.split_once(' ')
|
||||
.expect("Every color count should have one space");
|
||||
|
||||
let count = count
|
||||
.parse()
|
||||
.expect("Every color count should be a valid number");
|
||||
|
||||
match color {
|
||||
"red" => CubeCounts::red(count),
|
||||
"green" => CubeCounts::green(count),
|
||||
"blue" => CubeCounts::blue(count),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
});
|
||||
if group_counts.sum::<CubeCounts>().exceeds_limits() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(game_id + 1)
|
||||
})
|
||||
.sum();
|
||||
id_sum
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_1(SAMPLE_INPUT), 8)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_1(crate::INPUT), 2449);
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
use crate::CubeCounts;
|
||||
|
||||
pub(crate) fn part_2(input: &'static str) -> u16 {
|
||||
let id_sum = input
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let game_start_index = line.find(':').expect("Every line should have a ': '") + 2;
|
||||
|
||||
let game = &line[game_start_index..];
|
||||
|
||||
let groups = game.split("; ");
|
||||
|
||||
let game_counts = groups
|
||||
.map(|group| {
|
||||
let color_counts = group.split(", ");
|
||||
|
||||
let group_counts = color_counts.map(|color_count| {
|
||||
let (count, color) = color_count
|
||||
.split_once(' ')
|
||||
.expect("Every color count should have one space");
|
||||
|
||||
let count = count
|
||||
.parse()
|
||||
.expect("Every color count should be a valid number");
|
||||
|
||||
match color {
|
||||
"red" => CubeCounts::red(count),
|
||||
"green" => CubeCounts::green(count),
|
||||
"blue" => CubeCounts::blue(count),
|
||||
_ => unreachable!(),
|
||||
}
|
||||
});
|
||||
group_counts.sum::<CubeCounts>()
|
||||
})
|
||||
.reduce(|acc, cube_count| CubeCounts {
|
||||
red: u16::max(acc.red, cube_count.red),
|
||||
green: u16::max(acc.green, cube_count.green),
|
||||
blue: u16::max(acc.blue, cube_count.blue),
|
||||
})
|
||||
.expect("At least one group should exist in each game");
|
||||
game_counts.power()
|
||||
})
|
||||
.sum();
|
||||
id_sum
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_2(SAMPLE_INPUT), 2286);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_2(crate::INPUT), 63981);
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
|
@ -1,140 +0,0 @@
|
|||
..224.....487...................718.....................378............................................284........310......313..........311.
|
||||
....*..............................*744....486*485......*......741......@...359.#666...439................*925....*......$..+........@......
|
||||
.235................758..440...........................251....*......262.....*..........*......................752......774.......515.......
|
||||
.........705%..@746........+..942*591.347.470...#..257.........637...........793.......299..../.....813....509......464......&.........688..
|
||||
.....82................................*.../..901.....*..................836.....&............814...*........*..............80...17*....*...
|
||||
.../...*...679.661.....299...........222.............875.....213...161............964...894.........998.....310....258.85...........735.586.
|
||||
.650..23..#......*.......................................760*........@./........................202...................*.....339.............
|
||||
..............598......#.....536....702*.........705..........793......957............./........*...935...........965.......................
|
||||
..................*.357...+.....@.......242.......*......283..*...=956.......118.......959...184...*..............*....401*527.....348...161
|
||||
.63=...955.523..77......978.846....849..........699..........790........=911.*.....87...............486.........914..............=..........
|
||||
.........*.........842......*.......*..................*127....................844...*....946.......................235...209@...710.735....
|
||||
...........@.........*.....144....226....298........560.....253.........431......*...586.......723..../...482.......&...................*...
|
||||
...........871../918........................+....................329*......%.....906.............*...350.....@...............365.......361..
|
||||
......................536............................+..793..........664.....739................507......289.....256%...73..*...............
|
||||
.356..834..............*.........96.939..............28.+....=..............*...........................*................$.553..........526.
|
||||
...*...*.............501..746....*..-.......=.................890.....+...701..............807........447......97$..%...........58......$...
|
||||
.891....346...699...........*.421......+....666......198*791......340.433............#...%...*.......................316........*.....%.....
|
||||
..............%........81.984...........462....................../..........116...711....963...$................380.......745...85....224...
|
||||
.........370......923..@.....................563...........188+.........326*...................67.815..............*582.....................
|
||||
.........*........-........#530.........489........59...................................................#.....57.........100.*.......441*161
|
||||
.637*....961...........118...........21*...........@..216+.........................+....432*.*309..64....992.......81......=.781.644........
|
||||
.....324.........126......*166...............&...................385*..............233............*................*..436...........*517....
|
||||
.88*.........390*................355..335...372....+254..............294...$589........&..803/.....38..-...........56..$....................
|
||||
....235.-.........+196...948....*........-................359.........................398.............608..../.................145..346.....
|
||||
........915.................-.485.945.................936*................114.............118...............490.536..............*.%........
|
||||
.663........61.......856..........+....343....859...............*345.......*...=862............711.............................313.....606..
|
||||
........23...$.....@..................*......................316.....529.362.............49......................307*791....................
|
||||
225...............281...#..222.....@..283..............675............*.........911*90..-.....914..%39....509...............................
|
||||
.......797*....$........23..../...895.............67.......164.896.....554.....................*............=..............460........181...
|
||||
...........211.474...............................@...........*....*201..........911.717.#....192.75..679...........$.........*.........=....
|
||||
....355.........................&.....................678.650......................*.....128.....*.....*.........925..230...105.............
|
||||
....*.......409#.......*897.....698....427.........+....*.......*...............................313...670..521.......*....&.............*308
|
||||
...838..335.................367........-..........325....233...224...950......688.....199.774.........................793.108........501....
|
||||
...........*..102..924.349...+..595....................................*................&..............395+.....................753.........
|
||||
.........318...*......*........*....676...759.154...................524...........908.........694.211................173...........*214..424
|
||||
....458........403...........958.98....*........*..............688......957...488..+...........*.../....................................*...
|
||||
.......*.............591...............218.....203.....196$.......+....*........*......................765......971......./....927*741..227.
|
||||
......592..%60.$.....*.....885/....287...............................474.........409......226.174.......@........*.....230..................
|
||||
...............162.169.................510..962..............17......................32@..*...*.................225....................-....
|
||||
.....880...................201.....823*........*...914.724.........89...&.......267=.....717.54.436..........60...............&.........69..
|
||||
710........601....306.287.....+.........65...308....&...=.../......*.....926..................................*........278.415......-.......
|
||||
..............*..*......&..........241.%...................827../.265.............662.678......@...#......@.....$......-............734.144.
|
||||
.............424..434.....701.....*........380*731.............24.................*...&........973..741....728..357.........................
|
||||
........304.................*...881................238.....740.........947........587...22...........................271*........603....@...
|
||||
...................266.....918....................*..........+.519.617..*...826..........*............./268..974.........486.376....*.295...
|
||||
...939.........363.*...............378..........302....586........*....740...=..........380........931...........................12.........
|
||||
...*..........-.....387...............*..588..............*..../...............315...................-...712..491.........956.....#.........
|
||||
.180.454...................104..661...91...*.............811....370......471...-....419....804..........*...................*...............
|
||||
.....*.......@../464........%..*............243.....578...................&..........*...........604..250.....784....750....998.............
|
||||
.....245....165.................771...................&.......#.691...768....654....261.........................*.......*............566....
|
||||
441..................91.....194.......643...932*............379.#....$.......*.................86.............940..263.638...........*......
|
||||
...+.............%.../.......#.........*........344...795..................991..........544....*..................*..........767...266......
|
||||
.......-..708..727.....191$......*.....698....=...................990................+.....*....308.......@......325.........*.........44...
|
||||
...18.397....=.....93.........649.900.........62....-........322.....*.......@......339....619..........404..........540........./....*.....
|
||||
..../...............%............................742............*...........196................874.205........96#..............203.224......
|
||||
.........704...727.................496.......*........135....769........./.................%....&....*.../..=.........757...................
|
||||
........*........*..424..........&........714.5........*...........@....884...............114.......674.144..83..........*302...........%...
|
||||
........29....179..*............104..................531....629.455..................473......300....................254..............640...
|
||||
..................296.......................................................1........*.......%..............548........*.....103............
|
||||
....381...........................365#..713.282.......%744....................../....709...#...=...431...$.*......*.....837.....*9.....*....
|
||||
......*.90.....347.179#...................%.......359..........92............304...*.....923.446.......385.699.....749..............193.206.
|
||||
....922.+.......*.......-197.....................*.......128........273....@.....758..............439...................650*54.736#.........
|
||||
................817..-..........152..594..949..807.......$...224...*.....124............889.......=...................................625...
|
||||
....139....667......239........*...........*.......387........%..806........../...........*..788....632...........=8......584-......*.%.....
|
||||
...........*.................280...........11.........*726............181......761..-....66.....%....-................64...........14.......
|
||||
............742.736.725..........708.667..........332.......828*750......-.........425.......................944.....*...................926
|
||||
.719...110...........*.....348...=..........121......*........................................*.......961.....*.......971...........+.......
|
||||
..../.....*629........830..*............91....&..241..491...930............561................889....*....710.333..............163...311....
|
||||
......%...................252.../..................*...........*270.......................165.....208.......*..................../.......694
|
||||
...914...126...267.183........952..$645......414.822................................69.......-..........=..112.464..267....359..........*...
|
||||
.............7*..........................806.../.....931.....*.....355..............*....928...........854.........-..............*993...101
|
||||
439.897...........%...........8......381...*........*....748..987....*............437.......*....954.......................*................
|
||||
.......*595....783........49.....110.$...675...8...60.....=........981........&..........730....*.............336.......120.790..........386
|
||||
............90..............*212...*..........*.......985.....153........*..12...912*383......665.....754.....-.....................950.....
|
||||
......790#.*........896@.........773....777..581..514*....910.....5.....579.............................=.......#.....................*.....
|
||||
...&.......496...........347..............*...............*...................../............................790..............334......912..
|
||||
692............609....&.......694..........693...213....620......695......871..385.......82..........785.......................*..163.......
|
||||
.........#....*......984.........*.................=............*.......................................*.545...-............978.....*......
|
||||
......971...477.............465......196*313..........447.......766......49.......126*480.............798......792..359*193...........837...
|
||||
................157...........+..................773.=..............752$....................447*565..........................*53............
|
||||
.384%..........@.........449............470..749...@.........@792..............138..527.......................339.....299.505...........287.
|
||||
......691........700........@......96..........*........721*.....................@....*...942......845........*......-.........713..........
|
||||
.....*......260/...*...........................491..452.....336.......................73....+..960..........238...........163$..&...=.@.....
|
||||
....689.............831...282....709.960.............=.............204............................#..............59...97..........199..111..
|
||||
........................$........../........-....498......................557....&...........972............450.............................
|
||||
.............653........476...398.........619...*.....*280..923..............*31..691.........*........=...*.....67......782................
|
||||
..............*....%..........*.........+......268...........&........428....................408....740....576....*.......*.........$.......
|
||||
....-../...734......317.114.332...795...743.........................-..=..908...........381.......................914...420.*647....528.....
|
||||
..284.825...............*......................721/.=929.........324.....*....167.561...*.....815*466.......................................
|
||||
..............389..304.480.......851..@....585..............942%......#.496....*....-.53................170....938*..........518............
|
||||
........368..*.....@..............*....941..+.......*...............930.........364.......522......................59.........+....$....652.
|
||||
...........+.963...................949...........828.784......860............*......420.....*..................*......548...........310.*...
|
||||
.....476...............*...............=...94.+..................&........589.833....*..426.940.....&.....959.993.&88....................398
|
||||
.......*................624....917...838..*...664.......721........................833...$.......672......$............19...................
|
||||
....350.......................&....=..............333.................707....................................240..336....=...746.263..$463..
|
||||
.........................-.........220.....663...../.............*849..#..631.....712....=.../...308.580.............*..........*...........
|
||||
.78@......../..........422....444.............*...............281............*...*....447..37.......*................814....................
|
||||
........./...788...810.........&..............369..985....-................92................................684...............74...........
|
||||
......279.........*......128/....464........#...../......944........978...............163..984*5.@............+.......165......*....285.....
|
||||
..................889.............*.......969........................%.......5......&....$........272....................*......374.........
|
||||
.........&..............@948..*..13.358........796.............632............*....789........91*..............*66........152...............
|
||||
........508...+..............3...........544.....$.517.....703....*774.......434............/....794........932.............................
|
||||
...$...........241.....74...........974..*...954............*.......................375..772...........218.........414...........*366....252
|
||||
.501..566...............*..........*....599.....#........256.....468@..942.101.........*..........156...*.............*.......998...........
|
||||
...../.............263.312....+..767..............#.........................*...&95..838.162=.....+....130.........583..544.......176.......
|
||||
............................936......826.......421.......-139.......982...893.......................*..................*........./..........
|
||||
.284.....=724...................661.$....694........85..........438.............51...............616.698.*36.....262......357+........224...
|
||||
....@..........491........+........................@......193......*596...........%../844...387.................$.....132.........%.........
|
||||
.......84..............362.................................*..98..........&................*....14....394..........$..............56........
|
||||
.........*432.....512................704......424.............*............74........196%..875...*.....*............132.......229...........
|
||||
..............723*.........568........*..108........672......55.172...217.........................289.427........................*..........
|
||||
.........#795.........214....*.336...94....*....988................%..&.............*86......*...............838&.......540.......902.......
|
||||
.922...........288........719.....*........845...&..558......#...................524......195.704.....................................77....
|
||||
...*....842....../...166........883...-................*503..451..305../....600............................900..280.....*169...586..........
|
||||
751....*.........../.*......944......116....416.........................877....*....418...194........644..*....=.....244..........#.....354.
|
||||
.......118......208...................................788...................826........$....$...207.....@..152...........893*608.......&....
|
||||
..948.......................203../....206.............*....341./977.916.........49...#........@....-............+385........................
|
||||
...*......266.................*...607...@.990......964..............-..........*.....340...697........62..............526.....-.............
|
||||
..675.....*..........612....604.............*..............492.884...........212...............*157....*...679.........*....706...716%.518..
|
||||
......103.749..989...*...................739..............$......=..=..................212..684.....35.......*.........785..............+...
|
||||
..343*......../.......680.....................*423.................476....&....420..............241..*......532.....+.......864$.....&......
|
||||
..................826........403..311...60.451.............+...........562....../.......306.......*..............420..................321...
|
||||
...241..............*...........+..=....@......*240.......845....@.........740.................968..389.177*...................640..........
|
||||
......*82...........963...211%...............38...............901.....404.........&..253..............-.....37.........218.501...*....320...
|
||||
....*...........................#215...264......298........................*970..801....*....569...............3.......*......%..859.*......
|
||||
.136.818...212...........91*72........*.........-...750.....775*728.29.270...............984.&...371..........*.........639..........670....
|
||||
...........*.../959................438.....524......*...943.........*................755...................162.................446#.........
|
||||
..........290.............751................*.....557..*...483.............421.........*............189.%................/.................
|
||||
....................9.786..-......835.......978........445.%..........350........860..662.......#...*....354........*.....682...............
|
||||
.117..57+....441...*....+............................................../............*.........88....142..........%.927......................
|
||||
...*...........*..402....................874.....734.926$../...............*633......219.84/............662...205...................334.....
|
||||
...981........367........338...332/.........=......*......119....375#.334.......146..............%.....$................384.............-511
|
||||
........165................=....................666.....................#..614.....-..%744..617.887.......848*..............................
|
||||
...........*.203.593...158....*..........152..............+817.....866.......&...............*......../.......904........701.165.80.........
|
||||
404..977.93..*....*....*...396.281......*....953....*................*.........116..97.70=..179....107..338................$...*....622.....
|
||||
......=.....445........................382.....*...672................859......*...%....................&..........-.571......717....*......
|
||||
..................240............175..........808..............225..........988............/604..............232.448..*..651......769.......
|
||||
.........569*....*........975*.....*....968..............585.....*................26.................................394....@.142...........
|
||||
......*......498..969.........360.666...%.........................919.......360........-.*.........%...................................484..
|
||||
...407................886...................................84......................933...101....58........839..425.........................
|
|
@ -1,11 +0,0 @@
|
|||
const INPUT: &str = include_str!("input.txt");
|
||||
|
||||
mod part_1;
|
||||
use part_1::part_1;
|
||||
mod part_2;
|
||||
use part_2::part_2;
|
||||
|
||||
fn main() {
|
||||
println!("{}", part_1(INPUT));
|
||||
println!("{}", part_2(INPUT));
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
use std::iter::Sum;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PartNumber(u64);
|
||||
|
||||
impl<'a> Sum<&'a PartNumber> for u64 {
|
||||
fn sum<I: Iterator<Item = &'a PartNumber>>(iter: I) -> Self {
|
||||
iter.fold(0, |acc, x| acc + x.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn part_1(input: &'static str) -> u64 {
|
||||
let mut part_numbers = vec![];
|
||||
for (y, line) in input.lines().enumerate() {
|
||||
let mut search_index = 0;
|
||||
loop {
|
||||
let search_line = &line[search_index..];
|
||||
if search_line.is_empty() {
|
||||
break;
|
||||
}
|
||||
let Some(number_start) = search_line.find(|c| char::is_ascii_digit(&c)) else {
|
||||
break;
|
||||
};
|
||||
let number_end = search_line[number_start..]
|
||||
.find(|c| !char::is_ascii_digit(&c))
|
||||
.unwrap_or(search_line.len() - number_start)
|
||||
+ number_start;
|
||||
|
||||
let number = search_line[number_start..number_end]
|
||||
.parse()
|
||||
.expect("Should be a valid number");
|
||||
|
||||
// This `line.len()` assumes the input is square
|
||||
let mut has_symbol_neighbor = false;
|
||||
'symbol_search_loop: for y in y.saturating_sub(1)..=usize::min(y + 1, line.len() - 1) {
|
||||
for x in (search_index + number_start).saturating_sub(1)
|
||||
..=usize::min(search_index + number_end, line.len())
|
||||
{
|
||||
let idx = y * (line.len() + 1) + x;
|
||||
let char = input.as_bytes()[idx] as char;
|
||||
if !matches!(char, '0'..='9' | '.' | '\n') {
|
||||
has_symbol_neighbor = true;
|
||||
break 'symbol_search_loop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if has_symbol_neighbor {
|
||||
part_numbers.push(PartNumber(number));
|
||||
}
|
||||
search_index += number_end;
|
||||
}
|
||||
}
|
||||
|
||||
part_numbers.iter().sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_1(SAMPLE_INPUT), 4361)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_1(crate::INPUT), 539590);
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PartNumber {
|
||||
number: u64,
|
||||
adjacent_gear: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn part_2(input: &'static str) -> u64 {
|
||||
let mut part_numbers = vec![];
|
||||
for (y, line) in input.lines().enumerate() {
|
||||
let mut search_index = 0;
|
||||
loop {
|
||||
let search_line = &line[search_index..];
|
||||
if search_line.is_empty() {
|
||||
break;
|
||||
}
|
||||
let Some(number_start) = search_line.find(|c| char::is_ascii_digit(&c)) else {
|
||||
break;
|
||||
};
|
||||
let number_end = search_line[number_start..]
|
||||
.find(|c| !char::is_ascii_digit(&c))
|
||||
.unwrap_or(search_line.len() - number_start)
|
||||
+ number_start;
|
||||
|
||||
let number = search_line[number_start..number_end]
|
||||
.parse()
|
||||
.expect("Should be a valid number");
|
||||
|
||||
let mut gears = vec![];
|
||||
// This `line.len()` assumes the input is square
|
||||
for y in y.saturating_sub(1)..=usize::min(y + 1, line.len() - 1) {
|
||||
for x in (search_index + number_start).saturating_sub(1)
|
||||
..=usize::min(search_index + number_end, line.len())
|
||||
{
|
||||
let idx = y * (line.len() + 1) + x;
|
||||
let char = input.as_bytes()[idx] as char;
|
||||
if matches!(char, '*') {
|
||||
gears.push(idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
part_numbers.extend(gears.iter().map(|&gear| PartNumber {
|
||||
number,
|
||||
adjacent_gear: gear,
|
||||
}));
|
||||
search_index += number_end;
|
||||
}
|
||||
}
|
||||
|
||||
let mut groups = HashMap::new();
|
||||
|
||||
for part_number in part_numbers {
|
||||
let Some(group) = groups.get_mut(&part_number.adjacent_gear) else {
|
||||
groups.insert(part_number.adjacent_gear, vec![part_number]);
|
||||
continue;
|
||||
};
|
||||
group.push(part_number);
|
||||
}
|
||||
|
||||
groups
|
||||
.values()
|
||||
.filter(|group| group.len() == 2)
|
||||
.map(|group| group[0].number * group[1].number)
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_2(SAMPLE_INPUT), 467835);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_2(crate::INPUT), 80703636);
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
|
@ -1,208 +0,0 @@
|
|||
Card 1: 57 76 72 11 8 28 15 38 54 46 | 77 87 71 98 40 7 84 43 61 64 5 50 19 83 79 99 36 47 4 95 30 44 37 55 26
|
||||
Card 2: 44 69 14 83 54 48 21 6 20 26 | 80 26 86 3 9 4 62 34 15 87 60 88 90 29 65 46 92 73 24 12 40 10 99 37 74
|
||||
Card 3: 15 60 63 84 20 93 36 39 17 19 | 68 80 17 91 20 84 69 72 15 39 5 61 74 99 60 85 19 45 24 79 53 36 7 63 93
|
||||
Card 4: 22 74 83 58 88 46 7 52 84 5 | 75 20 95 8 37 56 31 42 73 43 40 48 4 28 99 45 90 63 81 93 68 50 46 30 7
|
||||
Card 5: 4 97 41 50 32 26 68 84 5 11 | 91 70 87 4 88 13 48 51 32 34 38 82 86 11 1 50 40 43 28 5 61 89 84 41 37
|
||||
Card 6: 79 97 39 26 57 69 38 87 60 44 | 22 92 80 38 27 66 54 2 9 62 3 4 71 99 24 97 14 7 93 28 53 50 77 68 73
|
||||
Card 7: 73 91 51 23 90 67 19 81 50 12 | 4 76 97 64 19 85 31 3 74 12 23 60 20 68 52 39 43 65 37 63 40 59 99 80 6
|
||||
Card 8: 23 64 38 82 68 79 49 56 5 76 | 68 25 64 30 40 52 16 53 95 96 85 9 4 7 26 80 62 67 73 35 32 44 90 69 93
|
||||
Card 9: 75 87 69 31 8 11 89 49 95 24 | 35 26 68 69 42 66 37 77 25 45 75 72 38 50 27 24 32 46 11 10 14 95 62 7 86
|
||||
Card 10: 37 25 47 36 57 81 44 6 79 98 | 67 34 86 70 39 97 80 69 27 17 7 50 99 84 45 32 49 53 15 95 19 18 47 37 41
|
||||
Card 11: 87 98 16 76 21 53 8 42 40 75 | 21 7 89 85 65 30 32 19 68 22 64 82 48 62 39 46 4 57 77 18 55 24 34 29 67
|
||||
Card 12: 60 11 44 35 9 56 93 91 15 32 | 31 45 37 63 26 12 15 14 48 92 81 1 97 65 29 95 57 77 99 93 27 25 58 66 61
|
||||
Card 13: 25 75 5 60 47 83 8 37 2 43 | 52 30 68 13 1 92 89 63 78 57 87 75 28 82 59 46 33 3 65 41 47 69 21 2 96
|
||||
Card 14: 64 44 89 88 1 38 20 99 9 81 | 71 68 91 21 92 75 49 22 27 12 9 26 57 13 66 45 40 37 16 4 44 90 98 85 61
|
||||
Card 15: 16 56 91 62 12 83 25 3 70 61 | 81 55 73 96 13 7 67 99 88 90 87 48 83 35 19 97 9 31 20 49 38 44 41 45 5
|
||||
Card 16: 78 68 81 18 76 41 88 45 24 87 | 59 84 67 36 33 57 42 32 11 74 65 31 54 46 72 39 98 40 16 49 79 19 3 44 22
|
||||
Card 17: 84 11 48 66 54 86 28 4 45 23 | 4 54 42 62 81 8 92 45 47 66 84 48 18 72 28 86 23 34 3 24 73 82 96 11 59
|
||||
Card 18: 46 40 41 22 75 92 68 10 52 3 | 84 73 9 22 7 19 3 65 32 6 99 77 97 63 62 59 57 17 8 68 91 28 39 4 41
|
||||
Card 19: 19 57 22 85 75 69 50 62 65 61 | 35 24 50 47 74 97 61 27 66 57 77 75 22 30 70 41 62 69 85 58 81 65 19 91 63
|
||||
Card 20: 18 13 96 41 20 44 62 97 57 52 | 18 59 96 40 23 58 20 57 41 97 44 62 75 54 85 78 94 52 64 34 37 45 84 13 53
|
||||
Card 21: 34 3 13 85 81 19 37 97 29 91 | 9 97 52 3 35 48 24 34 17 50 21 71 57 36 94 82 19 4 14 83 98 37 80 91 59
|
||||
Card 22: 18 14 95 74 23 71 31 83 51 57 | 94 14 63 18 16 73 57 31 5 23 51 69 85 45 70 35 74 49 79 27 40 95 83 13 71
|
||||
Card 23: 54 12 52 31 58 93 9 45 27 64 | 48 54 93 12 44 64 56 83 35 94 33 4 58 89 8 45 27 1 86 90 52 31 19 57 9
|
||||
Card 24: 56 75 17 67 59 37 76 94 25 36 | 24 14 56 53 82 35 92 96 17 34 25 1 16 86 41 95 64 45 38 63 31 18 80 33 66
|
||||
Card 25: 32 22 47 24 80 92 96 67 5 26 | 22 81 87 47 26 96 92 60 57 64 66 16 5 83 67 49 32 39 71 80 40 63 99 75 53
|
||||
Card 26: 62 36 66 9 3 71 75 67 29 61 | 9 31 66 82 29 41 67 71 38 36 28 76 14 75 69 61 99 57 62 88 70 95 63 10 59
|
||||
Card 27: 46 38 59 90 1 65 16 80 76 34 | 70 15 49 31 27 71 54 46 76 1 8 77 93 2 90 39 14 67 62 16 78 56 68 9 58
|
||||
Card 28: 47 85 54 21 37 14 44 73 12 51 | 78 70 14 77 98 88 25 49 9 79 58 23 52 2 43 17 12 84 59 51 56 89 47 48 6
|
||||
Card 29: 74 37 60 11 56 21 87 44 33 46 | 80 61 34 54 9 3 45 7 55 13 98 84 10 19 14 8 90 81 50 69 31 12 38 29 78
|
||||
Card 30: 29 20 44 62 79 34 52 15 49 48 | 17 84 34 1 33 9 23 55 94 10 95 69 42 79 78 44 51 82 20 25 81 29 15 13 32
|
||||
Card 31: 88 41 38 98 34 40 92 36 25 50 | 33 54 18 53 46 69 8 22 25 36 51 34 42 92 85 45 40 60 84 27 97 39 10 70 41
|
||||
Card 32: 5 28 85 29 95 37 60 34 24 16 | 74 8 48 73 34 65 66 56 64 85 78 17 39 67 92 30 75 22 95 12 29 24 6 2 51
|
||||
Card 33: 71 31 99 53 62 80 65 32 13 23 | 87 20 55 24 42 19 67 77 37 89 32 83 44 9 60 46 47 36 49 35 92 10 82 2 81
|
||||
Card 34: 78 61 12 81 96 82 7 30 80 32 | 62 8 56 89 11 12 39 31 17 18 79 51 30 92 48 5 45 78 41 44 77 98 71 67 73
|
||||
Card 35: 59 35 63 76 51 8 53 70 24 97 | 20 36 31 17 77 26 34 15 41 39 61 24 35 46 80 74 2 71 5 91 16 11 55 87 4
|
||||
Card 36: 46 51 79 66 57 52 21 11 75 33 | 88 64 74 99 22 39 42 11 14 65 1 56 86 8 26 16 72 13 55 20 60 40 19 85 58
|
||||
Card 37: 83 88 1 19 95 30 38 43 14 51 | 98 20 22 55 13 58 93 21 68 11 76 70 71 35 44 90 52 53 75 17 96 27 49 31 26
|
||||
Card 38: 87 49 43 19 16 34 88 66 67 9 | 70 46 63 58 7 53 96 1 59 35 91 85 18 21 93 68 90 73 11 92 60 61 98 38 15
|
||||
Card 39: 24 68 25 61 54 63 30 37 21 73 | 50 84 48 10 81 5 62 28 92 66 96 6 20 83 78 88 31 89 12 71 60 8 34 70 90
|
||||
Card 40: 18 72 44 15 3 19 69 63 73 57 | 14 3 52 76 71 12 50 13 86 21 55 31 27 29 43 47 90 75 9 97 6 32 96 37 18
|
||||
Card 41: 81 66 49 20 86 80 4 55 93 44 | 87 81 7 47 25 85 80 51 76 27 78 10 16 50 33 66 13 64 35 18 44 63 29 92 48
|
||||
Card 42: 27 21 14 28 69 89 94 9 19 46 | 92 13 27 99 96 19 43 54 4 14 45 16 44 83 24 61 2 28 5 90 49 51 63 64 73
|
||||
Card 43: 34 49 58 85 23 88 84 78 89 55 | 72 45 73 23 75 52 84 78 46 55 58 71 98 5 56 91 49 39 88 70 42 59 89 85 34
|
||||
Card 44: 18 69 46 58 73 59 56 23 12 40 | 71 23 87 93 21 84 10 79 47 92 91 13 52 1 32 78 59 95 72 55 97 56 43 61 75
|
||||
Card 45: 33 47 58 69 57 1 82 6 61 48 | 48 97 4 1 67 66 82 12 6 29 21 96 90 33 57 28 47 69 74 27 2 32 58 61 9
|
||||
Card 46: 42 54 98 50 36 86 27 66 29 60 | 32 23 40 62 38 91 43 98 29 85 18 30 66 28 81 35 68 61 11 27 50 22 41 46 42
|
||||
Card 47: 1 31 87 71 53 17 5 93 84 56 | 48 26 14 47 34 44 18 93 17 88 61 8 95 74 53 50 56 80 62 84 99 49 87 52 1
|
||||
Card 48: 40 75 79 29 64 57 33 49 95 68 | 7 39 63 79 89 10 23 40 22 86 92 13 57 29 9 19 90 87 58 12 77 16 75 4 91
|
||||
Card 49: 4 45 87 47 71 35 9 2 81 77 | 93 33 49 75 11 34 62 39 83 40 55 17 84 43 80 60 46 7 18 56 48 66 95 57 74
|
||||
Card 50: 88 42 2 30 24 89 15 93 16 45 | 93 45 72 68 30 28 17 82 64 91 29 98 14 24 88 70 55 48 58 10 42 83 66 2 77
|
||||
Card 51: 91 96 87 48 6 73 95 55 71 89 | 94 49 84 33 82 9 21 32 25 46 65 15 86 83 66 11 37 1 14 61 92 36 35 45 27
|
||||
Card 52: 48 3 94 56 41 13 34 8 96 25 | 40 88 46 14 68 25 75 66 87 55 64 78 92 43 19 97 53 90 83 59 69 31 84 95 13
|
||||
Card 53: 13 45 61 92 91 32 49 58 43 36 | 44 70 55 28 2 6 35 79 24 54 82 95 52 73 75 84 34 57 21 23 33 22 80 88 1
|
||||
Card 54: 61 52 20 8 73 54 83 60 29 6 | 74 40 27 46 81 75 3 42 47 69 22 59 58 49 90 63 57 50 79 70 82 5 53 91 39
|
||||
Card 55: 41 51 64 55 57 44 26 70 62 34 | 24 82 49 39 56 84 31 27 86 77 22 6 73 72 99 47 60 18 53 68 42 19 66 9 50
|
||||
Card 56: 30 89 82 17 72 46 98 5 54 58 | 4 86 18 15 84 41 16 63 44 91 12 31 66 96 94 87 49 59 67 64 80 33 5 11 40
|
||||
Card 57: 39 80 17 47 15 96 69 50 46 24 | 5 83 16 52 57 27 98 43 78 1 66 90 19 6 58 3 49 94 85 62 44 54 75 14 9
|
||||
Card 58: 42 77 37 13 74 40 31 92 36 46 | 16 74 80 59 51 31 95 85 40 93 23 15 32 18 46 97 36 13 79 10 37 99 77 25 92
|
||||
Card 59: 39 1 78 7 57 46 91 26 12 94 | 46 13 26 83 21 1 67 78 50 94 8 12 39 61 86 91 35 29 32 72 30 97 57 16 7
|
||||
Card 60: 62 32 18 51 40 96 93 36 80 84 | 42 93 65 8 2 52 84 70 11 1 92 21 80 99 18 14 17 47 56 90 49 67 19 48 97
|
||||
Card 61: 6 83 74 89 44 73 39 42 47 88 | 72 74 42 21 88 77 18 6 83 85 49 73 5 39 78 44 64 10 47 14 89 53 98 13 92
|
||||
Card 62: 91 86 35 23 30 28 77 88 56 41 | 54 26 90 20 96 78 14 5 47 98 31 55 74 83 33 15 67 92 19 40 73 72 52 81 94
|
||||
Card 63: 87 91 78 92 33 71 80 47 13 65 | 32 33 56 55 2 4 61 71 91 97 93 78 83 74 3 13 47 70 54 80 65 60 49 26 96
|
||||
Card 64: 70 61 63 52 32 35 85 46 54 4 | 42 54 32 84 56 46 29 61 63 78 4 36 80 86 26 17 3 87 48 21 85 52 35 70 22
|
||||
Card 65: 83 95 45 97 49 67 13 92 1 90 | 68 75 20 96 6 33 73 1 50 14 17 66 34 78 54 84 92 9 64 61 85 88 72 42 12
|
||||
Card 66: 1 7 99 75 17 21 48 70 30 13 | 70 80 45 89 75 7 21 99 20 54 42 46 67 85 61 17 1 16 30 92 77 48 13 68 90
|
||||
Card 67: 69 55 20 91 47 31 33 75 56 39 | 69 31 62 20 58 1 93 48 35 55 47 13 56 60 50 75 25 37 91 81 10 39 32 33 54
|
||||
Card 68: 14 97 54 28 73 64 81 32 47 17 | 86 48 88 25 47 65 22 81 28 95 41 14 27 26 46 64 79 61 45 96 32 9 21 54 53
|
||||
Card 69: 6 21 89 82 75 48 46 56 68 47 | 48 32 74 30 13 56 93 90 68 33 41 58 21 47 8 17 65 6 89 97 75 82 46 26 59
|
||||
Card 70: 35 48 78 92 64 30 88 77 76 10 | 76 33 48 67 78 64 24 69 36 14 77 85 30 73 53 91 3 35 96 88 43 84 10 95 92
|
||||
Card 71: 59 78 57 66 15 18 41 83 70 35 | 7 62 19 30 48 97 89 71 40 27 11 63 60 47 23 86 10 84 4 75 80 69 61 67 25
|
||||
Card 72: 80 82 46 70 10 14 55 49 62 9 | 31 76 62 17 8 49 19 50 85 72 77 75 42 48 33 60 54 45 12 91 20 92 15 3 25
|
||||
Card 73: 38 83 96 47 42 99 13 82 36 85 | 74 86 59 16 49 45 81 61 44 39 3 91 9 26 35 25 55 21 19 41 90 70 10 29 4
|
||||
Card 74: 92 36 96 65 24 6 98 13 33 86 | 17 83 30 5 46 51 54 81 44 99 33 56 45 14 57 34 8 16 77 48 40 94 82 73 75
|
||||
Card 75: 14 21 57 66 33 8 90 7 4 28 | 91 61 3 84 89 45 60 56 51 10 58 20 96 78 73 93 97 44 19 15 12 90 35 87 42
|
||||
Card 76: 37 91 60 44 43 3 40 33 95 51 | 24 39 81 1 46 83 97 88 87 6 67 40 22 96 93 2 71 33 29 15 41 16 89 21 68
|
||||
Card 77: 91 84 43 9 87 96 37 64 41 31 | 35 13 30 43 78 32 23 85 84 19 88 68 10 63 27 77 61 50 41 94 54 12 97 86 33
|
||||
Card 78: 9 78 53 16 80 56 91 3 62 70 | 85 64 21 88 51 16 15 4 69 30 13 1 70 17 52 23 90 5 24 50 19 81 41 67 12
|
||||
Card 79: 59 28 42 51 66 58 63 9 24 47 | 69 95 26 36 14 62 13 20 35 25 34 74 40 41 9 39 45 77 5 10 55 96 22 81 49
|
||||
Card 80: 72 83 73 23 85 2 53 22 3 43 | 14 50 67 63 19 76 39 60 31 33 62 92 29 12 49 75 69 78 44 8 96 95 34 65 20
|
||||
Card 81: 2 46 29 50 65 57 55 83 74 12 | 4 70 97 54 68 99 81 5 84 10 73 61 88 66 27 8 56 33 79 47 85 49 17 16 34
|
||||
Card 82: 37 30 10 3 8 34 44 24 57 13 | 42 17 25 65 48 71 4 64 51 83 75 27 72 96 45 18 11 15 70 53 91 14 12 87 59
|
||||
Card 83: 82 81 15 4 54 96 74 72 37 70 | 37 78 72 25 4 66 81 97 6 83 43 96 61 44 15 71 40 54 27 70 82 98 74 93 7
|
||||
Card 84: 97 52 96 23 80 53 57 83 16 62 | 5 31 89 91 84 33 52 83 76 23 64 67 10 97 29 63 96 58 74 53 62 57 80 81 92
|
||||
Card 85: 53 33 76 24 81 68 51 47 40 89 | 70 38 51 50 85 57 89 40 30 61 1 24 54 75 32 33 96 19 14 53 76 20 7 99 47
|
||||
Card 86: 19 96 52 18 15 53 82 16 86 13 | 69 27 32 85 87 30 33 83 11 47 3 21 68 70 42 61 46 2 64 65 44 1 97 48 74
|
||||
Card 87: 18 40 55 62 39 95 60 11 76 46 | 82 81 22 46 92 80 62 91 12 40 76 60 69 78 17 18 11 93 56 39 37 88 3 64 95
|
||||
Card 88: 72 65 91 61 57 4 49 24 45 31 | 28 49 91 31 19 59 65 36 34 87 72 24 60 89 17 12 57 30 75 32 63 8 21 4 25
|
||||
Card 89: 18 24 64 43 33 56 6 67 8 16 | 40 21 27 52 3 23 65 89 16 7 96 31 48 73 33 37 18 99 12 50 74 26 71 84 8
|
||||
Card 90: 75 3 92 35 12 26 49 59 60 55 | 65 58 39 73 3 56 11 44 4 47 68 24 86 10 61 6 72 13 82 42 29 93 97 77 8
|
||||
Card 91: 78 40 49 75 60 15 59 7 31 93 | 71 9 48 10 69 29 65 40 21 57 68 87 12 35 81 70 30 94 36 97 51 43 8 82 5
|
||||
Card 92: 3 53 23 43 15 4 98 11 67 29 | 35 3 93 87 83 60 5 92 1 90 67 23 78 98 20 37 81 71 31 82 95 47 53 75 21
|
||||
Card 93: 20 61 6 36 52 77 59 16 18 81 | 66 29 4 87 61 92 78 30 68 69 67 57 88 83 71 54 24 21 13 56 84 35 60 86 53
|
||||
Card 94: 25 52 87 17 94 41 23 30 72 53 | 93 62 38 77 31 24 21 36 75 64 45 83 56 39 90 29 55 43 71 54 42 98 76 74 28
|
||||
Card 95: 84 66 91 8 26 82 85 96 31 36 | 93 51 40 98 69 74 53 67 86 23 77 41 62 89 64 34 5 26 50 73 42 43 13 19 91
|
||||
Card 96: 7 6 90 39 14 73 66 81 33 67 | 63 26 1 58 29 10 3 13 94 9 85 68 69 19 53 96 90 36 49 99 31 74 54 45 77
|
||||
Card 97: 66 64 77 7 88 18 40 24 10 63 | 28 22 62 41 30 21 19 12 50 43 46 42 56 6 60 36 95 82 97 2 73 55 38 53 8
|
||||
Card 98: 48 10 16 15 93 40 37 72 57 88 | 10 59 38 19 97 23 51 40 35 31 56 54 21 27 28 81 15 67 12 57 37 65 9 22 74
|
||||
Card 99: 45 57 7 23 86 82 15 14 75 35 | 55 19 84 37 82 39 15 77 42 52 44 18 75 45 7 69 67 23 86 6 89 14 43 57 35
|
||||
Card 100: 68 85 29 69 17 44 19 56 92 8 | 8 4 20 98 36 39 78 79 72 81 51 22 13 47 2 77 30 28 64 41 89 57 50 34 16
|
||||
Card 101: 6 91 90 43 85 1 19 2 28 9 | 63 25 2 9 83 85 87 43 91 6 62 64 74 28 19 82 92 29 36 1 71 90 60 99 84
|
||||
Card 102: 20 72 12 52 58 28 30 76 42 55 | 30 47 59 29 20 93 90 33 76 58 78 28 52 83 48 72 54 42 67 17 55 12 36 2 37
|
||||
Card 103: 58 18 40 8 73 69 22 74 26 63 | 61 40 63 41 82 87 22 8 34 6 73 95 69 44 45 85 62 74 27 28 26 4 96 58 15
|
||||
Card 104: 42 71 57 39 22 79 43 80 90 37 | 43 37 76 94 40 67 4 55 74 21 7 42 3 39 28 12 80 57 32 61 95 58 64 90 13
|
||||
Card 105: 60 9 50 14 56 11 54 33 77 84 | 77 81 17 99 11 84 70 60 5 43 83 19 80 13 54 33 50 30 87 31 9 4 37 56 14
|
||||
Card 106: 79 87 86 96 1 8 63 43 39 91 | 6 2 75 63 67 38 11 96 90 91 87 97 86 9 21 77 43 36 79 8 40 85 39 1 13
|
||||
Card 107: 97 83 21 39 74 64 79 70 77 14 | 85 32 55 18 24 14 79 57 51 12 4 21 23 70 26 83 39 66 63 1 64 73 30 8 77
|
||||
Card 108: 18 41 11 62 88 38 73 4 47 36 | 82 53 41 92 65 15 42 47 85 96 26 43 58 62 11 3 54 55 89 63 30 17 20 93 2
|
||||
Card 109: 28 34 55 39 22 99 98 89 86 54 | 58 76 46 70 91 43 2 79 16 25 89 42 78 52 12 56 44 69 80 85 84 99 62 19 15
|
||||
Card 110: 32 38 50 41 8 97 84 60 92 40 | 43 7 51 76 69 38 92 34 41 71 8 49 95 79 32 45 42 58 60 40 4 3 98 31 20
|
||||
Card 111: 61 7 67 98 74 21 79 4 85 68 | 90 80 4 8 46 55 40 28 30 38 64 86 73 51 42 66 69 15 29 6 52 78 82 49 41
|
||||
Card 112: 13 92 98 37 72 52 1 30 42 36 | 17 65 49 6 5 33 40 10 57 72 12 53 7 15 44 18 90 46 81 99 26 16 23 52 66
|
||||
Card 113: 39 30 46 62 55 42 32 77 9 37 | 37 21 50 40 63 97 28 11 51 26 75 86 80 32 16 69 77 60 6 99 9 72 22 55 79
|
||||
Card 114: 54 6 72 17 56 76 23 78 7 38 | 15 76 40 56 8 50 51 97 94 64 13 3 69 24 54 66 14 25 82 1 71 41 47 74 92
|
||||
Card 115: 50 66 30 89 46 20 35 59 22 88 | 96 72 32 97 61 64 25 70 4 11 88 34 46 6 10 73 71 79 45 33 66 50 24 13 42
|
||||
Card 116: 83 33 99 22 90 32 11 28 47 85 | 80 58 57 7 15 1 23 59 86 54 67 36 83 38 34 18 37 35 19 90 45 24 46 4 84
|
||||
Card 117: 95 23 58 8 76 82 60 1 15 80 | 75 77 10 85 36 52 91 54 44 96 97 89 25 67 16 31 99 51 68 83 55 29 3 20 33
|
||||
Card 118: 53 7 99 97 39 37 80 52 18 77 | 76 78 83 34 75 69 39 14 27 44 89 56 23 30 43 48 57 61 29 82 87 93 67 62 12
|
||||
Card 119: 19 22 6 97 71 68 59 95 67 75 | 91 40 20 74 87 46 4 85 63 64 50 88 14 1 54 39 3 62 58 10 28 55 27 86 60
|
||||
Card 120: 37 76 87 74 15 84 14 11 99 60 | 24 15 92 60 25 3 86 1 33 5 62 65 79 6 91 45 11 14 10 2 43 4 68 85 54
|
||||
Card 121: 74 43 96 14 67 85 19 51 80 95 | 27 53 14 15 72 99 85 30 33 20 13 58 12 25 36 18 45 67 34 79 32 76 96 95 55
|
||||
Card 122: 93 51 95 32 2 18 40 72 31 45 | 8 98 70 17 62 22 63 72 69 73 3 26 42 25 1 41 28 13 77 92 32 60 56 2 65
|
||||
Card 123: 9 82 93 20 35 69 87 40 30 67 | 87 10 67 63 76 23 45 35 54 5 75 79 66 40 1 89 71 20 77 43 90 65 9 82 37
|
||||
Card 124: 93 48 59 54 75 8 83 35 4 64 | 71 59 41 35 4 65 49 5 98 91 54 45 76 64 93 75 8 83 48 87 94 32 16 89 82
|
||||
Card 125: 24 14 40 22 2 57 67 35 36 98 | 36 82 19 88 23 55 15 97 78 35 94 24 67 52 14 30 40 56 38 57 2 31 22 98 71
|
||||
Card 126: 22 7 97 12 95 66 69 51 59 88 | 94 88 59 58 70 64 95 29 7 93 68 21 16 19 36 39 41 66 10 76 78 82 63 34 56
|
||||
Card 127: 46 9 32 85 22 20 14 68 98 61 | 69 25 4 70 64 57 14 89 41 98 22 53 27 77 20 56 84 42 85 40 90 6 61 71 60
|
||||
Card 128: 53 84 81 45 23 13 93 34 42 80 | 80 74 39 50 75 49 7 61 43 5 1 51 36 54 57 97 26 32 82 98 68 45 93 37 86
|
||||
Card 129: 40 29 85 88 86 7 49 67 91 92 | 86 38 79 31 57 34 78 17 52 53 22 36 62 75 21 70 88 7 3 49 28 6 85 14 4
|
||||
Card 130: 63 20 36 62 43 98 99 12 46 57 | 14 32 99 22 17 70 5 91 57 95 49 15 28 46 84 89 78 79 43 98 45 50 88 16 23
|
||||
Card 131: 7 16 87 36 73 82 11 40 14 69 | 25 31 82 24 50 38 2 28 4 23 72 6 51 79 86 46 55 97 42 90 84 1 39 32 27
|
||||
Card 132: 67 56 15 63 40 9 59 23 94 27 | 26 65 80 40 46 23 37 78 27 12 34 98 41 59 94 16 50 79 90 15 4 7 6 62 17
|
||||
Card 133: 18 91 27 52 4 34 12 32 65 41 | 45 55 7 3 84 79 54 91 75 80 17 49 42 9 18 48 59 6 8 22 94 10 93 53 57
|
||||
Card 134: 78 75 48 26 14 8 91 41 34 68 | 18 29 57 5 17 22 56 97 74 34 13 50 40 33 62 20 10 71 58 1 21 88 87 8 25
|
||||
Card 135: 5 97 16 92 74 51 61 65 3 14 | 15 50 86 24 99 90 59 32 45 81 97 75 6 25 29 80 9 89 46 70 40 57 42 63 60
|
||||
Card 136: 81 35 23 70 51 14 31 50 67 7 | 32 28 40 58 4 99 18 95 11 90 86 13 84 74 61 5 44 47 24 38 21 1 77 48 78
|
||||
Card 137: 74 99 57 81 5 1 90 9 69 30 | 88 23 97 7 25 68 78 91 53 15 55 81 92 90 12 18 50 71 61 75 8 76 36 19 34
|
||||
Card 138: 37 2 84 13 78 51 29 15 42 71 | 49 30 16 88 79 67 76 75 38 80 91 6 28 83 14 26 1 19 40 18 32 98 74 17 44
|
||||
Card 139: 49 75 16 61 39 4 51 55 17 97 | 11 45 56 47 81 78 67 21 57 42 84 58 8 13 10 91 7 19 46 14 90 87 26 1 18
|
||||
Card 140: 39 19 41 45 17 30 29 66 61 25 | 61 53 29 41 37 30 95 93 45 17 8 21 66 10 14 78 65 18 39 5 52 91 19 25 4
|
||||
Card 141: 7 66 29 40 9 14 34 64 4 31 | 98 63 65 6 92 56 81 67 48 88 49 18 38 61 13 95 28 85 20 17 21 30 58 52 89
|
||||
Card 142: 32 88 54 27 21 86 49 87 44 45 | 15 44 67 75 87 79 21 10 34 70 54 49 88 3 28 32 65 27 43 98 53 64 45 86 9
|
||||
Card 143: 14 7 67 53 37 73 45 18 62 34 | 87 68 3 22 40 86 26 85 70 4 61 78 1 29 48 12 37 10 77 54 99 36 94 79 15
|
||||
Card 144: 92 35 52 27 19 16 58 4 22 85 | 47 37 30 51 96 28 58 81 85 9 19 10 46 22 27 7 35 52 16 60 4 92 53 13 84
|
||||
Card 145: 71 32 62 83 43 20 97 57 78 24 | 88 34 23 25 67 52 11 9 49 80 70 29 43 2 44 45 62 56 33 3 20 98 28 77 79
|
||||
Card 146: 99 11 17 93 16 77 1 46 55 68 | 25 17 77 99 35 53 3 84 98 2 21 74 27 58 16 20 33 22 39 28 69 9 92 46 52
|
||||
Card 147: 56 26 30 23 66 94 82 47 14 49 | 68 41 6 13 99 7 71 67 35 93 57 84 44 40 70 89 42 63 74 22 20 55 33 91 64
|
||||
Card 148: 21 6 43 36 7 44 61 23 93 57 | 53 20 51 59 74 77 16 92 47 25 62 58 18 85 3 63 46 81 99 5 79 70 69 75 34
|
||||
Card 149: 31 36 91 20 17 50 1 18 64 52 | 66 90 80 33 26 24 30 58 45 77 25 29 44 48 6 35 96 13 78 65 68 98 93 89 94
|
||||
Card 150: 81 91 37 66 12 33 59 97 38 32 | 61 38 91 95 75 85 48 44 37 47 84 66 35 62 79 94 25 22 97 17 10 31 96 5 78
|
||||
Card 151: 32 35 11 75 63 61 42 62 10 56 | 4 44 53 12 50 76 51 5 82 25 30 8 89 41 34 98 54 96 37 74 35 16 31 57 65
|
||||
Card 152: 96 60 29 43 99 19 80 8 5 2 | 87 52 19 11 99 35 20 60 55 80 24 21 8 61 38 78 42 28 95 6 64 65 49 59 26
|
||||
Card 153: 53 30 75 13 87 77 56 89 63 6 | 7 54 93 80 47 4 72 9 69 44 97 96 23 24 94 67 55 8 33 30 37 6 14 5 3
|
||||
Card 154: 10 65 46 58 13 25 69 52 19 3 | 47 41 9 3 40 79 89 21 33 73 14 7 74 65 31 62 24 69 60 87 12 16 53 80 82
|
||||
Card 155: 24 51 35 95 93 73 36 65 27 20 | 14 83 97 94 29 39 19 38 33 32 44 92 60 25 76 64 49 71 65 34 91 31 53 74 23
|
||||
Card 156: 52 31 50 54 82 42 23 9 39 3 | 29 64 88 70 48 74 12 90 75 57 23 25 58 68 36 33 73 5 84 28 47 92 50 41 21
|
||||
Card 157: 66 20 50 96 6 84 54 67 59 81 | 77 60 38 65 37 44 15 73 23 83 18 71 89 53 90 36 40 32 2 39 78 63 8 51 19
|
||||
Card 158: 38 46 85 81 87 86 98 90 37 34 | 41 71 35 26 12 19 51 93 39 20 76 24 7 80 50 56 49 2 57 84 68 92 54 1 75
|
||||
Card 159: 61 36 84 47 4 22 49 17 31 75 | 77 83 49 55 84 80 18 44 31 47 22 67 4 68 69 35 75 5 59 13 61 39 36 54 17
|
||||
Card 160: 90 70 62 65 87 95 15 77 76 35 | 70 94 97 10 90 80 35 27 84 87 42 62 54 26 95 57 82 63 1 18 92 25 49 64 21
|
||||
Card 161: 44 6 28 50 79 16 15 83 45 53 | 79 72 12 45 50 35 67 6 89 28 15 61 16 7 46 36 44 55 27 92 1 59 83 53 94
|
||||
Card 162: 29 51 46 64 4 75 37 78 81 71 | 83 71 37 39 74 66 32 1 51 93 43 46 20 3 15 50 81 64 75 73 78 29 33 4 22
|
||||
Card 163: 1 52 37 97 88 47 94 10 98 5 | 85 31 33 46 15 1 16 61 98 59 64 94 83 68 35 11 44 80 38 36 84 72 86 40 29
|
||||
Card 164: 60 40 94 62 18 71 92 25 21 64 | 64 18 58 76 38 55 40 45 71 92 73 75 25 62 12 94 68 79 23 91 21 60 72 39 7
|
||||
Card 165: 63 88 91 22 85 18 39 55 33 84 | 95 88 37 5 39 46 33 61 32 45 74 20 27 35 76 85 84 18 54 86 91 75 22 55 63
|
||||
Card 166: 72 11 31 50 53 82 41 74 62 87 | 42 34 50 11 96 3 77 7 37 22 44 38 62 1 87 68 12 54 74 53 47 82 69 89 85
|
||||
Card 167: 79 26 70 95 25 16 18 37 75 61 | 39 11 68 61 44 53 42 94 37 45 75 78 62 18 95 26 79 92 38 13 16 64 21 91 57
|
||||
Card 168: 94 86 69 88 31 15 62 44 19 14 | 3 24 29 8 44 61 89 7 75 15 91 36 45 70 66 4 35 6 71 22 25 39 55 33 18
|
||||
Card 169: 86 68 72 15 42 99 9 35 2 74 | 42 84 59 86 6 15 53 89 85 79 20 68 62 61 10 2 9 51 99 54 33 35 13 48 93
|
||||
Card 170: 83 6 15 80 93 63 79 50 69 5 | 15 25 6 93 69 50 83 68 16 40 66 58 63 79 52 7 80 34 61 95 5 33 78 91 32
|
||||
Card 171: 33 85 4 12 72 62 49 67 17 53 | 4 17 53 72 47 6 49 56 82 48 12 26 30 85 61 15 36 70 64 25 2 33 67 46 62
|
||||
Card 172: 98 63 26 82 12 61 56 95 27 99 | 76 30 14 95 26 97 71 19 57 67 73 48 63 54 82 18 98 27 61 5 12 44 1 56 74
|
||||
Card 173: 7 32 34 4 22 79 27 10 78 65 | 3 81 65 36 91 62 94 54 41 32 12 28 39 34 18 61 78 79 80 66 9 63 43 72 97
|
||||
Card 174: 14 78 60 32 26 31 15 80 11 72 | 1 31 33 35 73 83 97 36 21 3 26 9 91 23 51 84 82 70 22 20 34 90 98 87 69
|
||||
Card 175: 73 14 7 11 20 64 30 90 62 23 | 60 53 15 73 63 19 71 92 48 89 80 44 78 79 2 76 45 64 42 35 81 27 10 21 26
|
||||
Card 176: 32 30 39 10 1 3 67 66 94 62 | 86 95 56 54 58 35 90 19 74 43 5 48 17 2 46 65 97 71 36 31 69 8 47 94 42
|
||||
Card 177: 24 90 40 47 51 75 63 29 57 10 | 49 68 61 43 30 26 84 59 99 75 44 41 17 24 12 38 90 37 36 35 91 9 89 46 8
|
||||
Card 178: 73 74 31 76 10 21 70 3 30 41 | 39 14 30 70 79 75 97 44 87 20 92 12 86 56 18 46 8 90 23 98 2 59 28 53 3
|
||||
Card 179: 78 44 89 84 50 97 55 90 77 99 | 79 1 88 65 2 50 72 68 7 15 85 41 64 93 37 16 53 44 42 48 89 97 59 60 8
|
||||
Card 180: 55 98 13 45 33 91 88 4 49 37 | 18 44 64 83 56 79 81 26 78 54 72 75 11 70 66 57 73 61 62 34 19 95 93 94 76
|
||||
Card 181: 94 47 65 55 8 45 1 67 71 25 | 99 34 43 64 36 50 6 51 27 59 37 40 3 98 72 78 38 74 82 46 85 90 48 32 84
|
||||
Card 182: 78 75 63 31 30 70 84 50 28 19 | 61 18 58 87 77 48 71 50 91 92 60 86 73 94 85 57 97 15 1 25 74 67 11 68 47
|
||||
Card 183: 94 27 68 41 8 72 48 85 97 49 | 81 35 90 69 76 18 53 1 59 25 88 31 4 93 84 32 9 55 66 50 22 62 43 60 17
|
||||
Card 184: 40 31 56 54 59 98 93 81 24 44 | 62 42 93 56 99 10 81 59 37 6 41 66 44 72 31 30 20 54 51 24 27 83 40 73 98
|
||||
Card 185: 38 73 79 48 3 46 99 93 50 24 | 65 34 40 2 20 92 10 32 67 57 22 47 96 11 7 31 87 6 28 95 77 25 58 29 27
|
||||
Card 186: 47 65 99 98 90 68 13 49 51 10 | 90 82 27 68 84 83 57 50 18 5 49 65 85 10 46 13 21 81 73 51 71 47 98 88 99
|
||||
Card 187: 25 56 18 15 59 47 20 86 50 83 | 25 57 83 36 56 87 50 34 9 70 4 64 77 45 92 13 20 47 48 15 97 18 86 28 59
|
||||
Card 188: 99 16 44 2 85 17 71 45 49 11 | 94 13 45 36 77 89 26 6 39 27 84 1 80 21 73 41 33 90 46 72 65 96 34 71 83
|
||||
Card 189: 34 24 76 68 47 19 85 15 50 46 | 43 67 4 44 14 34 19 61 47 68 50 46 99 94 16 76 15 28 36 27 52 85 88 24 89
|
||||
Card 190: 56 20 43 86 2 88 87 30 14 4 | 43 14 19 92 3 23 87 74 50 97 2 88 18 80 20 86 36 41 95 27 57 98 49 30 26
|
||||
Card 191: 47 2 18 84 91 66 24 6 42 56 | 12 93 7 50 42 45 2 91 66 4 32 47 19 56 49 18 15 24 44 84 97 6 16 31 25
|
||||
Card 192: 42 88 68 56 93 48 9 52 20 70 | 30 93 42 4 68 70 36 56 9 15 88 98 64 67 33 91 20 61 50 27 13 94 52 48 85
|
||||
Card 193: 46 57 19 40 9 7 47 33 86 11 | 65 54 38 43 82 55 79 51 77 73 74 97 75 96 6 47 62 88 92 18 84 48 41 29 52
|
||||
Card 194: 58 23 35 79 82 72 44 93 12 43 | 43 60 2 24 77 48 61 25 44 75 35 12 93 51 36 72 6 31 29 50 37 80 19 14 87
|
||||
Card 195: 15 77 78 50 36 83 68 52 86 26 | 16 72 67 88 14 81 34 24 71 32 91 77 90 1 98 95 7 28 49 84 86 20 44 73 56
|
||||
Card 196: 25 3 32 15 1 56 27 51 82 81 | 87 79 15 11 98 54 56 88 18 92 69 25 66 27 60 58 44 1 51 3 32 81 12 72 41
|
||||
Card 197: 3 99 81 8 93 28 76 7 27 48 | 78 98 85 5 93 77 72 62 69 82 50 9 35 74 18 10 33 67 90 31 79 84 58 29 17
|
||||
Card 198: 26 81 19 24 59 82 8 95 86 17 | 13 22 10 96 19 20 88 3 90 78 24 9 50 34 6 94 7 60 44 76 31 81 26 33 43
|
||||
Card 199: 77 91 58 16 47 94 23 30 88 5 | 38 66 12 25 95 67 72 89 36 45 63 15 54 98 74 57 32 39 59 28 7 62 82 13 26
|
||||
Card 200: 82 47 52 12 83 4 26 93 33 9 | 31 30 91 2 6 27 28 1 81 8 75 92 56 57 41 24 72 85 53 74 59 11 66 32 54
|
||||
Card 201: 4 13 26 57 84 17 63 10 98 56 | 72 85 68 47 44 60 54 34 38 16 8 11 23 84 32 18 69 13 26 35 9 73 43 15 89
|
||||
Card 202: 11 9 1 42 71 78 97 89 8 10 | 33 17 81 48 60 96 69 37 12 46 73 4 76 54 86 91 28 5 51 98 99 84 13 85 32
|
||||
Card 203: 37 80 7 87 79 60 6 49 16 12 | 23 34 15 46 38 20 27 45 33 97 37 14 68 83 49 79 43 70 57 60 11 63 24 35 73
|
||||
Card 204: 84 24 48 76 7 18 77 37 69 5 | 88 39 92 94 34 37 11 40 85 35 2 81 73 58 42 66 83 9 56 12 14 51 62 20 7
|
||||
Card 205: 5 84 4 6 95 77 59 67 74 35 | 58 47 29 34 79 86 35 89 71 96 27 64 90 48 37 78 1 39 46 21 98 91 43 8 56
|
||||
Card 206: 56 21 34 13 1 17 99 11 76 60 | 36 24 83 31 50 19 82 32 61 9 98 71 79 39 97 37 29 13 27 10 52 22 41 40 59
|
||||
Card 207: 62 7 22 90 51 96 12 13 36 52 | 48 37 70 24 73 51 83 3 5 77 29 87 23 18 26 76 19 97 20 86 84 14 63 33 21
|
||||
Card 208: 40 42 5 91 29 59 70 49 23 94 | 82 81 30 61 64 65 19 9 67 75 92 16 26 52 73 43 55 35 17 93 39 90 74 53 51
|
|
@ -1,12 +0,0 @@
|
|||
#![allow(dead_code)]
|
||||
const INPUT: &str = include_str!("input.txt");
|
||||
|
||||
mod part_1;
|
||||
use part_1::part_1;
|
||||
mod part_2;
|
||||
use part_2::part_2;
|
||||
|
||||
fn main() {
|
||||
println!("{}", part_1(INPUT));
|
||||
println!("{}", part_2(INPUT));
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
struct Card {
|
||||
numbers: HashSet<u8>,
|
||||
winning_numbers: HashSet<u8>,
|
||||
}
|
||||
|
||||
impl Card {
|
||||
fn score(&self) -> usize {
|
||||
let winning_number_count =
|
||||
HashSet::intersection(&self.numbers, &self.winning_numbers).count();
|
||||
|
||||
match winning_number_count {
|
||||
0 => 0,
|
||||
x => usize::pow(2, x as u32 - 1),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn part_1(input: &'static str) -> usize {
|
||||
let prefix_end = input.find(':').expect("Input should start with 'Card X:'") + 1;
|
||||
input
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let mut number_groups = line[prefix_end..].split('|').map(|group| {
|
||||
group
|
||||
.split(' ')
|
||||
.filter_map(|number| {
|
||||
if number.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
number
|
||||
.trim()
|
||||
.parse::<u8>()
|
||||
.expect("Every number should be a valid u8"),
|
||||
)
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
let numbers = number_groups
|
||||
.next()
|
||||
.expect("There should be two groups of numbers");
|
||||
|
||||
let winning_numbers = number_groups
|
||||
.next()
|
||||
.expect("There should be two groups of numbers");
|
||||
|
||||
assert!(
|
||||
number_groups.next().is_none(),
|
||||
"There should be no more groups of numbers"
|
||||
);
|
||||
|
||||
Card {
|
||||
numbers,
|
||||
winning_numbers,
|
||||
}
|
||||
.score()
|
||||
})
|
||||
.sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_1(SAMPLE_INPUT), 13)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_1(crate::INPUT), 24160);
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
struct Card {
|
||||
times_won: usize,
|
||||
numbers: HashSet<u8>,
|
||||
winning_numbers: HashSet<u8>,
|
||||
}
|
||||
|
||||
impl Card {
|
||||
fn winning_number_count(&self) -> usize {
|
||||
HashSet::intersection(&self.numbers, &self.winning_numbers).count()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn part_2(input: &'static str) -> usize {
|
||||
let prefix_end = input.find(':').expect("Input should start with 'Card X:'") + 1;
|
||||
let mut cards = input
|
||||
.lines()
|
||||
.map(|line| {
|
||||
let mut number_groups = line[prefix_end..].split('|').map(|group| {
|
||||
group
|
||||
.split(' ')
|
||||
.filter_map(|number| {
|
||||
if number.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(
|
||||
number
|
||||
.trim()
|
||||
.parse::<u8>()
|
||||
.expect("Every number should be a valid u8"),
|
||||
)
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
let numbers = number_groups
|
||||
.next()
|
||||
.expect("There should be two groups of numbers");
|
||||
|
||||
let winning_numbers = number_groups
|
||||
.next()
|
||||
.expect("There should be two groups of numbers");
|
||||
|
||||
assert!(
|
||||
number_groups.next().is_none(),
|
||||
"There should be no more groups of numbers"
|
||||
);
|
||||
|
||||
Card {
|
||||
times_won: 1,
|
||||
numbers,
|
||||
winning_numbers,
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for idx in 0..cards.len() {
|
||||
let card_score = cards[idx].winning_number_count();
|
||||
|
||||
for winning_idx in (idx + 1)..(idx + 1 + card_score) {
|
||||
cards[winning_idx].times_won += cards[idx].times_won;
|
||||
}
|
||||
}
|
||||
|
||||
cards.iter().map(|card| card.times_won).sum()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(super::part_2(SAMPLE_INPUT), 30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(super::part_2(crate::INPUT), 5659035);
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
|
|
@ -1,252 +0,0 @@
|
|||
seeds: 432986705 28073546 1364097901 88338513 2733524843 234912494 3151642679 224376393 485709676 344068331 1560394266 911616092 3819746175 87998136 892394515 435690182 4218056486 23868437 848725444 8940450
|
||||
|
||||
seed-to-soil map:
|
||||
748585809 2125564114 88980459
|
||||
1317392128 775565564 217595062
|
||||
1218610825 676784261 98781303
|
||||
954230685 2235762425 141777617
|
||||
2920242079 4081180892 51765553
|
||||
2972007632 3159586797 16102841
|
||||
0 2377540042 17565155
|
||||
2834452876 3712797875 58062179
|
||||
2892515055 2917079842 6424918
|
||||
3327351062 3175689638 162608005
|
||||
673338549 647264576 29519685
|
||||
1197392973 2214544573 21217852
|
||||
738232750 116664417 10353059
|
||||
2988110473 2429807442 71556277
|
||||
17565155 334379348 277510712
|
||||
1700771639 228674051 105705297
|
||||
3059666750 4132946445 162020851
|
||||
1806476936 993160626 588628261
|
||||
1096008302 127289380 101384671
|
||||
622123656 1908836676 50942989
|
||||
3221687601 3338297643 28028532
|
||||
2408505336 3770860054 310320838
|
||||
4175210607 3039830108 119756689
|
||||
3326652416 3039131462 698646
|
||||
2898939973 2408505336 21302106
|
||||
673066645 127017476 271904
|
||||
3489959067 3382623558 330174317
|
||||
702858234 611890060 35374516
|
||||
4086270124 2562002619 88940483
|
||||
837566268 0 116664417
|
||||
1534987190 1959779665 165784449
|
||||
2718826174 2923504760 115626702
|
||||
3249716133 3366326175 16297383
|
||||
3820133384 2650943102 266136740
|
||||
3266013516 2501363719 60638900
|
||||
295075867 1581788887 327047789
|
||||
|
||||
soil-to-fertilizer map:
|
||||
2018515973 2192795257 82329405
|
||||
3722326327 3015971185 249665840
|
||||
3046459770 3689390318 25519185
|
||||
3971992167 3265637025 40217941
|
||||
3071978955 3453653215 203407731
|
||||
0 443504340 17965088
|
||||
584437096 1722124969 470670288
|
||||
1055107384 744431503 164966659
|
||||
1489299099 461469428 282962075
|
||||
2321848831 2380372526 153650776
|
||||
2100845378 269225056 174279284
|
||||
3487660258 2648616968 234666069
|
||||
3275386686 3305854966 147798249
|
||||
1772261174 1172578553 246254799
|
||||
4012210108 2883283037 132688148
|
||||
3423184935 4138946628 64475323
|
||||
4144898256 2321848831 58523695
|
||||
538253726 1418833352 46183370
|
||||
1220074043 0 269225056
|
||||
17965088 909398162 263180391
|
||||
2590093273 3657060946 32329372
|
||||
281145479 1465016722 257108247
|
||||
2622422645 3714909503 424037125
|
||||
2475499607 2534023302 114593666
|
||||
|
||||
fertilizer-to-water map:
|
||||
3731805434 353192162 37567806
|
||||
926873139 889685769 255250442
|
||||
3170336676 695153543 194532226
|
||||
679924479 451681440 193671776
|
||||
3009343704 3081959489 160992972
|
||||
1242360754 3579359343 278026518
|
||||
1861131448 2500688596 20068354
|
||||
4028837903 4006213119 266129393
|
||||
1182123581 3242952461 60237173
|
||||
3877550443 645353216 49800327
|
||||
2223776164 1371077033 341527178
|
||||
3364868902 2566566565 36440100
|
||||
1773121333 0 76664401
|
||||
264823995 2444756861 55931735
|
||||
3929841219 3857385861 27802851
|
||||
2166799431 1712604211 56976733
|
||||
873596255 1769580944 53276884
|
||||
645696746 3047731756 34227733
|
||||
3927350770 3955153621 2490449
|
||||
3769373240 177937131 108177203
|
||||
0 3314535348 264823995
|
||||
1942121274 3885188712 69964909
|
||||
1881199802 390759968 60921472
|
||||
1849785734 3303189634 11345714
|
||||
3401309002 2855740726 104355610
|
||||
2079164011 2960096336 87635420
|
||||
544424016 76664401 101272730
|
||||
2565303342 2520756950 45809615
|
||||
1520387272 2603006665 252734061
|
||||
2012086183 286114334 67077828
|
||||
2611112957 1822857828 398230747
|
||||
320755730 2221088575 223668286
|
||||
3505664612 1144936211 226140822
|
||||
4006213119 4272342512 22624784
|
||||
|
||||
water-to-light map:
|
||||
62780592 544346201 30115959
|
||||
2740764032 1352944740 34082945
|
||||
377487729 807592920 35446631
|
||||
1316419610 1454554942 34907962
|
||||
986581913 756881718 50711202
|
||||
4167758628 3240047125 127208668
|
||||
818809239 1222506283 58684750
|
||||
3649838514 2036598113 6212644
|
||||
127663629 0 10715051
|
||||
3023280854 1435387310 19167632
|
||||
663070842 10715051 124076893
|
||||
2774846977 2422700597 37614763
|
||||
1812617371 2460315360 5121443
|
||||
1640337506 1864318248 172279865
|
||||
2986755724 1316419610 36525130
|
||||
2023334670 2467203928 540327060
|
||||
1159184084 248462172 14557802
|
||||
1037293115 152894449 95567723
|
||||
0 134791944 18102505
|
||||
18102505 712203631 44678087
|
||||
465375803 972369801 197695039
|
||||
2576394916 3007530988 65274194
|
||||
92896551 1281191033 34767078
|
||||
3656051158 4289142647 5824649
|
||||
412934360 1170064840 52441443
|
||||
3417303830 3873138614 84580361
|
||||
787147735 263019974 31661504
|
||||
1817738814 2042810757 205595856
|
||||
1285160111 843039551 30798000
|
||||
2563661730 3123136764 12733186
|
||||
138378680 305237152 239109049
|
||||
3648071389 2465436803 1767125
|
||||
1132860838 574462160 26323246
|
||||
888049663 873837551 98532250
|
||||
3626039273 3072805182 22032116
|
||||
3530183657 4193287031 95855616
|
||||
1404769450 3957718975 235568056
|
||||
3042448486 1489462904 374855344
|
||||
2641669110 1387027685 48359625
|
||||
877493989 294681478 10555674
|
||||
3501884191 3094837298 28299466
|
||||
1351327572 3186605247 53441878
|
||||
2690028735 3135869950 50735297
|
||||
2812461740 2248406613 174293984
|
||||
3661875807 3367255793 505882821
|
||||
1173741886 600785406 111418225
|
||||
|
||||
light-to-temperature map:
|
||||
964570004 989608620 226759942
|
||||
2204148775 2545437438 20646474
|
||||
233260112 338444213 39032265
|
||||
958191857 332066066 6378147
|
||||
2318799855 914518254 75090366
|
||||
4247140372 3146297568 47826924
|
||||
2224795249 1216368562 94004606
|
||||
2871022952 1310373168 80313918
|
||||
1400254919 233260112 98805954
|
||||
445493256 487550555 149554087
|
||||
2576473348 3962746668 294549604
|
||||
3535295748 2775008885 371288683
|
||||
1499060873 377476478 110074077
|
||||
272292377 2215619580 173200879
|
||||
3347481948 1867953550 157067409
|
||||
4161267146 3794452372 85873226
|
||||
3504549357 2184873189 30746391
|
||||
1759636962 1780717197 87236353
|
||||
2951336870 2388820459 6114967
|
||||
1191329946 2566083912 208924973
|
||||
1884544339 3880325598 82421070
|
||||
595047343 3431307858 363144514
|
||||
2393890221 731935127 182583127
|
||||
4001414916 2025020959 159852230
|
||||
2957451837 1390687086 390030111
|
||||
1846873315 4257296272 37671024
|
||||
1966965409 3194124492 237183366
|
||||
1609134950 2394935426 150502012
|
||||
3906584431 637104642 94830485
|
||||
|
||||
temperature-to-humidity map:
|
||||
1406768592 2335526312 13344484
|
||||
666958498 1862550129 472976183
|
||||
558853371 843618476 74696086
|
||||
1168798622 129171378 168640618
|
||||
1713291209 297811996 183431863
|
||||
1993628008 635748116 152317885
|
||||
2560263686 2849350774 11516524
|
||||
32266442 1212766321 287276323
|
||||
2571780210 3319898101 11192927
|
||||
375095240 995599149 183758131
|
||||
2661986290 2353962919 50829838
|
||||
3252020768 4280298713 14668583
|
||||
1337439240 1793220777 69329352
|
||||
3419718116 3502299739 574454544
|
||||
2353962919 2650392505 198958269
|
||||
633549457 1179357280 33409041
|
||||
2582973137 4076754283 50515665
|
||||
319542765 788066001 55552475
|
||||
1896723072 32266442 96904936
|
||||
1420113076 1500042644 293178133
|
||||
3006421020 2404792757 245599748
|
||||
2842554807 3331091028 163866213
|
||||
2633488802 2990605977 28497488
|
||||
2300450150 947178503 48420646
|
||||
3266689351 4127269948 153028765
|
||||
2145945893 481243859 154504257
|
||||
3994172660 3019103465 300794636
|
||||
1139934681 918314562 28863941
|
||||
2712816128 2860867298 129738679
|
||||
2552921188 3494957241 7342498
|
||||
|
||||
humidity-to-location map:
|
||||
897459980 3171885613 268595078
|
||||
506368722 1864971513 13322696
|
||||
1166055058 2803961444 53745388
|
||||
2572095034 667166679 114420176
|
||||
687118932 1725187165 139784348
|
||||
2478398695 0 14138781
|
||||
3427672233 370325921 251085897
|
||||
3888215738 3612891343 82449665
|
||||
1674720770 1530101168 79955344
|
||||
3970665403 925512154 2812137
|
||||
519691418 2452425610 167427514
|
||||
3884704963 3168374838 3510775
|
||||
826903280 2381868910 70556700
|
||||
2399774019 349568762 20757159
|
||||
2972099388 3465151802 147739541
|
||||
1754676114 131614075 217954687
|
||||
2865104023 3440480691 24671111
|
||||
2206760431 932309368 77882935
|
||||
2284643366 1610056512 115130653
|
||||
2492537476 14138781 35151040
|
||||
2527688516 3695341008 44406518
|
||||
3119838929 781586855 143925299
|
||||
2732270071 2857706832 132833952
|
||||
1599442846 2728683520 75277924
|
||||
3263764228 3995626854 27783181
|
||||
0 2990540784 177834054
|
||||
2686515210 621411818 45754861
|
||||
2420531178 2670816003 57867517
|
||||
1219800446 1010192303 191374197
|
||||
3678758130 3789680021 205946833
|
||||
3973477540 3739747526 49932495
|
||||
1972630801 2014419033 234129630
|
||||
3291547409 1878294209 136124824
|
||||
2889775134 49289821 82324254
|
||||
1411174643 2619853124 50962879
|
||||
1466122599 2248548663 133320247
|
||||
177834054 1201566500 328534668
|
||||
1462137522 928324291 3985077
|
|
@ -1,12 +0,0 @@
|
|||
const INPUT: &str = include_str!("input.txt");
|
||||
|
||||
mod part_1;
|
||||
use part_1::part_1;
|
||||
mod part_2;
|
||||
use part_2::part_2;
|
||||
|
||||
fn main() -> Result<(), std::num::ParseIntError> {
|
||||
println!("{}", part_1(INPUT)?);
|
||||
println!("{}", part_2(INPUT)?);
|
||||
Ok(())
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
pub(crate) struct Mapping {
|
||||
destination_range: std::ops::RangeInclusive<i64>,
|
||||
source_range: std::ops::RangeInclusive<i64>,
|
||||
}
|
||||
|
||||
impl FromStr for Mapping {
|
||||
type Err = std::num::ParseIntError;
|
||||
|
||||
fn from_str(line: &str) -> Result<Self, Self::Err> {
|
||||
let range = line
|
||||
.split(' ')
|
||||
.map(|num| num.parse::<i64>())
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
assert_eq!(range.len(), 3);
|
||||
let destination_start = range[0];
|
||||
let source_start = range[1];
|
||||
let length = range[2];
|
||||
Ok(Mapping {
|
||||
destination_range: destination_start..=destination_start + length - 1,
|
||||
source_range: source_start..=source_start + length - 1,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn part_1(input: &'static str) -> Result<i64, <Mapping as FromStr>::Err> {
|
||||
let mut lines = input.lines();
|
||||
let lines = lines.by_ref();
|
||||
|
||||
let mut values = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.map(|line| {
|
||||
line.split(' ')
|
||||
.skip(1)
|
||||
.map(|num| num.parse().expect("Should be a valid i64"))
|
||||
})
|
||||
.flatten()
|
||||
.collect::<Vec<_>>();
|
||||
// println!("seed {:?}", values);
|
||||
// Seed to soil
|
||||
let seed_to_soil = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
for value in values.iter_mut() {
|
||||
if let Some(mapping) = seed_to_soil
|
||||
.iter()
|
||||
.find(|group| group.source_range.contains(&value))
|
||||
{
|
||||
*value += mapping.destination_range.start() - mapping.source_range.start();
|
||||
};
|
||||
}
|
||||
// println!("soil {:?}", values);
|
||||
let soil_to_fertilizer = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
for value in values.iter_mut() {
|
||||
if let Some(mapping) = soil_to_fertilizer
|
||||
.iter()
|
||||
.find(|group| group.source_range.contains(&value))
|
||||
{
|
||||
*value += mapping.destination_range.start() - mapping.source_range.start();
|
||||
};
|
||||
}
|
||||
// println!("fert {:?}", values);
|
||||
let fertilizer_to_water = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
for value in values.iter_mut() {
|
||||
if let Some(mapping) = fertilizer_to_water
|
||||
.iter()
|
||||
.find(|group| group.source_range.contains(&value))
|
||||
{
|
||||
*value += mapping.destination_range.start() - mapping.source_range.start();
|
||||
};
|
||||
}
|
||||
// println!("watr {:?}", values);
|
||||
let water_to_light = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
for value in values.iter_mut() {
|
||||
if let Some(mapping) = water_to_light
|
||||
.iter()
|
||||
.find(|group| group.source_range.contains(&value))
|
||||
{
|
||||
*value += mapping.destination_range.start() - mapping.source_range.start();
|
||||
};
|
||||
}
|
||||
// println!("lite {:?}", values);
|
||||
let light_to_temperature = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
for value in values.iter_mut() {
|
||||
if let Some(mapping) = light_to_temperature
|
||||
.iter()
|
||||
.find(|group| group.source_range.contains(&value))
|
||||
{
|
||||
*value += mapping.destination_range.start() - mapping.source_range.start();
|
||||
};
|
||||
}
|
||||
// println!("temp {:?}", values);
|
||||
let temperature_to_humidity = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
for value in values.iter_mut() {
|
||||
if let Some(mapping) = temperature_to_humidity
|
||||
.iter()
|
||||
.find(|group| group.source_range.contains(&value))
|
||||
{
|
||||
*value += mapping.destination_range.start() - mapping.source_range.start();
|
||||
};
|
||||
}
|
||||
// println!("hmdt {:?}", values);
|
||||
let humidity_to_location = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
for value in values.iter_mut() {
|
||||
if let Some(mapping) = humidity_to_location
|
||||
.iter()
|
||||
.find(|group| group.source_range.contains(&value))
|
||||
{
|
||||
*value += mapping.destination_range.start() - mapping.source_range.start();
|
||||
};
|
||||
}
|
||||
// println!("loct {:?}", values);
|
||||
Ok(*values.iter().min().unwrap())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
assert_eq!(
|
||||
super::part_1(SAMPLE_INPUT).expect("Should run on sample input"),
|
||||
35
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
assert_eq!(
|
||||
super::part_1(crate::INPUT).expect("Should run on real input"),
|
||||
621354867
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,492 +0,0 @@
|
|||
use std::{cmp::Ordering, fmt::Debug, ops::Range, str::FromStr};
|
||||
|
||||
pub(crate) struct Mapping {
|
||||
source_range: std::ops::Range<i64>,
|
||||
destination_range: std::ops::Range<i64>,
|
||||
}
|
||||
|
||||
impl Debug for Mapping {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:?} => {:?}", self.source_range, self.destination_range)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Mapping {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
write!(f, "{:?} => {:?}", self.source_range, self.destination_range)
|
||||
}
|
||||
}
|
||||
|
||||
enum Overlap {
|
||||
// MAPPING 456 -> 789 (+3)
|
||||
// RANGE 789 // < < < < // 789 // X
|
||||
// RANGE 123 // > > > > // 123 // X
|
||||
None {
|
||||
rest: Range<i64>,
|
||||
},
|
||||
// MAPPING 345 -> 789 (+4)
|
||||
// RANGE 234 // > > < > // 2 78 // X
|
||||
// RANGE 567 // < < < = // 9 67 // X
|
||||
// RANGE 456 // < < < > // 89 6 // X
|
||||
// RANGE 123 // > > = > // 12 7 // X
|
||||
// RANGE 1234 // > = < > // 12 78 // X
|
||||
// RANGE 3456 // = < < > // 789 X //
|
||||
Simple {
|
||||
contained: Range<i64>,
|
||||
rest: Range<i64>,
|
||||
},
|
||||
// MAPPING 1234 -> 5678 (+4)
|
||||
// RANGE 234 // < = < > // 678 // X
|
||||
// RANGE 123 // = > < > // 567 // X
|
||||
Contained {
|
||||
contained: Range<i64>,
|
||||
},
|
||||
// MAPPING 12345 -> 56789 (+4)
|
||||
// RANGE 234 // < > < > // 789 // X
|
||||
// RANGE 12345 // = = < > // 56789 // X
|
||||
Complete {
|
||||
contained: Range<i64>,
|
||||
},
|
||||
// MAPPING 234 -> 678 (+4)
|
||||
// RANGE 12345 // > < < > // 1 678 5 // X
|
||||
Overreaching {
|
||||
left: Range<i64>,
|
||||
contained: Range<i64>,
|
||||
right: Range<i64>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Mapping {
|
||||
const fn diff(&self) -> i64 {
|
||||
self.destination_range.start - self.source_range.start
|
||||
}
|
||||
fn apply(&self, range: &Range<i64>) -> Overlap {
|
||||
let result = match (
|
||||
i64::cmp(&self.source_range.start, &range.start),
|
||||
i64::cmp(&self.source_range.end, &range.end),
|
||||
i64::cmp(&self.source_range.start, &range.end),
|
||||
i64::cmp(&self.source_range.end, &range.start),
|
||||
) {
|
||||
(Ordering::Equal, Ordering::Less, Ordering::Less, Ordering::Greater) => {
|
||||
Overlap::Simple {
|
||||
contained: self.destination_range.clone(),
|
||||
rest: self.source_range.end + 1..range.end,
|
||||
}
|
||||
}
|
||||
(Ordering::Greater, Ordering::Equal, Ordering::Less, Ordering::Greater) => {
|
||||
Overlap::Simple {
|
||||
contained: self.destination_range.start..range.end + self.diff(),
|
||||
rest: range.start..self.source_range.start - 1,
|
||||
}
|
||||
}
|
||||
(Ordering::Greater, Ordering::Less, Ordering::Less, Ordering::Greater) => {
|
||||
Overlap::Overreaching {
|
||||
left: range.start..self.source_range.start - 1,
|
||||
contained: self.destination_range.clone(),
|
||||
right: self.source_range.end + 1..range.end,
|
||||
}
|
||||
}
|
||||
(Ordering::Less, Ordering::Greater, Ordering::Less, Ordering::Greater) => {
|
||||
Overlap::Complete {
|
||||
contained: range.start + self.diff()..range.end + self.diff(),
|
||||
}
|
||||
}
|
||||
(Ordering::Equal, Ordering::Equal, Ordering::Less, Ordering::Greater) => {
|
||||
Overlap::Complete {
|
||||
contained: self.destination_range.clone(),
|
||||
}
|
||||
}
|
||||
(Ordering::Greater, Ordering::Greater, Ordering::Greater, Ordering::Greater)
|
||||
| (Ordering::Less, Ordering::Less, Ordering::Less, Ordering::Less) => Overlap::None {
|
||||
rest: range.clone(),
|
||||
},
|
||||
(Ordering::Less, Ordering::Equal, Ordering::Less, Ordering::Greater)
|
||||
| (Ordering::Equal, Ordering::Greater, Ordering::Less, Ordering::Greater) => {
|
||||
Overlap::Contained {
|
||||
contained: range.start + self.diff()..range.end + self.diff(),
|
||||
}
|
||||
}
|
||||
(Ordering::Greater, Ordering::Greater, Ordering::Less, Ordering::Greater) => {
|
||||
Overlap::Simple {
|
||||
rest: range.start..self.source_range.start - 1,
|
||||
contained: self.destination_range.start..range.end + self.diff(),
|
||||
}
|
||||
}
|
||||
(Ordering::Less, Ordering::Less, Ordering::Less, Ordering::Greater)
|
||||
| (Ordering::Less, Ordering::Less, Ordering::Less, Ordering::Equal) => {
|
||||
Overlap::Simple {
|
||||
contained: range.start + self.diff()..self.destination_range.end,
|
||||
rest: self.source_range.end + 1..range.end,
|
||||
}
|
||||
}
|
||||
(Ordering::Greater, Ordering::Greater, Ordering::Equal, Ordering::Greater) => {
|
||||
Overlap::Simple {
|
||||
rest: range.start..self.source_range.start - 1,
|
||||
contained: self.destination_range.start..range.end + self.diff(),
|
||||
}
|
||||
}
|
||||
(a, b, c, d) => unreachable!("{:?} {:?} {:?} {:?}", a, b, c, d),
|
||||
};
|
||||
|
||||
match &result {
|
||||
Overlap::Contained { contained } => assert_eq!(
|
||||
range.end - range.start + 1,
|
||||
contained.end - contained.start + 1
|
||||
),
|
||||
Overlap::Complete { contained } => assert_eq!(
|
||||
range.end - range.start + 1,
|
||||
contained.end - contained.start + 1
|
||||
),
|
||||
Overlap::None { rest } => {
|
||||
assert_eq!(range.end - range.start + 1, rest.end - rest.start + 1)
|
||||
}
|
||||
Overlap::Simple { rest, contained } => assert_eq!(
|
||||
range.end - range.start + 1,
|
||||
(rest.end - rest.start + 1) + (contained.end - contained.start + 1),
|
||||
"{:?} ; {} ; {:?} ; {:?}",
|
||||
range,
|
||||
self,
|
||||
contained,
|
||||
rest,
|
||||
),
|
||||
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => assert_eq!(
|
||||
range.end - range.start + 1,
|
||||
(left.end - left.start + 1)
|
||||
+ (contained.end - contained.start + 1)
|
||||
+ (right.end - right.start + 1)
|
||||
),
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Mapping {
|
||||
type Err = <i64 as FromStr>::Err;
|
||||
|
||||
fn from_str(line: &str) -> Result<Self, Self::Err> {
|
||||
let range = line
|
||||
.split(' ')
|
||||
.map(|num| num.parse::<i64>())
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let destination_start = range[0];
|
||||
let source_start = range[1];
|
||||
let length = range[2];
|
||||
Ok(Mapping {
|
||||
destination_range: destination_start..destination_start + length - 1,
|
||||
source_range: source_start..source_start + length - 1,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn part_2(input: &'static str) -> Result<i64, <Mapping as FromStr>::Err> {
|
||||
let mut lines = input.lines();
|
||||
let lines = lines.by_ref();
|
||||
|
||||
let mut seed_values = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.map(|line| line.split(' ').skip(1).map(|num| num.parse::<i64>()))
|
||||
.flatten()
|
||||
.collect::<Result<Vec<_>, _>>()?
|
||||
.chunks_exact(2)
|
||||
.map(|v| [v[0], v[1]])
|
||||
.map(|[start, length]| start..(start + length - 1))
|
||||
.collect::<Vec<_>>();
|
||||
println!("seed {:?}", seed_values);
|
||||
let seed_to_soil = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
println!(" {:?}", seed_to_soil);
|
||||
let mut soil_values = vec![];
|
||||
for mapping in &seed_to_soil {
|
||||
let mut new_seeds = vec![];
|
||||
for seed in &seed_values {
|
||||
let overlap = mapping.apply(seed);
|
||||
|
||||
match overlap {
|
||||
Overlap::None { rest } => {
|
||||
new_seeds.push(rest);
|
||||
}
|
||||
Overlap::Simple { contained, rest } => {
|
||||
soil_values.push(contained);
|
||||
new_seeds.push(rest);
|
||||
}
|
||||
Overlap::Contained { contained } => soil_values.push(contained),
|
||||
Overlap::Complete { contained } => soil_values.push(contained),
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => {
|
||||
soil_values.push(contained);
|
||||
new_seeds.push(left);
|
||||
new_seeds.push(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
seed_values = new_seeds;
|
||||
}
|
||||
soil_values.extend_from_slice(&seed_values);
|
||||
|
||||
println!("soil {:?}", soil_values);
|
||||
let soil_to_fertilizer = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
println!(" {:?}", soil_to_fertilizer);
|
||||
|
||||
let mut fertilizer_values = vec![];
|
||||
for mapping in &soil_to_fertilizer {
|
||||
let mut new_soils = vec![];
|
||||
for soil in &soil_values {
|
||||
let overlap = mapping.apply(soil);
|
||||
|
||||
match overlap {
|
||||
Overlap::None { rest } => {
|
||||
new_soils.push(rest);
|
||||
}
|
||||
Overlap::Simple { contained, rest } => {
|
||||
fertilizer_values.push(contained);
|
||||
new_soils.push(rest);
|
||||
}
|
||||
Overlap::Contained { contained } => fertilizer_values.push(contained),
|
||||
Overlap::Complete { contained } => fertilizer_values.push(contained),
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => {
|
||||
fertilizer_values.push(contained);
|
||||
new_soils.push(left);
|
||||
new_soils.push(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
soil_values = new_soils;
|
||||
}
|
||||
fertilizer_values.extend_from_slice(&soil_values);
|
||||
|
||||
println!("fert {:?}", fertilizer_values);
|
||||
let fertilizer_to_water = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
println!(" {:?}", fertilizer_to_water);
|
||||
|
||||
let mut water_values = vec![];
|
||||
for mapping in &fertilizer_to_water {
|
||||
let mut new_fertilizers = vec![];
|
||||
for fertilizer in &fertilizer_values {
|
||||
let overlap = mapping.apply(fertilizer);
|
||||
|
||||
match overlap {
|
||||
Overlap::None { rest } => {
|
||||
new_fertilizers.push(rest);
|
||||
}
|
||||
Overlap::Simple { contained, rest } => {
|
||||
water_values.push(contained);
|
||||
new_fertilizers.push(rest);
|
||||
}
|
||||
Overlap::Contained { contained } => water_values.push(contained),
|
||||
Overlap::Complete { contained } => water_values.push(contained),
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => {
|
||||
water_values.push(contained);
|
||||
new_fertilizers.push(left);
|
||||
new_fertilizers.push(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
fertilizer_values = new_fertilizers;
|
||||
}
|
||||
water_values.extend_from_slice(&fertilizer_values);
|
||||
|
||||
println!("watr {:?}", water_values);
|
||||
let water_to_light = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
println!(" {:?}", water_to_light);
|
||||
|
||||
let mut light_values = vec![];
|
||||
for mapping in &water_to_light {
|
||||
let mut new_waters = vec![];
|
||||
for fertilizer in &water_values {
|
||||
let overlap = mapping.apply(fertilizer);
|
||||
|
||||
match overlap {
|
||||
Overlap::None { rest } => {
|
||||
new_waters.push(rest);
|
||||
}
|
||||
Overlap::Simple { contained, rest } => {
|
||||
light_values.push(contained);
|
||||
new_waters.push(rest);
|
||||
}
|
||||
Overlap::Contained { contained } => light_values.push(contained),
|
||||
Overlap::Complete { contained } => light_values.push(contained),
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => {
|
||||
light_values.push(contained);
|
||||
new_waters.push(left);
|
||||
new_waters.push(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
water_values = new_waters;
|
||||
}
|
||||
light_values.extend_from_slice(&water_values);
|
||||
|
||||
println!("lite {:?}", light_values);
|
||||
let light_to_temperature = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
println!(" {:?}", light_to_temperature);
|
||||
|
||||
let mut temperature_values = vec![];
|
||||
for mapping in &light_to_temperature {
|
||||
let mut new_lights = vec![];
|
||||
for light in &light_values {
|
||||
let overlap = mapping.apply(light);
|
||||
|
||||
match overlap {
|
||||
Overlap::None { rest } => {
|
||||
new_lights.push(rest);
|
||||
}
|
||||
Overlap::Simple { contained, rest } => {
|
||||
temperature_values.push(contained);
|
||||
new_lights.push(rest);
|
||||
}
|
||||
Overlap::Contained { contained } => temperature_values.push(contained),
|
||||
Overlap::Complete { contained } => temperature_values.push(contained),
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => {
|
||||
temperature_values.push(contained);
|
||||
new_lights.push(left);
|
||||
new_lights.push(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
light_values = new_lights;
|
||||
}
|
||||
temperature_values.extend_from_slice(&light_values);
|
||||
|
||||
println!("temp {:?}", temperature_values);
|
||||
let temperature_to_humidity = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
println!(" {:?}", temperature_to_humidity);
|
||||
|
||||
let mut humidity_values = vec![];
|
||||
for mapping in &temperature_to_humidity {
|
||||
let mut new_temperatures = vec![];
|
||||
for temperature in &temperature_values {
|
||||
let overlap = mapping.apply(temperature);
|
||||
|
||||
match overlap {
|
||||
Overlap::None { rest } => {
|
||||
new_temperatures.push(rest);
|
||||
}
|
||||
Overlap::Simple { contained, rest } => {
|
||||
humidity_values.push(contained);
|
||||
new_temperatures.push(rest);
|
||||
}
|
||||
Overlap::Contained { contained } => humidity_values.push(contained),
|
||||
Overlap::Complete { contained } => humidity_values.push(contained),
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => {
|
||||
humidity_values.push(contained);
|
||||
new_temperatures.push(left);
|
||||
new_temperatures.push(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
temperature_values = new_temperatures;
|
||||
}
|
||||
humidity_values.extend_from_slice(&light_values);
|
||||
|
||||
println!("hmdt {:?}", humidity_values);
|
||||
let humidity_to_location = lines
|
||||
.take_while(|line| !line.is_empty())
|
||||
.skip(1)
|
||||
.map(Mapping::from_str)
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
println!(" {:?}", humidity_to_location);
|
||||
|
||||
let mut location_values = vec![];
|
||||
for mapping in &humidity_to_location {
|
||||
let mut new_humidities = vec![];
|
||||
for humidity in &humidity_values {
|
||||
let overlap = mapping.apply(humidity);
|
||||
|
||||
match overlap {
|
||||
Overlap::None { rest } => {
|
||||
new_humidities.push(rest);
|
||||
}
|
||||
Overlap::Simple { contained, rest } => {
|
||||
location_values.push(contained);
|
||||
new_humidities.push(rest);
|
||||
}
|
||||
Overlap::Contained { contained } => location_values.push(contained),
|
||||
Overlap::Complete { contained } => location_values.push(contained),
|
||||
Overlap::Overreaching {
|
||||
left,
|
||||
contained,
|
||||
right,
|
||||
} => {
|
||||
location_values.push(contained);
|
||||
new_humidities.push(left);
|
||||
new_humidities.push(right);
|
||||
}
|
||||
}
|
||||
}
|
||||
humidity_values = new_humidities;
|
||||
}
|
||||
location_values.extend_from_slice(&humidity_values);
|
||||
println!("loct {:?}", location_values);
|
||||
|
||||
Ok(location_values.iter().map(|v| v.start).min().unwrap())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
|
||||
|
||||
#[test]
|
||||
fn test_with_sample_solution() {
|
||||
let solution = super::part_2(SAMPLE_INPUT).expect("Should run on sample input");
|
||||
assert_eq!(solution, 46)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_with_solution() {
|
||||
let solution = super::part_2(crate::INPUT).expect("Should run on real input");
|
||||
|
||||
assert_eq!(solution, 15880236);
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
seeds: 79 14 55 13
|
||||
|
||||
seed-to-soil map:
|
||||
50 98 2
|
||||
52 50 48
|
||||
|
||||
soil-to-fertilizer map:
|
||||
0 15 37
|
||||
37 52 2
|
||||
39 0 15
|
||||
|
||||
fertilizer-to-water map:
|
||||
49 53 8
|
||||
0 11 42
|
||||
42 0 7
|
||||
57 7 4
|
||||
|
||||
water-to-light map:
|
||||
88 18 7
|
||||
18 25 70
|
||||
|
||||
light-to-temperature map:
|
||||
45 77 23
|
||||
81 45 19
|
||||
68 64 13
|
||||
|
||||
temperature-to-humidity map:
|
||||
0 69 1
|
||||
1 0 69
|
||||
|
||||
humidity-to-location map:
|
||||
60 56 37
|
||||
56 93 4
|
Loading…
Reference in a new issue