Compare commits

...

No commits in common. "2022" and "main" have entirely different histories.
2022 ... main

122 changed files with 151771 additions and 14145 deletions

3
.gitignore vendored
View file

@ -1 +1,2 @@
*.exe
node_modules/
yarn-*.cjs

View file

@ -4,9 +4,5 @@
"path": "."
}
],
"settings": {
"files.associations": {
"aoc.h": "c"
}
}
"settings": {}
}

1
Python/day1/input Normal file

File diff suppressed because one or more lines are too long

132
Python/day1/solution.ipynb Normal file
View 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

File diff suppressed because it is too large Load diff

104
Python/day2/solution.ipynb Normal file
View 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

File diff suppressed because one or more lines are too long

123
Python/day3/solution.ipynb Normal file
View 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
View file

@ -0,0 +1 @@
yzbqklnj

112
Python/day4/solution.ipynb Normal file
View 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

File diff suppressed because it is too large Load diff

119
Python/day5/solution.ipynb Normal file
View 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
View 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
View 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
}

View 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
View 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
View 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

View 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"
}

View 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);

View 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);

View 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
View 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
View 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
View 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"

View 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"
}

View 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);

View 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);

View 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
View 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==

File diff suppressed because one or more lines are too long

View 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"

View 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"
}

View 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);

View 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);

View 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. */
}
}

View 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==

View file

@ -1,25 +0,0 @@
clang day01/*.c -o day01.exe -Og -g -Wall -Werror -std=c18
clang day02/*.c -o day02.exe -Og -g -Wall -Werror -std=c18
clang day03/*.c -o day03.exe -Og -g -Wall -Werror -std=c18
clang day04/*.c -o day04.exe -Og -g -Wall -Werror -std=c18
clang day05/*.c -o day05.exe -Og -g -Wall -Werror -std=c18
clang day06/*.c -o day06.exe -Og -g -Wall -Werror -std=c18
clang day07/*.c -o day07.exe -Og -g -Wall -Werror -std=c18
clang day08/*.c -o day08.exe -Og -g -Wall -Werror -std=c18
clang day09/*.c -o day09.exe -Og -g -Wall -Werror -std=c18
clang day10/*.c -o day10.exe -Og -g -Wall -Werror -std=c18
clang day11/*.c -o day11.exe -Og -g -Wall -Werror -std=c18
clang day12/*.c -o day12.exe -Og -g -Wall -Werror -std=c18
clang day13/*.c -o day13.exe -Og -g -Wall -Werror -std=c18
clang day14/*.c -o day14.exe -Og -g -Wall -Werror -std=c18
clang day15/*.c -o day15.exe -Og -g -Wall -Werror -std=c18
clang day16/*.c -o day16.exe -Og -g -Wall -Werror -std=c18
clang day17/*.c -o day17.exe -Og -g -Wall -Werror -std=c18
clang day18/*.c -o day18.exe -Og -g -Wall -Werror -std=c18
clang day19/*.c -o day19.exe -Og -g -Wall -Werror -std=c18
clang day20/*.c -o day20.exe -Og -g -Wall -Werror -std=c18
clang day21/*.c -o day21.exe -Og -g -Wall -Werror -std=c18
clang day22/*.c -o day22.exe -Og -g -Wall -Werror -std=c18
clang day23/*.c -o day23.exe -Og -g -Wall -Werror -std=c18
clang day24/*.c -o day24.exe -Og -g -Wall -Werror -std=c18
clang day25/*.c -o day25.exe -Og -g -Wall -Werror -std=c18

View file

@ -1,52 +0,0 @@
project('adventofcode', 'c')
subdir('template')
# day01
# subdir('day01')
# day02
# subdir('day02')
# day03
# subdir('day03')
# day04
# subdir('day04')
# day05
# subdir('day05')
# day06
# subdir('day06')
# day07
# subdir('day07')
# day08
# subdir('day08')
# day09
# subdir('day09')
# day10
# subdir('day10')
# day11
# subdir('day11')
# day12
# subdir('day12')
# day13
# subdir('day13')
# day14
# subdir('day14')
# day15
# subdir('day15')
# day16
# subdir('day16')
# day17
# subdir('day17')
# day18
# subdir('day18')
# day19
# subdir('day19')
# day20
# subdir('day20')
# day21
# subdir('day21')
# day22
# subdir('day22')
# day23
# subdir('day23')
# day24
# subdir('day24')
# day25
# subdir('day25')

View file

@ -1,4 +0,0 @@
#pragma once
int main(void);
void part_1(char const *const input);
void part_2(char const *const input);

View file

@ -1,16 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aoc.h"
#define DAY 0
#define INPUT_LENGTH 0
int main(void)
{
char const *const input = "";
part_1(input);
part_2(input);
return 0;
}

View file

@ -1 +0,0 @@
executable('day00', ['aoc.h', 'main.c', 'part1.c', 'part2.c'])

View file

@ -1,6 +0,0 @@
#include "aoc.h"
void part_1(char const *const input)
{
return;
}

View file

@ -1,6 +0,0 @@
#include "aoc.h"
void part_2(char const *const input)
{
return;
}

1
rust/.gitignore vendored
View file

@ -1 +0,0 @@
/target

7
rust/Cargo.lock generated
View file

@ -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 = "22.14.2"

View file

@ -1,80 +0,0 @@
[package]
name = "advent-of-code"
version = "22.14.2"
edition = "2021"
resolver = "2"
[profile.release]
strip = "symbols"
lto = "fat"
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.dev.build-override]
opt-level = 3
codegen-units = 1
[profile.release.build-override]
opt-level = 3
codegen-units = 1
[[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"
[[bin]]
name = "day06"
path = "src/day06/main.rs"
[[bin]]
name = "day07"
path = "src/day07/main.rs"
[[bin]]
name = "day08"
path = "src/day08/main.rs"
[[bin]]
name = "day09"
path = "src/day09/main.rs"
[[bin]]
name = "day10"
path = "src/day10/main.rs"
[[bin]]
name = "day11"
path = "src/day11/main.rs"
[[bin]]
name = "day12"
path = "src/day12/main.rs"
[[bin]]
name = "day14"
path = "src/day14/main.rs"
[dependencies]
# Required for one of the day06 solutions (commented out)
# phf = { version = "0.11.1", features = ["macros"] }

View file

@ -1 +0,0 @@
Placeholder input

View file

@ -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;
pub fn main() {
part_1(INPUT);
part_2(INPUT);
}

View file

@ -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_solution() {
assert_eq!(
super::part_1(crate::INPUT),
todo!("Add result for solved part 1")
);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(
super::part_1(SAMPLE_INPUT),
todo!("Add result from example part 1")
);
}
}

View file

@ -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_solution() {
assert_eq!(
super::part_2(crate::INPUT),
todo!("Add result for solved part 2")
);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(
super::part_2(SAMPLE_INPUT),
todo!("Add result from example part 2")
);
}
}

File diff suppressed because it is too large Load diff

View file

@ -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;
pub fn main() {
part_1(INPUT);
part_2(INPUT);
}

View file

@ -1,33 +0,0 @@
pub(crate) fn part_1(input: &str) -> u32 {
let maximum = input
.replace("\r\n", "\n")
.split("\n\n")
.map(|inventory| {
inventory
.lines()
.map(|item| {
item.parse::<u32>()
.expect("Input isn't clean. Non-number found")
})
.sum::<u32>()
})
.max()
.expect("No highest inventory found. Input unclean?");
println!("Part 1: {maximum}");
maximum
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_1(&crate::INPUT.replace("\r\n", "\n")), 69528);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_1(&SAMPLE_INPUT.replace("\r\n", "\n")), 24000);
}
}

View file

@ -1,35 +0,0 @@
pub(crate) fn part_2(input: &str) -> u32 {
let mut calories = input
.replace("\r\n", "\n")
.split("\n\n")
.map(|inventory| {
inventory
.lines()
.map(|item| {
item.parse::<u32>()
.expect("Input isn't clean. Non-number found")
})
.sum::<u32>()
})
.collect::<Vec<_>>();
calories.sort();
calories.reverse();
let top_three = calories.iter().take(3).sum::<u32>();
println!("Part 2: {top_three}");
top_three
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_2(&crate::INPUT.replace("\r\n", "\n")), 206152);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_2(&SAMPLE_INPUT.replace("\r\n", "\n")), 45000);
}
}

View file

@ -1,14 +0,0 @@
1000
2000
3000
4000
5000
6000
7000
8000
9000
10000

File diff suppressed because it is too large Load diff

View file

@ -1,129 +0,0 @@
const INPUT: &str = include_str!("input.txt");
mod part_1;
use std::str::FromStr;
use part_1::part_1;
mod part_2;
use part_2::part_2;
#[derive(Clone, Copy)]
pub(crate) enum Shape {
Rock,
Paper,
Scissors,
}
#[derive(Clone, Copy)]
pub(crate) enum GameResult {
Win,
Tie,
Loss,
}
impl Shape {
fn play_against(&self, other: &Shape) -> GameResult {
match self {
Shape::Rock => match other {
Shape::Rock => GameResult::Tie,
Shape::Paper => GameResult::Loss,
Shape::Scissors => GameResult::Win,
},
Shape::Paper => match other {
Shape::Rock => GameResult::Win,
Shape::Paper => GameResult::Tie,
Shape::Scissors => GameResult::Loss,
},
Shape::Scissors => match other {
Shape::Rock => GameResult::Loss,
Shape::Paper => GameResult::Win,
Shape::Scissors => GameResult::Tie,
},
}
}
fn get_response_for_result(&self, result: &GameResult) -> Self {
match self {
Shape::Rock => match result {
GameResult::Tie => Shape::Rock,
GameResult::Loss => Shape::Scissors,
GameResult::Win => Shape::Paper,
},
Shape::Paper => match result {
GameResult::Win => Shape::Scissors,
GameResult::Tie => Shape::Paper,
GameResult::Loss => Shape::Rock,
},
Shape::Scissors => match result {
GameResult::Loss => Shape::Paper,
GameResult::Win => Shape::Rock,
GameResult::Tie => Shape::Scissors,
},
}
}
}
impl From<&Shape> for u64 {
fn from(shape: &Shape) -> Self {
match shape {
Shape::Rock => 1,
Shape::Paper => 2,
Shape::Scissors => 3,
}
}
}
impl From<&GameResult> for u64 {
fn from(game_result: &GameResult) -> Self {
match game_result {
GameResult::Win => 6,
GameResult::Tie => 3,
GameResult::Loss => 0,
}
}
}
#[derive(Debug)]
pub(crate) struct ParseShapeError;
impl FromStr for Shape {
type Err = ParseShapeError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
assert_eq!(s.len(), 1);
let Some(character) = s.bytes().next() else {
return Err(ParseShapeError);
};
match character {
b'A' | b'X' => Ok(Shape::Rock),
b'B' | b'Y' => Ok(Shape::Paper),
b'C' | b'Z' => Ok(Shape::Scissors),
_ => Err(ParseShapeError),
}
}
}
#[derive(Debug)]
pub(crate) struct ParseGameResultError;
impl FromStr for GameResult {
type Err = ParseGameResultError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
assert_eq!(s.len(), 1);
let Some(character) = s.bytes().next() else {
return Err(ParseGameResultError);
};
match character {
b'X' => Ok(GameResult::Loss),
b'Y' => Ok(GameResult::Tie),
b'Z' => Ok(GameResult::Win),
_ => Err(ParseGameResultError),
}
}
}
pub fn main() {
part_1(INPUT);
part_2(INPUT);
}

View file

@ -1,42 +0,0 @@
use std::str::FromStr;
use crate::Shape;
pub(crate) fn part_1(input: &'static str) -> u64 {
let parsed_input = parse_input(input);
let final_score = parsed_input.iter().fold(0u64, |acc, [enemy, mine]| {
acc + u64::from(&mine.play_against(enemy)) + u64::from(mine)
});
println!("Part 1: {final_score}");
final_score
}
pub(crate) fn parse_input(input: &'static str) -> Vec<[Shape; 2]> {
input
.lines()
.map(|round_string| {
let round = round_string
.split(' ')
.map(|play| {
assert_eq!(play.len(), 1, "play: {play}");
Shape::from_str(play).unwrap_or_else(|_| panic!("Found invalid play {play}"))
})
.take(2)
.collect::<Vec<_>>();
[round[0], round[1]]
})
.collect::<Vec<_>>()
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_1(crate::INPUT), 13221);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_1(SAMPLE_INPUT), 15);
}
}

View file

@ -1,48 +0,0 @@
use std::str::FromStr;
use crate::{GameResult, Shape};
pub(crate) fn part_2(input: &'static str) -> u64 {
let input = parse_input(input);
let final_score = input
.iter()
.fold(0u64, |acc, (enemy_play, desired_result)| {
acc + u64::from(&enemy_play.get_response_for_result(desired_result))
+ u64::from(desired_result)
});
println!("Part 2: {final_score}");
final_score
}
fn parse_input(input: &'static str) -> Vec<(Shape, GameResult)> {
input
.lines()
.map(|round_string| {
let round = round_string.split(' ').take(2).collect::<Vec<_>>();
assert_eq!(round.len(), 2);
assert_eq!(round[0].len(), 1);
assert_eq!(round[1].len(), 1);
let enemy_shape = Shape::from_str(round[0])
.unwrap_or_else(|_| panic!("Found invalid play {}", round[0]));
let desired_result = GameResult::from_str(round[1])
.unwrap_or_else(|_| panic!("Found invalid desired result {}", round[1]));
(enemy_shape, desired_result)
})
.collect::<Vec<_>>()
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_2(crate::INPUT), 13131);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_2(SAMPLE_INPUT), 12);
}
}

View file

@ -1,3 +0,0 @@
A Y
B X
C Z

View file

@ -1,300 +0,0 @@
NJvhJcQWTJWTNTFFMTqqGqfTmB
VwVzPldRZVLVRmfsvfjvqfmm
ZDPDHZHVcvDhbvnv
FHHwHBzzVCWWmmCzCPrVmgBwbLTtRFFbbbttRGRLjTcLpbbT
vhZZvdsNSdSMdNvjncppCLcLnGnj
CDZZsNZMZqdNSdlNZCqrzPHDzgrgzwVVWwmwwm
ndlndntsFJntFvccLjjLrjBShcBBfc
GpCGHzVwmmzqQWSSSfWHBhQL
mpCMGGCZVzVwGGVwmJsZnFtZnTSTJtdsvl
nCnPDGmDNmVCsVQDmGSWqvzchWSjjcWGqS
gTnBRLpfTRnrTdZgdLfRdrThvqcvWWhFFWvcFSSgjqqzjv
pfZfTMwrbLTTfsbmQtlVtHHnbs
wNdSdsbTvTZMTvTv
rrdRWdWQhFVdHWBGWQmmmnnMvCfmnhvmCmtZ
rJrVDRWpGddpbSlNSlspPP
chTNrthMMwWMTjfsmRzZszJpwm
BLnFFCngbcBnbbldDlpRjGpmsCzGsGsRGmmG
dqvnvlgbqtcPPMhH
QcLNqZbCzJDQBJJRpwzRpdnRldgnpf
GmmmvVGsHrWffrlwdCWd
CMsFVVFjCmFStGQbbLZNBbJBcTjc
LQVggbQvcLbQLHgvVLhWGGsChssrMWfzGccc
qDnRTTRqJttPfWMChJhGslWlzh
qRTRwPBTBtRZdnjnqqqnQVbjbNLFbbfLgVmgHLQm
cZbzwCwZPlJcMLrNSNfHWNBBNZ
vsQsDCqtsDhmtjVrBNWNjBHrhr
TtDTGnvTlgbbRCGg
BgBlplHlsgNNsJlVpBtPwJhMPRRQSSttRtSP
bvhTnmdFTzddStwStQRddt
ZnZDLvnvqZzbbhFzzmTbnFsVjVlNgsCCNVsVLpNWVgsB
TdptqrrcVGhhzFtw
DRnSfwJlDmmDDVGv
RCSQNSCQZndwbcMqQrBB
wvRlrlwVwwqzgbZRdCJBWfmdzCWfBdhf
cFcsQpNtLLsGTtNGpMdPmDdPBmmBvJPWvDtC
TpjssTFFvLLLcFFQpwbwwHngjHRrZRqZVH
mqqddrPPcPmqPDlrQnjTrbvMvbHzzsjjpTvz
gtBWgGgVhLGWHzMDztzstDHj
hfWRhBBNBGgLNQDPwdNPcPdw
LhQzdhhbTzpMhddhhhTzhnZcBFllHZFtrrHZHMHFjlHr
mwwssqDvjptrvplr
NCSgVDPDwmDgVJVpLfTznQJdhfLhnhQQ
GzjzDhjhhZzcrRgQCBjBPBBjQCgT
vHHHmntsbSgLwbsSmNHbwNbvpqPCBVppCpFTpTPTBtqWBCqV
NJbwNSwdndvmvwhGhgzcfMcDJfgJ
GncgDvvcMGnttjDvrgRRFSZZLZFWdJFJwGQwZBWZ
bPqpChPfsshfZZBdZdLTFZ
lNqqsClmbsNlPbHqPsmblmsrHdvdMngcVrjggvrvggRDcn
bDvtgVVVpMQvjQWmQL
rwTflmlfZJBBdQWQWjQqdM
HsJJmZZwscHrwTrcRbzpcbPgtCSbgz
CsCsRvshMjpbqCqf
ncblgDBgtDmmmTlBgwlgbHHqMFHLqPDMHPHHpqWfFM
TcBctSmTZTtSTzsZvsvJZRsGVb
znznvngttwltzlLwhtThHbqHPvNbNHSSHmmNWHjP
FBcLrRMFQpPqpPSpqHHW
fRQMJZJfrcMcMVrQJJftnwCzVCltgTnstTVnVL
MfLlRfCMrLzRlQgwNqQFcsGd
jtTjjBTvbdqcGjqFcj
vvShDSBDppzhCmzq
plWMptTvfrnncvcRfwqzqLGhzhzThNzNNJqD
jSdSHFPQQbdPCQCssjSbBmhJGNZZNGNqqJNBlJqqLh
VCCCVCQgjdddjCgljCjbbwgRRttgrpftfWrgvpwpnf
MWlbBcPjjvvjPWWMPqgRQZfJZDGGbRZJffQQwh
HrHrnncHpzrJQJfVDQVR
zzsSTtSTLzsspSdtTmHHmpmtFgqcgPlgFqWBqqqBMdWWvFlg
nSqBbJbqlnBBClVZcMgZVgcP
FQwrwHrRwWWFBRPNgNgcCGZZZC
rWFWFTwpwwWzHrnDbfJDLDbBBbbz
BMmNtLMMtFCNFNMvvLmcndpgcdgppPrgrGPPrgJD
WVWWhbTtVnGpjrrPhr
HWssSTHWfRHRsQQFLvfvFFCLCNMNlt
sTmDsQffVrrLCjTFltTFWL
BnwwQBJbJndMMRzMwCLlWlLWWCWLLtRlWF
cqqBMcMqwnznMGzcvDmQhrvssHmPDVssrP
pQGQGJDDrDVJbbfVzvvgPcCZwhZhncscZWWc
SqMMlBBljMmRlchhPTqThCZnPs
FMjMBmjRNFHQJJpHVhVDhG
tHNNdBdNtBBBMgsMpsZm
wVPzVvbwqzhrVqvjqzzsZpDsZDsZmsCPCgZgCM
bVbvLThvvbrWqHmmnJLdHdJQLn
PzTspPZpdLLDZTplPLpPDpvbfhnqNvqzfvNMzQQfNwnQ
GWRHmjmFWMMSnhbhHw
JWWcmtBrBtWBFWGJpsgTgldhLVLpJl
DwLMDzLMhvMcwvgdVqWWlCVgvlqF
TTSBBRpbStHZVgjWFldjRVlV
SnbTBdJBmnpQzMPDMcMznr
nNlMNBPPNtJQnbZhZsgSbh
czzCjcwTdvSbgQNcgNQq
VTdNdGDTzDTdlFFPtBrtLtDr
FMbbfMlzvFsmgVZmmg
SrNTHGmdSQDqLhtQhhgggs
dRDTSDPPcHRdHGDHlwJBbmwljmMcfjbW
sQgWLtqLtWhdqlpNZRpG
blTHTjlvTCJnJvRZdGGhHHGZhFGV
CCDlJclnCmbrmBMgcwcLWtcBsB
vqPWWvqwwCFvFZfZPRFRrcGQrQwsDrNcrwnbDNcQ
LVgJLSBBVtzTLzBMmTMJmLnnDNQcrsGbsQbNbrbDjs
zggVSmmhVdfqFhvHWG
WwdndGGmmmLwwwmRwWSncLRnZqZqhqZthBtqtBqZBgtdtvMH
FfHHzlQQDsFzzrNsVTfttZvTvttTqqtbqb
lQjFDNQFPjCsVCCDjGCwwSGGnccwcHppGp
mrjggcFsFMjdjZRpSZpn
NCqfLCFNbQPzPPlPzNfSRTRZdSdWWwndpqRSSd
vDvzzbPQFNCFtllLLNMBhMcDHGBGMggMmcBc
jhjlBvvnjbtDNPjtSjBDBbDNgHggrQrhghRQrqRrZcRwwqVg
pLdTMsWdLLmpMdqZZdPdVqZgHPwH
WLTCGmMLfPSlbGjlnnJD
gtbwhgHbHgqqbgQthgQLtZZCRjMcjjnRnrRNJmMRJrNhRc
bGWVTTvDvfpVFFBpvvVTdRDMJcrccCrJnMRnNnNCcc
FVWTBsdvdTzTBFWssVQtLgSQtHqqPzPbqHbw
dlzrPTSSjSrllzWhsvVmVtTRTWtf
bJMpLGcqGhNbJQttVQmmvRWWsp
qLbMwqqbGHFGzrlZrjhPHCrj
rNrrffVlqqrfLlPpltcBBTTGRzzZRPRsBTcJ
msbsmWSsMmQwjdMbWMhMhQmcRZRzGjTBGTBcBJBjCHJGcC
FwWbvdhbmrsFrfrgsN
rHjrQHdhdQrvSddcHWLssBSVVpBSWWWWWf
JNfTGtqDwVWBMBMpwM
qlltZgfJFvcRgcRjvc
CqfcwfDqwwmRnnqmRdNRBTRTRrdGdNpTvF
WVbzsZszBbrsvpdMpdQM
tJhbVZHWLLHDgnSwnSSgHB
TZCqqlTsqpZVVsZQJSBSLpLmppnJzmFz
brSgNtGjjRjRRjDddDtrRJcJJbJmmwcmBmnPcJFwFB
jgdRtMjNNjfqlMvShvSZSZ
dJTdqCwMNCgqTQllGBdlGBmmmZ
fcVfVcnbVfrwDLWVfncZBQPlBHRGljLZQjHGQl
brwnnfSFDvfzCTqFzgMJTh
njnsPBjjsrrnGLnbTTjGvcldQPCMllNzMvRQPCdd
ggZgfZtmZVpqZqZWDgFmgqfCcQRcRcWhQcccQddMcvRQdQ
tfqgggVgHpDwDtfwbGLJRjbLjsrLTj
JmrfrmTlDWTfgQCdHCdpqBvQdD
jsZtVzNsSNVQQHnBlVQR
PljljFjPljSsLPtFLTTgTcFrrfMJmrrmrr
hmGcmmndhmGnfmtGnDzFLwrFJQsQFzNFrNJG
ZSqPlSWcWlbgqWVTVWRVZPrjQqjzjFNJzLsNJsLJNqNL
RHcWTZbSMMMPgZcWgSWPPbVMDnBffmtdpDBddfnnvmCdfC
vSJvsbFfJfvqCsTHJswssJnLTZjjhzrrzLrzLMrzhdjM
pBNQDPcpmWDcBNgMMnZPVjdddnndhH
QWlDgmpmgDBlGRgDDgffSqwSwGCwHfvqwSFJ
jvlgvMJclPdGdtdcjMVmMHbFHFVHWHbZHZ
CwhLzLhzQpnqfpfqDVHCHbsbDFZDmHmj
LnBzfQjSzQrPvJvdSSrr
wpcvcsqclDCnVCVvWfnZ
BLRMRtbnbbBLNCjNCjVVZhbC
rFgMPSRnrRpmqpJwqFDs
LZQNQbMrZppLNLQplvlGLNvVmmmfjbwVCfjbwJwCmBCwfj
ShTPRFtTHZPCsnwswsFwCF
WtHRPdThSqZTRtDqtdRWTdpGDLLzrNczvzMGLlQLGDDM
hdcffBvldjhCMljqPwWwWNwWdwqHZr
LtQmbQRVsZQZMZPQSN
tmMRsJMpDhjJzJhv
wNQCMFCDQDBmrHmmRWrrHN
SShLnfqpcqpSZSfrzJvRVrvfrrJH
cRpqdGclpScltTQQtsFQMQsTCT
NCjggZmgfBgnBmgWbcwcTFctcWWfvb
HsDGthRGrtppSQpbFFJTVcJdFbTRvd
rPDGhDDrSzZLtzBLZMCB
RsBBMBsCBlFFCgRsBJzlMjMPNSdPhSrSrzLbmSDrDNmDSd
pZHZZJpGHHHpTTHvTncZqVLdqLbhLrDLdhrSLLbLDDdD
tGtwnJccvCtCffMBgt
wbddvVjfwPhbjjbDbbvbjvTNCNmfHZfpCZRJNzCmJmnJNC
BslcLtclZWsZJWNrRRNRpRmR
BSLBlScGtFMcssMBBFGLlQZTDZQjPddVwwbTdvvdhTZb
NSZHzmLZBnzHmLLzLSntDttDDtddhDtttDWW
QgfjsrrvNNJwtMddcvcvtq
jrfgfQpQrTTVLSNBClFV
GQWcWWPPQRcrJQNDdRcDmmLCFSnqNSmqhCNvFnql
zHfwjzpMjwZmCLqvvnlljC
ZgtVZBtHHZtgQGgPrbPRJdPv
TWdWpJTJTdgLWfWLlLFLrfrgBGsNqhGslBGHqSNqqBNshnws
ZpQmjzbZZCjZCCCPZtttRCCwsBnHNssBHbShsshHqsGBqN
RDRRPpPCzmZCtRpVVJFrfTfWFLLJggJrDv
pDDFlglsvFMgntlTMMqNffmTdfddRM
jhGJLVCHQpHGQCCzLjWdTTdZZdNdcRWNccWfNN
jQjSGjrjCQLhzVSLSCSHGDpngbrnDFtFBwBglBnBvg
wsLzstsgszcpcGLHGpcgcghlDBvQvjQvbFbQCbJBtCCJJv
mnSqRSSqSRThWRnmWWRSJDFTFCFCblbBCFQFCjFj
rZRRWqSSdZZfMVnZLspPsMgHpzMhHGPg
mwHrCLSWWwrsHCHDDsVrsmhfFZFnSSBlFlgZbbgBglbggj
GJdpcRtGJvNRdcPtdpJJdbQZfjfQBlnQBjnBtbfFnB
qcPpqqzFzJqvPVCCmWrVwhrWrz
jjMbvbhDvnRjNRGMmjbMZftSSwwwthJSffStctcwqd
lTQrVlpCVvCcfdcSJqLVcw
srHFWCHrFlrHlrsBsprljjRmDZZnmbDngNBgbNZv
MgTlQJlTQJZWpgLrRssrVqqqpRts
bBNbbzSSjMBPjzhMjsPtRVVRVPRqLttGGs
SjHBbfjNCDfjZgTlZdMJnDJW
lpThgTwtplhghgwhThqnnrdZctSZSjSZcRSRfbdrrc
RBVBGvmBmfdrcvrbbr
PmVGNGmmGRLLQwwLqTnglQ
nHwnBwBTnFHQwRsMhwghmzcm
GtprdCpdtqWdbqbrfdnPPszsWmRzRnShPszS
dGptbCfCrlnVDBJNLDLLVDLQ
CZtCjhTndCzqbCNq
dwpGvpsmwGslDszrNNrzqDMzWMgJ
vmcGccvpBVPTVTjTdTTTdZ
jWZhvZLjZfCZDwrDrSSzJGhVdJccscGsgV
blMBlRqqqgSJLBLcsJ
blmHLmFMMMnRqLmMMFqHmfPDfjQDnCDDQrZvfCjvDr
rnvnHrDLFZmMFLvrHQBMGQggBztzglplRl
sbWWhdNzsshsfhcsjJJPPbWdtQGVGllRTRjRRgBgQlpRlppB
PPCCwNWhPhNfWCzbqmFnDFFnCDLSrvZS
GChNjwWlWJWTJZBggvdgnQgdhdnd
HPsHfHHrpHDpFFrcSfsfpCMmQdntLBMgtmtBgDdLLC
SqpPscpPzpSWzjlCjjCGjl
nvgLvcLgvgvngbLprpJNTDCCRNVJrNPlDDTV
WZsMtsffGQtMzWFqFmWmWsVNJNlDwwCDVRTwJlCCDVLz
BQfGZGmmsMWFstWFmfMsfBccdncbpbSbvbbvHnLbpc
tsmDsvswNZmcZTccfh
zCTpGCbWBRWFWHGRFZJbMbJfnrhnhfMnnZ
TzFGFBRLdpHHNNQddDQDvwQN
fhBBpJgdHddjZQfmVmNzNNLmFN
qvMRrvlbwqlbTTMBMvLssFNmVzzwFDmLLzVD
TRSRWqRRMcBHhGHcdGgPGp
lSjHmtmnpHStblnpSlHSrtmMzLWzqzqCZDDTzTTWqMFqCqVV
sLRLLfPPRQfCTqqVVqFT
dNJgRPNQNsJJhBRvdJvQvNNsjSrrSmrcctpbpHtBrBjLjmSH
nwFwpppjfwSlpLTsqsTgNshhjM
ccBRGvtsmgGNPqNNGP
BCcJHvssdcWBCVmVHSSrZrwVzblpwbzZnf
rcfQRrBPPczjcRBctZDNlnVNHbgZGjVDjN
TvMsFJGSFMhJnNZlwVVnDNTZ
qhSqqmqLCLhFdJLqSvLhmQRQRWcRPczPtzrCrWGRBp
JVhdPhsFPFqLDBHVdHLPvhHDCMwcgJJwbwRgnnCMbwGwcmGC
fzjzpTZTQQQLwCbgGgbMmQcR
jzNpTzfSZtfNSWZlVVtdFFFDHHqLHVqv
TwSNnSnSGVTpNppGlPTlTcVqQrRhVBqdqBRqZqQZqQ
DcDCMfDbCMHJdrRBqbdjRBRZ
gvftMCJHcHfCDmDLgfMmMmmWlwWnWsTTwlGTlWTwppNlGL
pbGMbllDQPhhWWQDpPgVGlMCvRRrQLcCCcfBBQzLBcvQBv
wqnJjSmjrstdqwwFBLcRsBRRszzLFC
qwdddTJTdHtjndqJqHZHmwVWGpDbGTlbWWpWWrPGhhhM
WGllqLjjLCpSffmBmvfpHs
dnrQwZzRTdZwnCThdzzFTVmcBHBJBmsHfBPHcfvcSVHs
QgQrzCdrTRCZzrZLbjGLqNMWGgNNLt
sgPnhPPTTPTTwlJfwNHlqcfs
LMCpFbLLbRpMGbMcCFLVlNlNqrHqVfbHHwNDwr
GjBcCCtWMtMRZTSvgWQTngvg
BCMtJJMpRDlMMvBJBBnfjtcjPhPmZgnhgdcf
NrsrsqFNvrVLVGVrsHsqFgfmcPGdcmhfjdPgfjcnZd
zFTzsNqHqFssLVLQqNTFbsBDwCCwvWlDwRMRCTRBDMDS
zQtLgvggSRtgvVRtLvvnzdnjnGwGdmmrlpnlGz
JssBFpqsDqPNnlWWjrrjqrnj
DHDFBNDfPbJBsFHNMPvpvStQvMRVTtgVTVtv
FvzttFvBTJJzLbvwhCnnVnWwjCnBNC
mQdZgZPDPdPPSsMSQPdZgCwVGmnwnWpGnGhqNWjWCG
ggdDgfQSdcjtFHjlLJfF
ghcgScNNSsCvGSzmpVFlZbrzcFcV
MWWRLRqqqdQwTtLjjmqMlFpFlzVnbFVDwplFzlDr
LHMHqdHWjdQMdMtLHHLtWjJRsGCGSNghmSvPBJBNhsGfvfGP
CbVqqqDbcbMHnnDqcCbrRFCfBvvwGjzrBwQGzrwwBjGwBQ
sTPmpNWdWPTJssSSLPfNljjBvflGtjwwBzMG
mmWgmgSZLTLMZWpnhqZbhFFCnhqnnn
QQmjmZqnmQrfTZlbbcVbBcfbHfzf
vpdSNShNppFdSRtdGBqvJBDlDzqbPPHVBH
tRNSNRFhNpSRhFRMFtGhRGswLZZsZqWnmrmZwqwsTZmmmQ
gGWCllFCGWtGGWdlGlWNZdwpnnSbwpMvpphZpndn
RsshDDLcQVMSJQwJwnvw
HVPzrPcDNhPFGhPC
jtHQGHjGGtdTLjnqTQlmvRPRPBBwRBnFPPWP
hZbzNzVrczZzcbNssVspZZVvBwbmPmJPWmvbBRvPlmvRJF
fzNVDsZMhzpVhpVhlZcMNfcDDdQTLTjGDTCqGCjtSQHdHL
GrbFggGrTrzSrgfwJjdTmwmNJZJd
VMPQplPDptchwdsjmlml
MqMWtBDPPWDWHQtvqQtWPjbzCGLgSBgGbzgrzFgnnz
fcJccCcwcDfcpbRnCfWJnQJqtqtqPQdsGdgPsgTQqg
LSjVMhzSFFrljdNbltNGtgdqQq
MMhSHFFMLzBWDcHHcfcHwb
rwmWtJWMwSNRJMtwNmMrrSsmtTjjlgqnTqZZZPlHnTngTTgn
BGqGqqFBFggjjdGHlj
QDhhLbDQCDFMNcmhRhqJNW
BnRnRvMnLGLSCHvvSnlRfWbbTNQJsJsbNbJTBfQT
tzMmmMwjhcpFjDmMcptrcjzFQggfQPTsWsfgNbbgfhJbPhQT
FdzcrtDwDMtcwtFGRZdRLvdnHRSZZv
HVpsSpvjpNjsBmbGFBnMNnDM
WRRWhZtfrVtLJrBZMnDmDbnZBTGF
thhPLzWzhzwPtLRLWrQlpPvvClcVcCppSvpl
lZPbhnZLRPnnPZZPdlGMBWcBMgMQHBBcvvvzBL
jpFjmwwwCDDbsjvjjgcvQgcNBQ
rbFmppbwhqhGRGZr
ggrLwFgWCBwbMWBbFwLMgNBZdmZHclJPllnJlNRPmSNZRR
ppszzDfhDfhsqpnvDVTfGpSPlPmclHcdRcZmmmdPPGSP
pvtDDVDVpqDfzDfngBLCwQrgCtCwFwrg
pbGjFFGGDjpbsGsmNhNFNRBBBtRhhhHv
JnczJVCvwWJvhPgghgNtNtNJ
nwVSSzdzzqSpvQSZQG
mssLLttQrsMrMzLCRmMmrrSQpvWpDNlBTBDlvNTccDQl
HdHJwJqVPwHnqJwbjJbGjnSgSTWPpNgWWpgBBgcvDWWN
ZHVwVZGwwdndqJVJqfHbGwnwrRLtLMftMvMMRrhmLMthhLmz
RgHGLbTqlZlPRZPHfvvfZttJnvfvjnzr
sVcChDVDccwNhhvjTvVzWJjnzFff
mpNcCMTCGmLqBLGH
wVJwHJHVMtMpBmDDWPQVPWDGDD
zCrlZzCblBvnCDWNGLmvGDLPNG
dqZglgbzrzbbgZqzTFSBHHFJSSSfjjSMfwhj
NMWJSjLMCnHHNMNNHWCHMbVVGBPZTrPVPBVDrBSDGTTr
zvttlFpgdtldwwvftPDPTWQdBZrsrWrGBZ
hFlFmhRFvfCbmWJWHcnj

View file

@ -1,19 +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) fn character_priority(character: u8) -> u64 {
(match character {
b'a'..=b'z' => character - b'a' + 1,
b'A'..=b'Z' => character - b'A' + 27,
_ => panic!("Invalid character '{character}', no priority"),
}) as u64
}
pub fn main() {
part_1(INPUT);
part_2(INPUT);
}

View file

@ -1,52 +0,0 @@
use std::collections::HashSet;
pub(crate) fn part_1(input: &'static str) -> u64 {
let rucksacks = input.lines();
let compartments = rucksacks.map(|rucksack| {
let compartment_size = rucksack.len() / 2;
let compartments = (
rucksack
.bytes()
.take(compartment_size)
.collect::<HashSet<_>>(),
rucksack
.bytes()
.skip(compartment_size)
.take(compartment_size)
.collect::<HashSet<_>>(),
);
compartments
});
let mut running_sum = 0;
for compartments in compartments {
let same_bytes =
HashSet::intersection(&compartments.0, &compartments.1).collect::<Vec<_>>();
assert_eq!(
same_bytes.len(),
1,
"{}",
same_bytes
.iter()
.map(|byte| char::from(**byte))
.collect::<String>()
);
running_sum += crate::character_priority(*same_bytes[0]);
}
println!("Part 1: {running_sum}");
running_sum
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(crate::part_1(crate::INPUT), 7742);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(crate::part_1(SAMPLE_INPUT), 157);
}
}

View file

@ -1,39 +0,0 @@
use std::collections::HashSet;
use crate::character_priority;
pub(crate) fn part_2(input: &'static str) -> u64 {
let rucksacks = input.lines();
let compartments = rucksacks
.map(|rucksack| rucksack.bytes().collect::<HashSet<_>>())
.collect::<Vec<_>>();
assert_eq!(compartments.len() % 3, 0);
let mut running_sum = 0;
for group_compartments in compartments.chunks_exact(3) {
let group_bytes = &group_compartments[0]
.intersection(&group_compartments[1])
.copied()
.filter(|byte| group_compartments[2].contains(byte))
.collect::<Vec<_>>();
assert_eq!(group_bytes.len(), 1);
running_sum += character_priority(group_bytes[0]);
}
println!("Part 2: {running_sum}");
running_sum
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_2(crate::INPUT), 2276);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_2(SAMPLE_INPUT), 70);
}
}

View file

@ -1,6 +0,0 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw

File diff suppressed because it is too large Load diff

View file

@ -1,35 +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 parse_input(input: &'static str) -> Vec<[[u32; 2]; 2]> {
input
.lines()
.map(|line| {
let pairs = line
.split(',')
.take(2)
.map(|v| {
let boundary = v
.split('-')
.map(|v| v.parse::<u32>().expect("Non-numerical value in input"))
.take(2)
.collect::<Vec<_>>();
assert_eq!(boundary.len(), 2);
[boundary[0], boundary[1]]
})
.collect::<Vec<_>>();
assert_eq!(pairs.len(), 2);
[pairs[0], pairs[1]]
})
.collect::<Vec<_>>()
}
pub fn main() {
let input = parse_input(INPUT);
part_1(&input);
part_2(&input);
}

View file

@ -1,64 +0,0 @@
#[inline(always)]
fn sections_contain_each_other(sections: [[u32; 2]; 2]) -> bool {
let start_1 = sections[0][0];
let end_1 = sections[0][1];
let start_2 = sections[1][0];
let end_2 = sections[1][1];
(start_1 <= start_2 && end_1 >= end_2) || (start_1 >= start_2 && end_1 <= end_2)
}
pub(crate) fn part_1(input: &[[[u32; 2]; 2]]) -> usize {
let times_contained = input
.iter()
.filter(|sections| sections_contain_each_other(**sections))
.count();
println!("Part 1: {times_contained}");
times_contained
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_1(&crate::parse_input(crate::INPUT)), 584);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_1(&crate::parse_input(SAMPLE_INPUT)), 2);
}
#[test]
#[ignore = "Sanity check test"]
fn test_containment() {
for num in 0..=1024u32 {
assert!(super::sections_contain_each_other([[num, num], [num, num]]));
}
for num_a in 0..=1024u32 {
for num_b in num_a..=1024u32 {
assert!(super::sections_contain_each_other([
[num_a, num_b],
[num_b, num_b]
]));
assert!(super::sections_contain_each_other([
[num_a, num_b],
[num_a, num_b]
]));
}
}
for num_a in 0..=1024u32 {
for num_b in num_a + 1u32..=num_a + 1024u32 {
assert!(!super::sections_contain_each_other([
[num_a, num_a],
[num_b, num_b]
]));
}
}
assert!(!super::sections_contain_each_other([[1, 3], [3, 83]]));
}
}

View file

@ -1,59 +0,0 @@
#[inline(always)]
fn sections_overlap(sections: [[u32; 2]; 2]) -> bool {
let start_1 = sections[0][0];
let end_1 = sections[0][1];
let start_2 = sections[1][0];
let end_2 = sections[1][1];
(start_1 <= end_2 && end_1 >= start_2) || (start_1 >= end_2 && end_1 <= start_2)
}
pub(crate) fn part_2(input: &[[[u32; 2]; 2]]) -> usize {
let times_overlapped = input
.iter()
.filter(|sections| sections_overlap(**sections))
.count();
println!("Part 2: {times_overlapped}");
times_overlapped
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_2(&crate::parse_input(crate::INPUT)), 933);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_2(&crate::parse_input(SAMPLE_INPUT)), 4);
}
#[test]
#[ignore = "Sanity check test"]
fn test_overlap() {
for num in 0..=1024u32 {
assert!(super::sections_overlap([[num, num], [num, num]]));
}
for num_a in 0..=1024u32 {
for num_b in num_a..=1024u32 {
assert!(
super::sections_overlap([[num_a, num_b], [num_b, num_b]]),
"{:?}",
[[num_a, num_b], [num_b, num_b]]
);
assert!(super::sections_overlap([[num_a, num_b], [num_a, num_b]]));
}
}
for num_a in 0..=1024u32 {
for num_b in num_a + 1u32..=num_a + 1024u32 {
assert!(!super::sections_overlap([[num_a, num_a], [num_b, num_b]]));
}
}
assert!(super::sections_overlap([[1, 3], [3, 83]]));
}
}

View file

@ -1,6 +0,0 @@
2-4,6-8
2-3,4-5
5-7,7-9
2-8,3-7
6-6,4-6
2-6,4-8

View file

@ -1,514 +0,0 @@
[G] [D] [Q]
[P] [T] [L] [M] [Z]
[Z] [Z] [C] [Z] [G] [W]
[M] [B] [F] [P] [C] [H] [N]
[T] [S] [R] [H] [W] [R] [L] [W]
[R] [T] [Q] [Z] [R] [S] [Z] [F] [P]
[C] [N] [H] [R] [N] [H] [D] [J] [Q]
[N] [D] [M] [G] [Z] [F] [W] [S] [S]
1 2 3 4 5 6 7 8 9
move 7 from 6 to 8
move 5 from 2 to 6
move 2 from 4 to 1
move 1 from 4 to 5
move 5 from 7 to 6
move 7 from 6 to 3
move 5 from 9 to 2
move 6 from 2 to 3
move 2 from 7 to 9
move 20 from 3 to 1
move 11 from 1 to 6
move 1 from 9 to 8
move 3 from 8 to 2
move 8 from 1 to 5
move 10 from 8 to 4
move 7 from 6 to 4
move 1 from 8 to 3
move 8 from 1 to 7
move 16 from 4 to 8
move 1 from 9 to 8
move 1 from 5 to 2
move 4 from 7 to 4
move 5 from 6 to 7
move 1 from 6 to 1
move 8 from 7 to 4
move 1 from 6 to 9
move 12 from 4 to 5
move 3 from 2 to 5
move 1 from 6 to 2
move 1 from 3 to 7
move 1 from 3 to 2
move 1 from 9 to 3
move 1 from 7 to 8
move 1 from 7 to 5
move 1 from 3 to 2
move 4 from 5 to 7
move 5 from 5 to 7
move 1 from 4 to 3
move 1 from 3 to 9
move 3 from 1 to 8
move 1 from 9 to 1
move 2 from 2 to 1
move 2 from 2 to 7
move 8 from 8 to 1
move 3 from 5 to 2
move 8 from 7 to 5
move 7 from 1 to 3
move 3 from 1 to 7
move 1 from 1 to 5
move 1 from 3 to 7
move 7 from 5 to 8
move 2 from 2 to 8
move 1 from 3 to 2
move 1 from 2 to 4
move 1 from 4 to 8
move 13 from 8 to 1
move 13 from 5 to 9
move 2 from 5 to 2
move 7 from 9 to 3
move 12 from 8 to 3
move 4 from 9 to 3
move 1 from 3 to 4
move 2 from 2 to 3
move 1 from 1 to 6
move 1 from 2 to 3
move 1 from 5 to 9
move 7 from 7 to 4
move 10 from 1 to 8
move 1 from 1 to 4
move 1 from 9 to 5
move 2 from 5 to 1
move 1 from 6 to 5
move 3 from 8 to 9
move 5 from 4 to 3
move 4 from 4 to 1
move 7 from 1 to 6
move 2 from 5 to 7
move 35 from 3 to 4
move 4 from 9 to 1
move 19 from 4 to 8
move 1 from 7 to 6
move 1 from 9 to 2
move 10 from 4 to 5
move 2 from 4 to 7
move 3 from 4 to 3
move 1 from 2 to 8
move 1 from 1 to 9
move 3 from 3 to 6
move 4 from 8 to 6
move 4 from 5 to 2
move 2 from 8 to 3
move 3 from 5 to 9
move 12 from 6 to 1
move 8 from 8 to 6
move 2 from 9 to 1
move 1 from 4 to 1
move 1 from 3 to 8
move 3 from 7 to 8
move 2 from 9 to 7
move 1 from 6 to 7
move 10 from 6 to 8
move 4 from 2 to 5
move 1 from 3 to 7
move 7 from 5 to 7
move 13 from 8 to 1
move 29 from 1 to 4
move 8 from 7 to 8
move 1 from 1 to 3
move 3 from 7 to 6
move 1 from 1 to 9
move 15 from 4 to 1
move 1 from 3 to 6
move 10 from 1 to 6
move 10 from 6 to 7
move 1 from 4 to 9
move 1 from 9 to 1
move 1 from 9 to 7
move 6 from 7 to 8
move 1 from 1 to 6
move 5 from 6 to 5
move 21 from 8 to 9
move 5 from 1 to 9
move 2 from 9 to 5
move 3 from 5 to 6
move 3 from 7 to 9
move 4 from 4 to 6
move 6 from 8 to 7
move 6 from 6 to 3
move 2 from 7 to 9
move 1 from 7 to 2
move 6 from 3 to 2
move 1 from 6 to 4
move 4 from 5 to 9
move 1 from 4 to 5
move 9 from 4 to 6
move 7 from 6 to 4
move 10 from 9 to 2
move 5 from 7 to 5
move 10 from 2 to 7
move 2 from 5 to 4
move 2 from 5 to 9
move 4 from 9 to 4
move 1 from 8 to 6
move 7 from 7 to 2
move 1 from 5 to 4
move 2 from 7 to 1
move 1 from 5 to 7
move 3 from 6 to 2
move 4 from 4 to 5
move 1 from 2 to 7
move 10 from 4 to 7
move 3 from 7 to 3
move 17 from 9 to 4
move 1 from 1 to 4
move 1 from 1 to 5
move 5 from 2 to 7
move 1 from 9 to 2
move 5 from 4 to 8
move 2 from 9 to 7
move 4 from 8 to 1
move 3 from 4 to 8
move 1 from 2 to 5
move 1 from 9 to 2
move 6 from 4 to 8
move 3 from 7 to 5
move 1 from 4 to 9
move 1 from 9 to 1
move 3 from 1 to 9
move 4 from 8 to 5
move 2 from 9 to 8
move 4 from 2 to 5
move 8 from 7 to 2
move 5 from 8 to 5
move 2 from 7 to 8
move 1 from 3 to 5
move 1 from 1 to 2
move 1 from 1 to 6
move 2 from 3 to 6
move 5 from 2 to 8
move 4 from 7 to 1
move 7 from 8 to 5
move 1 from 1 to 5
move 3 from 8 to 3
move 1 from 9 to 3
move 7 from 2 to 3
move 2 from 2 to 8
move 2 from 4 to 8
move 1 from 8 to 5
move 1 from 1 to 4
move 2 from 4 to 7
move 2 from 7 to 1
move 3 from 2 to 3
move 3 from 5 to 2
move 1 from 8 to 3
move 3 from 3 to 2
move 5 from 2 to 1
move 17 from 5 to 8
move 9 from 8 to 1
move 11 from 3 to 5
move 8 from 8 to 5
move 2 from 8 to 5
move 16 from 1 to 4
move 13 from 4 to 7
move 6 from 5 to 2
move 2 from 4 to 8
move 5 from 7 to 9
move 2 from 1 to 2
move 7 from 7 to 1
move 1 from 1 to 4
move 1 from 9 to 8
move 7 from 2 to 8
move 1 from 4 to 7
move 2 from 9 to 4
move 1 from 4 to 1
move 1 from 3 to 5
move 2 from 9 to 8
move 11 from 8 to 7
move 2 from 6 to 5
move 1 from 6 to 9
move 1 from 1 to 9
move 1 from 9 to 1
move 4 from 1 to 4
move 2 from 1 to 8
move 1 from 1 to 2
move 1 from 9 to 5
move 2 from 4 to 3
move 2 from 2 to 7
move 2 from 3 to 9
move 1 from 9 to 1
move 1 from 9 to 1
move 5 from 5 to 1
move 19 from 5 to 6
move 5 from 1 to 4
move 1 from 2 to 9
move 1 from 1 to 3
move 7 from 5 to 8
move 1 from 3 to 6
move 8 from 7 to 3
move 7 from 4 to 8
move 3 from 8 to 5
move 1 from 4 to 1
move 1 from 9 to 4
move 1 from 4 to 9
move 1 from 5 to 2
move 2 from 5 to 6
move 2 from 8 to 2
move 7 from 8 to 1
move 1 from 1 to 7
move 3 from 6 to 9
move 2 from 3 to 2
move 1 from 2 to 1
move 1 from 8 to 7
move 2 from 9 to 6
move 2 from 9 to 5
move 1 from 5 to 6
move 1 from 2 to 8
move 2 from 1 to 7
move 1 from 4 to 3
move 3 from 2 to 5
move 7 from 1 to 3
move 10 from 3 to 4
move 3 from 5 to 4
move 1 from 3 to 8
move 3 from 3 to 2
move 1 from 8 to 1
move 1 from 1 to 3
move 3 from 8 to 3
move 5 from 4 to 6
move 1 from 2 to 3
move 4 from 6 to 4
move 1 from 5 to 7
move 4 from 3 to 4
move 1 from 2 to 8
move 12 from 7 to 6
move 1 from 8 to 2
move 2 from 2 to 7
move 1 from 8 to 4
move 23 from 6 to 3
move 14 from 3 to 6
move 15 from 4 to 6
move 1 from 8 to 6
move 10 from 3 to 7
move 2 from 4 to 2
move 11 from 7 to 8
move 2 from 2 to 6
move 44 from 6 to 9
move 21 from 9 to 3
move 12 from 3 to 6
move 1 from 7 to 4
move 1 from 4 to 7
move 9 from 3 to 2
move 2 from 8 to 6
move 3 from 2 to 4
move 17 from 9 to 1
move 3 from 4 to 6
move 2 from 2 to 9
move 4 from 9 to 2
move 10 from 6 to 9
move 1 from 7 to 6
move 4 from 9 to 5
move 4 from 2 to 4
move 14 from 1 to 5
move 4 from 4 to 3
move 3 from 2 to 9
move 9 from 9 to 7
move 1 from 2 to 5
move 9 from 8 to 5
move 8 from 7 to 2
move 4 from 3 to 8
move 5 from 6 to 2
move 3 from 1 to 6
move 1 from 7 to 1
move 4 from 2 to 4
move 3 from 6 to 4
move 3 from 8 to 3
move 13 from 5 to 2
move 2 from 3 to 5
move 12 from 5 to 9
move 1 from 3 to 5
move 1 from 5 to 9
move 1 from 8 to 3
move 4 from 9 to 5
move 6 from 4 to 5
move 12 from 9 to 7
move 1 from 9 to 3
move 1 from 3 to 2
move 12 from 5 to 6
move 12 from 7 to 2
move 1 from 3 to 7
move 1 from 4 to 8
move 33 from 2 to 8
move 1 from 7 to 5
move 1 from 1 to 2
move 4 from 5 to 4
move 3 from 2 to 5
move 34 from 8 to 6
move 1 from 4 to 3
move 1 from 5 to 7
move 1 from 7 to 5
move 3 from 4 to 9
move 2 from 9 to 7
move 1 from 9 to 4
move 1 from 3 to 7
move 1 from 5 to 8
move 1 from 5 to 1
move 1 from 5 to 7
move 1 from 4 to 8
move 1 from 1 to 4
move 1 from 4 to 2
move 3 from 7 to 5
move 2 from 8 to 5
move 1 from 2 to 8
move 4 from 6 to 2
move 1 from 8 to 6
move 1 from 7 to 9
move 29 from 6 to 7
move 4 from 2 to 3
move 2 from 5 to 8
move 1 from 9 to 5
move 2 from 8 to 1
move 23 from 7 to 5
move 2 from 6 to 1
move 23 from 5 to 6
move 1 from 3 to 6
move 4 from 5 to 9
move 2 from 1 to 3
move 5 from 3 to 8
move 2 from 6 to 5
move 2 from 1 to 4
move 1 from 9 to 8
move 1 from 9 to 1
move 1 from 4 to 6
move 2 from 5 to 6
move 6 from 7 to 8
move 2 from 9 to 2
move 18 from 6 to 5
move 21 from 6 to 4
move 1 from 1 to 6
move 2 from 6 to 7
move 2 from 7 to 9
move 2 from 2 to 8
move 7 from 4 to 3
move 12 from 5 to 3
move 1 from 9 to 5
move 1 from 9 to 4
move 6 from 5 to 2
move 17 from 3 to 4
move 3 from 4 to 3
move 1 from 2 to 4
move 5 from 2 to 8
move 1 from 5 to 8
move 19 from 8 to 7
move 1 from 3 to 6
move 1 from 8 to 4
move 1 from 6 to 1
move 15 from 4 to 6
move 1 from 1 to 4
move 3 from 3 to 5
move 4 from 6 to 7
move 1 from 4 to 7
move 10 from 6 to 7
move 16 from 4 to 5
move 24 from 7 to 2
move 8 from 7 to 8
move 1 from 4 to 2
move 6 from 8 to 7
move 1 from 8 to 7
move 1 from 6 to 9
move 14 from 5 to 4
move 9 from 7 to 8
move 4 from 5 to 1
move 2 from 1 to 5
move 3 from 8 to 6
move 2 from 6 to 9
move 2 from 2 to 8
move 6 from 2 to 7
move 3 from 4 to 6
move 1 from 3 to 4
move 3 from 5 to 7
move 1 from 6 to 9
move 5 from 7 to 2
move 4 from 9 to 1
move 1 from 7 to 9
move 9 from 8 to 4
move 5 from 1 to 2
move 2 from 6 to 1
move 6 from 4 to 7
move 1 from 7 to 3
move 1 from 3 to 9
move 1 from 9 to 7
move 1 from 6 to 7
move 9 from 4 to 5
move 7 from 7 to 9
move 3 from 7 to 5
move 1 from 9 to 2
move 6 from 9 to 8
move 4 from 4 to 5
move 1 from 4 to 2
move 1 from 4 to 2
move 2 from 1 to 2
move 1 from 9 to 8
move 10 from 2 to 4
move 8 from 2 to 7
move 12 from 2 to 9
move 6 from 7 to 4
move 1 from 1 to 2
move 8 from 9 to 8
move 7 from 5 to 1
move 9 from 4 to 3
move 14 from 8 to 4
move 1 from 8 to 4
move 1 from 1 to 5
move 1 from 5 to 2
move 3 from 2 to 4
move 1 from 7 to 1
move 1 from 7 to 3
move 2 from 1 to 7
move 3 from 5 to 7
move 2 from 7 to 6
move 1 from 6 to 5
move 3 from 7 to 1
move 1 from 6 to 8
move 1 from 8 to 7
move 1 from 3 to 6
move 1 from 7 to 1
move 4 from 1 to 4
move 6 from 3 to 2
move 3 from 1 to 2
move 3 from 3 to 6
move 3 from 2 to 6
move 6 from 6 to 5
move 1 from 1 to 4
move 1 from 9 to 6
move 5 from 2 to 1
move 3 from 1 to 2
move 2 from 9 to 8
move 3 from 1 to 5
move 1 from 9 to 7
move 25 from 4 to 1
move 1 from 1 to 7
move 2 from 8 to 3
move 13 from 1 to 9
move 2 from 3 to 5
move 8 from 5 to 9
move 4 from 2 to 1
move 2 from 6 to 7
move 10 from 5 to 9
move 4 from 7 to 2
move 2 from 2 to 3
move 9 from 9 to 2
move 4 from 4 to 5
move 4 from 5 to 4
move 5 from 1 to 4
move 10 from 4 to 5
move 22 from 9 to 1
move 2 from 2 to 7
move 3 from 2 to 1
move 6 from 2 to 6
move 1 from 7 to 1
move 10 from 5 to 7
move 15 from 1 to 4
move 13 from 1 to 5
move 3 from 6 to 8
move 1 from 8 to 9

View file

@ -1,153 +0,0 @@
#![feature(iter_array_chunks)]
const INPUT: &str = include_str!("input.txt");
mod part_1;
use part_1::part_1;
mod part_2;
use part_2::part_2;
#[derive(Debug, Clone)]
pub(crate) struct Instruction {
origin: usize,
destination: usize,
amount: usize,
}
impl std::fmt::Display for Instruction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"move {} from {} to {}",
self.amount, self.origin, self.destination
)
}
}
#[derive(Debug, Clone)]
pub(crate) struct ChallengeInput {
initial_state: Vec<Vec<char>>,
instructions: Vec<Instruction>,
}
fn parse_input(input: &'static str) -> ChallengeInput {
let (unparsed_instructions, unparsed_initial_state) = input
.lines()
.partition::<Vec<_>, _>(|line| line.starts_with("move"));
let mut initial_state = vec![];
unparsed_initial_state
.iter()
.rev()
.filter(|line| line.contains('['))
.for_each(|line| {
let mut array_chunks = line.chars().array_chunks::<4>();
let mut idx = 0;
loop {
let Some([lbracket, char, _rbracket, _space]) = array_chunks.next() else {
break;
};
for _ in 0..usize::saturating_sub(1 + 1 + idx, initial_state.len()) {
initial_state.push(vec![]);
}
if lbracket != '[' {
idx += 1;
continue;
}
initial_state[idx].push(char);
idx += 1;
}
let remainder = array_chunks.into_remainder().unwrap().collect::<Vec<_>>();
let last_char = remainder[1];
drop(remainder);
if last_char != ' ' {
let length = initial_state.len();
initial_state[length - 1].push(last_char);
}
});
let instructions = unparsed_instructions
.iter()
.map(|instruction| {
// println!("instruction={instruction}");
let mut chars = instruction.chars().peekable();
loop {
if match chars.peek() {
None => true,
Some(char) => char.is_numeric(),
} {
break;
}
chars.next();
}
let mut amount = String::new();
loop {
if match chars.peek() {
None => true,
Some(char) => !char.is_numeric(),
} {
break;
}
amount.push(chars.next().unwrap());
}
// println!("Amount: {amount}");
loop {
if match chars.peek() {
None => true,
Some(char) => char.is_numeric(),
} {
break;
}
chars.next();
}
let mut origin = String::new();
loop {
if match chars.peek() {
None => true,
Some(char) => !char.is_numeric(),
} {
break;
}
origin.push(chars.next().unwrap());
}
loop {
if match chars.peek() {
None => true,
Some(char) => char.is_numeric(),
} {
break;
}
chars.next();
}
let mut destination = String::new();
loop {
if match chars.peek() {
None => true,
Some(char) => !char.is_numeric(),
} {
break;
}
destination.push(chars.next().unwrap());
}
Instruction {
origin: origin.parse().expect("Non-numeric input encountered"),
destination: destination.parse().expect("Non-numeric input encountered"),
amount: amount.parse().expect("Non-numeric input encountered"),
}
})
.collect();
ChallengeInput {
initial_state,
instructions,
}
}
pub fn main() {
let input = parse_input(INPUT);
part_1(input.clone());
part_2(input);
}

View file

@ -1,40 +0,0 @@
pub(crate) fn part_1(input: crate::ChallengeInput) -> String {
let mut state = input.initial_state;
for crate::Instruction {
origin,
destination,
amount,
} in input.instructions
{
let length = state[origin - 1].len();
let (new_state, moved) = state[origin - 1].split_at(length - amount);
let new_state = new_state.to_vec();
let mut moved = moved.to_vec();
moved.reverse();
state[origin - 1] = new_state;
state[destination - 1].append(&mut moved);
}
state
.iter()
.filter(|stack| !stack.is_empty())
.map(|stack| stack.last().unwrap())
.collect()
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_1(crate::parse_input(crate::INPUT)), "RTGWZTHLD");
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_1(crate::parse_input(SAMPLE_INPUT)), "CMZ");
}
}

View file

@ -1,40 +0,0 @@
pub(crate) fn part_2(input: crate::ChallengeInput) -> String {
let mut state = input.initial_state;
for crate::Instruction {
origin,
destination,
amount,
} in input.instructions
{
let length = state[origin - 1].len();
let (new_state, moved) = state[origin - 1].split_at(length - amount);
let new_state = new_state.to_vec();
let mut moved = moved.to_vec();
// moved.reverse();
state[origin - 1] = new_state;
state[destination - 1].append(&mut moved);
}
state
.iter()
.filter(|stack| !stack.is_empty())
.map(|stack| stack.last().unwrap())
.collect()
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_2(crate::parse_input(crate::INPUT)), "STHGRZZFR");
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_2(crate::parse_input(SAMPLE_INPUT)), "MCD");
}
}

View file

@ -1,9 +0,0 @@
[D]
[N] [C]
[Z] [M] [P]
1 2 3
move 1 from 2 to 1
move 3 from 1 to 3
move 2 from 2 to 1
move 1 from 1 to 2

View file

@ -1 +0,0 @@
zcncrcnrrlccmhchssgqsqrsstfffnqfnfsswgwjjcmcnnvjvwjvwvfvnvwwhvvwmwhmwwwhbhhldhdmhhdfdbdfbdblllnfllgslllqhlhfhlhqllncnfnsffwmwzzlglzlwlhwwmvmddpvvbrvrdvrdvdhhzdhdpdzzbgbsssrpsrshrshhbqbgbmmtwwcbcrbbvnvhnncscwcwlcwlwnwswbbnwntthzzdlzdzffvqvdqvvtptdptphpddzzvhzvzwwqgqjjjvsspvspsbsffvpvcvjcvjvrvjjgmjjhrrdhhdvhvttjttzptpssnlnjjlnnhmnndjnjwwtjjtbbfflwfwgwvvpjpwpcwcgglmgmdmnmbbqtqctcwcmwwvmvlmvmdvdvhvlhlzhzttghttnvnjntnqqtmtwwhvhrhfhchqchhdrdllnwnfwfjjmsmmnhhshnhpptstjjpnpzzhmmpssgrsrzsrrffzjjhvjhjcjcpcvpccfnfjnfjfllssrdsdnnmffldldppcctcmtctffprpsrrrfhfmflldccnpppvsswppdgpgjpgpqgpqpjppclcjczcnzzzqvzzwlzzqfzffsqqphqhvqqbcccstsdttwcwcvvmjjhqqmllpglgtgwgnnbnrbnnjdndhhbrbvrvwwwblwwwppmdmttztqzqrqjjpggpmgpmpqqmssvnsvnndnvddtztddrrsnsbbshhqmhqmmdnnrsrllqvvfjfpfqpqfqflqlmqmrrqgrqrrhvvfddfhhfnhnlncnzzwwjwswpsscpchcssrzssjqsqrsswbbzggnqnwqqsrqqzbqbddtffcjjdggwlwnwtnnpddcqddsppcwpcwpphvphhhrprqrqttwgwqwppvdpvvrgggmpmddzvvwwthwtttbqtbbftfrffbdfbbspshphpwhppnhnmhhbbshbsbmbdmmtrmrbrprbprphhnmhmvhmhhqqbvqvqcvcwcbwcchbbgwwqffrcffsvvcczrztrzzdhdmhdmmzbbvlvqqtptpvvfsfppdzppmddfvdfdwdfdmdwwlvvqdvqdqmdqqmnmdndsswsfwfvwfwzzhrzhhwfhhpvhppmssnhsnsnwswvwlwdwzwnwswwmqmjmbbdjdbbtllcpllltqlttnvvppznpnttlrrwlwvllphpbblccgjcggbtbwtwdwrrbnndpddbqqnpnrnnqqshspsggtptztpzzclcggtqtgqttcmmbgbfbdfdfsddlrlvrlvvmqqgbqgbqbcbbnpplqqblqbqmbbbdqbbhjjcgcdgdwdjwjqqlsqqnnwffglfglgnlggjgjtgjtgjtgjjclcwcqqvpvwwvgvhgvhvjjzpzbznnvrrrpbpdbdhhmshsnnnwppcbcvvlldccdggqnqgnqqzbzzcfflnnmppcgcmgmrgmrgmgngwwptpzzpfzpfzpzdppgcgtcgtgccvtctzzdmzmlmzlzwllbplblltgtctrrghgvhgvvfvssngsschshrhvrvddghgwwwwzgwgvgccjdjzjwwvdvvqsqshsvvddmddbllvppmlpmlmwlwppjmppwrrdzrrpmrmrdmrmbmzzwttvwwsfswwlflnlrlvvdllzbztbtpbtppnjpnpdnnjrjsshtssvvsjvjfjwffsszvsvjssqzsslpslppjpspqptbncvzrlwtjvsrwtnzzhwdfsmlthvgqgjrpshpbsrrvnsdbqslbcplnpcjqwmwqsnwdcjsdmccbdglwbrcdcqsfhjqhstvhqqdwltqwhhqcrnpvnzjhhbjvqbqhclwggjqfvnfsvcnjjhbmrvbpjqrbljbtltvnsgdfhddlmsdhcrfwvlvbsdrjwjvtnqzhrlqgjmzsmjlpdjsrjmdhmvgwjmfwtqffnzfrtswrlgvvhhqgpzcjwscfqgjmdhtvbgzdlvzfhgqlqbfwsjrmmhrlcwhrcnwwvngcmsrfgczsfqvvmdtmtprfvjrwrwcqwvgmzcjncrzvcswlzsdszvdtwmptnrhgzqwrhjjtbchhpwsdjnqmnsgzwqzvlzlsznpqgvtqnldjqpvndtsjlzhpzsgthbwvwnlbwjlmndqpcdvjdgdzhctpghlfwrtqtvfwdpgrjbmwzqgthjpmlrsqmzsznddhrbjnggqrdntpbngvldnnltfnmdwfhftjvpqbrzqvdzbzzctshzldtcdgfnczglrrjtwswzdvjrfgwztwznbpplmbgwpcmstcsjtqhmzmzsjwsfbjlbnbdtdsmlpdmrrbhdhpzrjdpzhcwsrgfrhmqzqtjfhpvltnthwjrrrpnsbmmwrhsfqbmnvwhpntltsgwgnqhcvlndfrtrfrnlmbhltmtgzhlzqgtsbbnggdjvbslfbczhpghqqcqlrbtpnbqbflfjrmpmwwvjqgvcqtmfggmptqlqstcmdtqlslnnzwbgnstftfsvsjdrmgbzfnzltwbjmqhsvshnmwhftjdndltdpngzwbrjpgpwmqgfsflnhmtzcmdjmzwrsrrrmpvwgggwrhrwtfwdbgbpmwpcdspdtbqvdwwsnwdtrtdtgnfzzsmlbcqdzbsqnrgtvvnlfcdlcgcnfpqbddqcjfqtmpndmnwvfqgjzrltqvlprmbbhmtwbzjjgfhhhfjswpffmjnsdmrcjrwlwpmfrmhljpphlwwwwmgsjcsrcvmfrdjdhshddshpplzsnsphcmdhvllgmdgrvbvjmtpltdthffsvwwhvgqrhmfjfpdswcqldrhpmznffjsntwrnmnpmsshljszbchctptsdlnbcvpfvtlfnzcrljpdwrsjnlpqcpnwvnqhzhqmjbvlbtgslzthlbbjzsgdglbrltzjdshpfbndjtssvsjqlstnrjdzzjvlpqhmwvrsvndcqrqjjcsqvmvrbhngtcfdprlbnqmhqllddgjpdzbjlphntrtgjrdgtbslrtzczbnnlddzzsvqvqvvzjpjqfhztgtsfggdppfdhzsbjzqjmpnmgqzlsdhjjbfpbsbnzpmhwrzjqhczrgcsflfwtrgwbnbrshjpwltntsnsdhmhqlmzdprcrcpcpjnphsmjwhzdqtncdbwgspmnfzsgmpbdhmslqchhhbbwfrghhnfjplsvrtbvplgrwdnbnfsgpwrqczvzlnfsngnsnbwvpmfdcmjztdnrllslnwcfwwnwsvztqmgqtfvmdqrrrmwfmphbcvwwttpmwjjbvqrmlwtwfsjdpcbmdlnlzcqntfzzmslshwprjfhwwpbbdfcdjwllfwcznwpjpwrlsfnnbgzjllrgtzcdcvhdhbtlrcvfdvsdjlzsmwwqvpzfhzjlqpfbqstvfrpcchmtwgbrhqqbglrvzmctdlpnvmglgdtzpbdngtfdnmsmwbgjstzbqwqcdlhfrtqqnhqvpfhdrjqvsvstftdgwwnwpfbfbdcfqnqlwpdnfhhfctwrgdqpbpbmgnfsnbpjfctvdtjnsfqlrtctrnjgltndngcmrdphhsqpjhprbngjzqqhnhhrdwlwwpmhzwshvrtzfgzlrhwghvpvfprbbvflltplpptvrmwcrdqndfqbfqtlqqwvphsmcvnbzghvsptrphhfcgdsslhfbcwhtjcmnpbvqrfgpsjgqpnnwwhjjwqrhhqgznwdzjqbtmmjljjwctqtfgwqbdrjwqwbbcftvjwfdfrgvsrlcrccpvfzdrcjvqfbhddpvrrhjrmhdgchrghbzsqpmgnmslfctblwlvphdfpvtdtwpdfsjwssmgnsvsqpdbqngccsplhmjbwjwtzwsbjhwpwcslqjdchmbvzrbgnwvjrrrdtvhtlzlrbwthzlhhqzzpvpwbzrrbrbtpwnhldhqqltqrqdddfwdmjzgctnlrjrjwvddfmjpnptdmrvnqjvsjfrmlvlqsthhsbvnjlsdzrjngfnqdjfssmvgrchbwmwbbvfqfhvrtwghmrpddnwbrbvbmqvfzbjdsnbzgrtmsfhmsmjtrqsgmpnwwbfwtp

View file

@ -1,23 +0,0 @@
#![feature(const_mut_refs)]
#![feature(array_windows)]
#![feature(test)]
extern crate test;
const INPUT: &str = include_str!("input.txt");
use solutions::*;
mod part_1;
mod part_2;
mod solutions;
pub fn main() {
println!(
"Part 1: {}",
solve_nicopap_vertesians_nodeps_const::<4>(INPUT)
);
println!(
"Part 2: {}",
solve_nicopap_vertesians_nodeps_const::<14>(INPUT)
);
}

View file

@ -1,334 +0,0 @@
#[cfg(test)]
mod tests {
const WINDOW_SIZE: usize = 4;
use crate::solutions::*;
const SAMPLES: [(&str, usize); 5] = [
(include_str!("sample_inputs/1.txt"), 7),
(include_str!("sample_inputs/2.txt"), 5),
(include_str!("sample_inputs/3.txt"), 6),
(include_str!("sample_inputs/4.txt"), 10),
(include_str!("sample_inputs/5.txt"), 11),
];
#[bench]
fn bench_vec(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vec::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vec_with_solution() {
assert_eq!(solve_vec::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_vec_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_vec::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_hashset(bencher: &mut test::Bencher) {
bencher.iter(|| solve_hashset::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_hashset_with_solution() {
assert_eq!(solve_hashset::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_hashset_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_hashset::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_snaketwix(bencher: &mut test::Bencher) {
bencher.iter(|| solve_snaketwix::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_snaketwix_with_solution() {
assert_eq!(solve_snaketwix::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_snaketwix_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_snaketwix::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_snaketwix_modified(bencher: &mut test::Bencher) {
bencher.iter(|| solve_snaketwix_modified::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_snaketwix_modified_with_solution() {
assert_eq!(solve_snaketwix_modified::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_snaketwix_modified_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_snaketwix_modified::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_original(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_original::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_original_with_solution() {
assert_eq!(solve_nicopap_original::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_nicopap_original_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_original::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_original_without_windows(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_original_without_windows::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_original_without_windows_with_solution() {
assert_eq!(
solve_nicopap_original_without_windows::<WINDOW_SIZE>(crate::INPUT),
1723
)
}
#[test]
fn test_nicopap_original_without_windows_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_original_without_windows::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_improved(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_improved::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_improved_with_solution() {
assert_eq!(solve_nicopap_improved::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_nicopap_improved_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_improved::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_improved_again(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_improved_again::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_improved_again_with_solution() {
assert_eq!(
solve_nicopap_improved_again::<WINDOW_SIZE>(crate::INPUT),
1723
)
}
#[test]
fn test_nicopap_improved_again_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_improved_again::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_manevillef(bencher: &mut test::Bencher) {
bencher.iter(|| solve_manevillef::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_manevillef_with_solution() {
assert_eq!(solve_manevillef::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_manevillef_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_manevillef::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_manevillef_again(bencher: &mut test::Bencher) {
bencher.iter(|| solve_manevillef_again::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_manevillef_again_with_solution() {
assert_eq!(solve_manevillef_again::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_manevillef_again_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_manevillef_again::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_harudagondi(bencher: &mut test::Bencher) {
bencher.iter(|| solve_harudagondi::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_harudagondi_with_solution() {
assert_eq!(solve_harudagondi::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_harudagondi_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_harudagondi::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
/* Requires phf crate
#[bench]
fn bench_vertesians(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_with_solution() {
assert_eq!(solve_vertesians::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_vertesians_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_vertesians::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
*/
#[bench]
fn bench_vertesians_nodeps(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians_nodeps::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_nodeps_with_solution() {
assert_eq!(solve_vertesians_nodeps::<WINDOW_SIZE>(crate::INPUT), 1723)
}
#[test]
fn test_vertesians_nodeps_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_vertesians_nodeps::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_vertesians_nodeps_improved(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians_nodeps_improved::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_nodeps_improved_with_solution() {
assert_eq!(
solve_vertesians_nodeps_improved::<WINDOW_SIZE>(crate::INPUT),
1723
)
}
#[test]
fn test_vertesians_nodeps_improved_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_vertesians_nodeps_improved::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_vertesians_nodeps_const(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_vertesians_nodeps_const::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_vertesians_nodeps_const_with_solution() {
assert_eq!(
solve_nicopap_vertesians_nodeps_const::<WINDOW_SIZE>(crate::INPUT),
1723
)
}
#[test]
fn test_nicopap_vertesians_nodeps_const_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_vertesians_nodeps_const::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_vertesians_3_1(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians_nodeps_3_1::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_3_1_with_solution() {
assert_eq!(
solve_vertesians_nodeps_3_1::<WINDOW_SIZE>(crate::INPUT),
1723
)
}
#[test]
fn test_vertesians_3_1_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_vertesians_nodeps_3_1::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
}

View file

@ -1,334 +0,0 @@
#[cfg(test)]
mod tests {
const WINDOW_SIZE: usize = 14;
use crate::solutions::*;
const SAMPLES: [(&str, usize); 5] = [
(include_str!("sample_inputs/1.txt"), 19),
(include_str!("sample_inputs/2.txt"), 23),
(include_str!("sample_inputs/3.txt"), 23),
(include_str!("sample_inputs/4.txt"), 29),
(include_str!("sample_inputs/5.txt"), 26),
];
#[bench]
fn bench_vec(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vec::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vec_with_solution() {
assert_eq!(solve_vec::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_vec_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_vec::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_hashset(bencher: &mut test::Bencher) {
bencher.iter(|| solve_hashset::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_hashset_with_solution() {
assert_eq!(solve_hashset::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_hashset_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_hashset::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_snaketwix(bencher: &mut test::Bencher) {
bencher.iter(|| solve_snaketwix::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_snaketwix_with_solution() {
assert_eq!(solve_snaketwix::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_snaketwix_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_snaketwix::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_snaketwix_modified(bencher: &mut test::Bencher) {
bencher.iter(|| solve_snaketwix_modified::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_snaketwix_modified_with_solution() {
assert_eq!(solve_snaketwix_modified::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_snaketwix_modified_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_snaketwix_modified::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_original(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_original::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_original_with_solution() {
assert_eq!(solve_nicopap_original::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_nicopap_original_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_original::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_original_without_windows(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_original_without_windows::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_original_without_windows_with_solution() {
assert_eq!(
solve_nicopap_original_without_windows::<WINDOW_SIZE>(crate::INPUT),
3708
)
}
#[test]
fn test_nicopap_original_without_windows_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_original_without_windows::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_improved(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_improved::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_improved_with_solution() {
assert_eq!(solve_nicopap_improved::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_nicopap_improved_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_improved::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_improved_again(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_improved_again::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_improved_again_with_solution() {
assert_eq!(
solve_nicopap_improved_again::<WINDOW_SIZE>(crate::INPUT),
3708
)
}
#[test]
fn test_nicopap_improved_again_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_improved_again::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_manevillef(bencher: &mut test::Bencher) {
bencher.iter(|| solve_manevillef::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_manevillef_with_solution() {
assert_eq!(solve_manevillef::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_manevillef_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_manevillef::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
#[bench]
fn bench_manevillef_again(bencher: &mut test::Bencher) {
bencher.iter(|| solve_manevillef_again::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_manevillef_again_with_solution() {
assert_eq!(solve_manevillef_again::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_manevillef_again_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_manevillef_again::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_harudagondi(bencher: &mut test::Bencher) {
bencher.iter(|| solve_harudagondi::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_harudagondi_with_solution() {
assert_eq!(solve_harudagondi::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_harudagondi_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_harudagondi::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
/* Requires phf crate
#[bench]
fn bench_vertesians(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_with_solution() {
assert_eq!(solve_vertesians::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_vertesians_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(solve_vertesians::<WINDOW_SIZE>(sample_input), sample_answer)
}
}
*/
#[bench]
fn bench_vertesians_nodeps(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians_nodeps::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_nodeps_with_solution() {
assert_eq!(solve_vertesians_nodeps::<WINDOW_SIZE>(crate::INPUT), 3708)
}
#[test]
fn test_vertesians_nodeps_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_vertesians_nodeps::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_vertesians_nodeps_improved(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians_nodeps_improved::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_nodeps_improved_with_solution() {
assert_eq!(
solve_vertesians_nodeps_improved::<WINDOW_SIZE>(crate::INPUT),
3708
)
}
#[test]
fn test_vertesians_nodeps_improved_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_vertesians_nodeps_improved::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_nicopap_vertesians_nodeps_const(bencher: &mut test::Bencher) {
bencher.iter(|| solve_nicopap_vertesians_nodeps_const::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_nicopap_vertesians_nodeps_const_with_solution() {
assert_eq!(
solve_nicopap_vertesians_nodeps_const::<WINDOW_SIZE>(crate::INPUT),
3708
)
}
#[test]
fn test_nicopap_vertesians_nodeps_const_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_nicopap_vertesians_nodeps_const::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
#[bench]
fn bench_vertesians_3_1(bencher: &mut test::Bencher) {
bencher.iter(|| solve_vertesians_nodeps_3_1::<WINDOW_SIZE>(crate::INPUT));
}
#[test]
fn test_vertesians_3_1_with_solution() {
assert_eq!(
solve_vertesians_nodeps_3_1::<WINDOW_SIZE>(crate::INPUT),
3708
)
}
#[test]
fn test_vertesians_3_1_with_sample_solutions() {
for (sample_input, sample_answer) in SAMPLES {
assert_eq!(
solve_vertesians_nodeps_3_1::<WINDOW_SIZE>(sample_input),
sample_answer
)
}
}
}

View file

@ -1 +0,0 @@
mjqjpqmgbljsphdztnvjfqwrcgsmlb

View file

@ -1 +0,0 @@
bvwbjplbgvbhsrlpgdmjqwftvncz

View file

@ -1 +0,0 @@
nppdvjthqldpwncqszvftbrmjlhg

View file

@ -1 +0,0 @@
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg

View file

@ -1 +0,0 @@
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw

View file

@ -1,564 +0,0 @@
#![allow(dead_code)]
// My original solution
pub(crate) fn solve_vec<const N: usize>(input: &'static str) -> usize {
for idx in 0..(input.len() - N) {
let mut unique_chars = input[idx..idx + N].chars().collect::<Vec<_>>();
unique_chars.sort();
unique_chars.dedup();
if unique_chars.len() == N {
return idx + N;
}
}
unreachable!("We should always find an answer");
}
pub(crate) fn solve_hashset<const N: usize>(input: &'static str) -> usize {
for idx in 0..(input.len() - N) {
let unique_chars = input[idx..idx + N]
.chars()
.collect::<std::collections::HashSet<_>>();
if unique_chars.len() == N {
return idx + N;
}
}
unreachable!("We should always find an answer");
}
pub(crate) fn solve_nicopap_original<const N: usize>(input: &'static str) -> usize {
nicopap_original::first_sop(input.as_bytes(), N).unwrap()
}
mod nicopap_original {
fn all_distinct<T: Clone + Ord>(slice: &[T]) -> bool {
let mut slice_copy = slice.to_vec();
slice_copy.sort_unstable();
slice_copy.windows(2).all(|pair| pair[0] != pair[1])
}
// sop stands for "start of packet"
pub(crate) fn first_sop<T: Clone + Ord>(
datastream: &[T],
required_distinct: usize,
) -> Option<usize> {
datastream
.windows(required_distinct)
.enumerate()
.find_map(|(i, slice)| all_distinct(slice).then_some(i + required_distinct))
}
}
pub(crate) fn solve_nicopap_original_without_windows<const N: usize>(input: &'static str) -> usize {
let mut cache = Vec::with_capacity(N);
for (i, char) in input.chars().enumerate() {
cache.insert(0, char);
if cache.len() >= N {
let mut sorted_cache = cache.clone();
sorted_cache.sort_unstable();
sorted_cache.dedup();
if sorted_cache.len() == N {
return i + 1;
}
cache.pop();
}
}
unreachable!()
}
pub(crate) fn solve_nicopap_improved<const N: usize>(input: &'static str) -> usize {
nicopap_improved::first_sop(input.as_bytes(), N).unwrap()
}
mod nicopap_improved {
fn all_distinct<T: Clone + Ord>(slice: &[T], collect_vec: &mut Vec<T>) -> bool {
collect_vec.clear();
slice.clone_into(collect_vec);
collect_vec.sort_unstable();
collect_vec.windows(2).all(|pair| pair[0] != pair[1])
}
// sop stands for "start of packet"
pub(crate) fn first_sop<T: Clone + Ord>(
datastream: &[T],
required_distinct: usize,
) -> Option<usize> {
let mut collect_vec = Vec::with_capacity(required_distinct);
datastream
.windows(required_distinct)
.enumerate()
.find_map(|(i, slice)| {
all_distinct(slice, &mut collect_vec).then_some(i + required_distinct)
})
}
}
pub(crate) fn solve_nicopap_improved_again<const N: usize>(input: &'static str) -> usize {
nicopap_improved_again::first_sop::<N>(input.as_bytes()).unwrap()
}
mod nicopap_improved_again {
struct AlphabetSet(u32);
impl AlphabetSet {
const fn new() -> Self {
Self(0)
}
/// Add letter to set, return `true` if it is already part of it.
/// `symbol` must be an ascii latin alphabet letter.
fn add_letter_or_contains(&mut self, symbol: u8) -> bool {
let to_set = 1 << (symbol.wrapping_sub(b'a') as u32);
let already_set = self.0 & to_set == to_set;
self.0 |= to_set;
already_set
}
}
fn all_distinct(slice: &[u8]) -> bool {
let mut set = AlphabetSet::new();
!slice
.iter()
.any(|letter| set.add_letter_or_contains(*letter))
}
// sop stands for "start of packet"
pub(crate) fn first_sop<const W: usize>(datastream: &[u8]) -> Option<usize> {
datastream
.array_windows::<W>()
.enumerate()
.find_map(|(i, slice)| all_distinct(slice).then_some(i + W))
}
}
pub(crate) fn solve_manevillef<const N: usize>(input: &'static str) -> usize {
manevillef::find_marker(&input.chars().collect::<Vec<_>>(), N).unwrap()
}
mod manevillef {
use std::collections::HashSet;
pub(crate) fn find_marker(chars: &[char], window: usize) -> Option<usize> {
chars
.windows(window)
.into_iter()
.position(|items| {
let set: HashSet<char> = items.iter().copied().collect();
set.len() == window
})
.map(|p| p + window)
}
}
pub(crate) fn solve_manevillef_again<const N: usize>(input: &'static str) -> usize {
let bytes = input.as_bytes();
let mut cache = bytes[..N].to_owned();
for (i, byte) in bytes[N..].iter().enumerate() {
let mut sorted = cache.clone();
sorted.sort_unstable();
sorted.dedup();
if sorted.len() == N {
return i + N;
}
cache.rotate_left(1);
cache[N - 1] = *byte;
}
unreachable!()
}
pub fn solve_snaketwix<const N: usize>(input: &'static str) -> usize {
let mut number_of_duplicates = 0;
let mut char_map = std::collections::HashMap::new();
let mut char_deque = std::collections::VecDeque::with_capacity(N + 1);
let mut ans = 0;
for (index, char) in input.char_indices() {
let entry = char_map.entry(char).or_insert(0);
*entry += 1;
if *entry > 1 {
number_of_duplicates += 1;
}
char_deque.push_back(char);
if index > N - 1 {
let char = char_deque.pop_front().unwrap();
// Know that the entry exists, but not sure how to unwrap the entry to get access to the value
let entry = char_map.entry(char).or_default();
*entry -= 1;
if *entry >= 1 {
number_of_duplicates -= 1;
}
if number_of_duplicates == 0 {
ans = index + 1;
break;
}
}
}
ans
}
pub fn solve_snaketwix_modified<const N: usize>(input: &'static str) -> usize {
let mut number_of_duplicates = 0;
let mut char_map = std::collections::HashMap::new();
let mut char_deque = std::collections::VecDeque::with_capacity(N + 1);
let mut ans = 0;
for (index, char) in input.char_indices() {
let entry = char_map.entry(char).or_insert(0);
*entry += 1;
if *entry > 1 {
number_of_duplicates += 1;
}
char_deque.push_back(char);
if index > N - 1 {
let char = char_deque.pop_front().unwrap();
let entry = match char_map.entry(char) {
std::collections::hash_map::Entry::Occupied(entry) => entry.into_mut(),
std::collections::hash_map::Entry::Vacant(_) => unreachable!(),
};
*entry -= 1;
if *entry >= 1 {
number_of_duplicates -= 1;
}
if number_of_duplicates == 0 {
ans = index + 1;
break;
}
}
}
ans
}
pub fn solve_harudagondi<const N: usize>(input: &'static str) -> usize {
harudagondi::solve_part2::<N>(input)
}
mod harudagondi {
use std::collections::{HashSet, VecDeque};
#[derive(Default)]
struct Solver {
buffer: VecDeque<char>,
counter: usize,
buffer_size: usize,
}
impl Solver {
fn new(buffer_size: usize) -> Self {
Self {
buffer: VecDeque::new(),
counter: 0,
buffer_size,
}
}
fn update(&mut self, c: char) {
if self.buffer.len() < self.buffer_size {
self.buffer.push_back(c);
} else {
self.buffer.pop_front();
self.buffer.push_back(c);
}
self.counter += 1;
}
fn starter(&self) -> Option<usize> {
let buffer = self.buffer.iter().fold(HashSet::new(), |mut acc, c| {
acc.insert(*c);
acc
});
if buffer.len() == self.buffer_size {
Some(self.counter)
} else {
None
}
}
}
pub fn solve_part2<const N: usize>(input: &'static str) -> usize {
let mut solver = Solver::new(N);
for c in input.chars() {
solver.update(c);
if let Some(counter) = solver.starter() {
return counter;
}
}
unreachable!();
}
}
/* Requires phf crate
pub fn solve_vertesians<const N: usize>(input: &'static str) -> usize {
vertesians::main::<N>(input)
}
mod vertesians {
pub(super) fn main<const N: usize>(input: &'static str) -> usize {
let data = input
.chars()
.map(|c| *SYMBOL_MAP.get(&c).expect("Invalid characters in input"))
.collect::<Vec<u32>>();
assert!(!data.is_empty(), "Received empty input");
process::<N>(data)
}
fn process<const N: usize>(data: Vec<u32>) -> usize {
let mut counter = 0;
loop {
let combined = {
let mut combined = 0;
for i in 0..N {
combined |= data[counter + i];
}
combined
};
if check::<N>(combined) {
return counter + N;
} else {
counter += 1;
}
}
}
static SYMBOL_MAP: phf::Map<char, u32> = phf::phf_map! {
'a' => 0b0000_0000_0000_0000_0000_0000_0000_0001,
'b' => 0b0000_0000_0000_0000_0000_0000_0000_0010,
'c' => 0b0000_0000_0000_0000_0000_0000_0000_0100,
'd' => 0b0000_0000_0000_0000_0000_0000_0000_1000,
'e' => 0b0000_0000_0000_0000_0000_0000_0001_0000,
'f' => 0b0000_0000_0000_0000_0000_0000_0010_0000,
'g' => 0b0000_0000_0000_0000_0000_0000_0100_0000,
'h' => 0b0000_0000_0000_0000_0000_0000_1000_0000,
'i' => 0b0000_0000_0000_0000_0000_0001_0000_0000,
'j' => 0b0000_0000_0000_0000_0000_0010_0000_0000,
'k' => 0b0000_0000_0000_0000_0000_0100_0000_0000,
'l' => 0b0000_0000_0000_0000_0000_1000_0000_0000,
'm' => 0b0000_0000_0000_0000_0001_0000_0000_0000,
'n' => 0b0000_0000_0000_0000_0010_0000_0000_0000,
'o' => 0b0000_0000_0000_0000_0100_0000_0000_0000,
'p' => 0b0000_0000_0000_0000_1000_0000_0000_0000,
'q' => 0b0000_0000_0000_0001_0000_0000_0000_0000,
'r' => 0b0000_0000_0000_0010_0000_0000_0000_0000,
's' => 0b0000_0000_0000_0100_0000_0000_0000_0000,
't' => 0b0000_0000_0000_1000_0000_0000_0000_0000,
'u' => 0b0000_0000_0001_0000_0000_0000_0000_0000,
'v' => 0b0000_0000_0010_0000_0000_0000_0000_0000,
'w' => 0b0000_0000_0100_0000_0000_0000_0000_0000,
'x' => 0b0000_0000_1000_0000_0000_0000_0000_0000,
'y' => 0b0000_0001_0000_0000_0000_0000_0000_0000,
'z' => 0b0000_0010_0000_0000_0000_0000_0000_0000,
};
fn check<const N: usize>(combined: u32) -> bool {
let mut flipped_count = 0;
for position in 0..26 {
let filtered = combined & !(1 << position);
if filtered != combined {
flipped_count += 1;
}
if flipped_count == N {
return true;
}
}
false
}
}
*/
pub fn solve_vertesians_nodeps<const N: usize>(input: &'static str) -> usize {
vertesians_nodeps::main::<N>(input)
}
mod vertesians_nodeps {
pub(super) fn main<const N: usize>(input: &'static str) -> usize {
let data = input
.chars()
.map(|c| 1 << (c as u32 - 0x61))
.collect::<Vec<u32>>();
assert!(!data.is_empty(), "Received empty input");
process::<N>(data)
}
fn process<const N: usize>(data: Vec<u32>) -> usize {
let mut counter = 0;
loop {
let combined = {
let mut combined = 0;
for i in 0..N {
combined |= data[counter + i];
}
combined
};
if check::<N>(combined) {
return counter + N;
} else {
counter += 1;
}
}
}
fn check<const N: usize>(combined: u32) -> bool {
let mut flipped_count = 0;
for position in 0..26 {
let filtered = combined & !(1 << position);
if filtered != combined {
flipped_count += 1;
}
if flipped_count == N {
return true;
}
}
false
}
}
pub fn solve_vertesians_nodeps_improved<const N: usize>(input: &'static str) -> usize {
vertesians_nodeps_improved::main::<N>(input)
}
mod vertesians_nodeps_improved {
pub(super) fn main<const N: usize>(input: &'static str) -> usize {
let data = input
.chars()
.map(|c| 1 << (c as u32 - 0x61))
.collect::<Vec<u32>>();
assert!(!data.is_empty(), "Received empty input");
process::<N>(data)
}
fn process<const N: usize>(data: Vec<u32>) -> usize {
let mut counter = 0;
loop {
let combined = {
let mut combined = 0;
for i in 0..N {
combined |= data[counter + i];
}
combined
};
// Thanks to Gibonius for the suggestion to use u32::count_ones()
if (combined & u32::MAX).count_ones() == N as u32 {
return counter + N;
} else {
counter += 1;
}
}
}
}
pub const fn solve_nicopap_vertesians_nodeps_const<const N: usize>(input: &'static str) -> usize {
// For 0ns results
// match N {
// 4 => nicopap_vertesians_const::RESULT_PART_1,
// 14 => nicopap_vertesians_const::RESULT_PART_2,
// _ => unreachable!(),
// }
nicopap_vertesians_nodeps_const::process::<N>(input.as_bytes())
}
mod nicopap_vertesians_nodeps_const {
pub(super) const RESULT_PART_1: usize = process::<4>(include_bytes!("./input.txt"));
pub(super) const RESULT_PART_2: usize = process::<14>(include_bytes!("./input.txt"));
pub(super) const fn process<const N: usize>(data: &'static [u8]) -> usize {
let mut counter = 0;
loop {
let combined = {
let mut combined = 0;
let mut i = 0;
loop {
if i == N {
break;
}
combined |= 1 << (data[counter + i] - b'a') as u32;
i += 1;
}
combined
};
if check::<N>(combined) {
return counter + N;
} else {
counter += 1;
}
}
}
const fn check<const N: usize>(combined: u32) -> bool {
let flipped_count = (combined & 0b11_1111_1111_1111_1111_1111_1111).count_ones();
flipped_count == (N as u32)
}
}
pub fn solve_vertesians_nodeps_3_1<const N: usize>(input: &'static str) -> usize {
vertesians_nodeps_3_1::main::<N>(input)
}
mod vertesians_nodeps_3_1 {
pub(super) fn main<const N: usize>(input: &'static str) -> usize {
let data = input
.chars()
.map(|c| 1 << (c as u32 - 0x61))
.collect::<Vec<u32>>();
assert!(!data.is_empty(), "Received empty input");
process::<N>(data)
}
fn process<const N: usize>(data: Vec<u32>) -> usize {
for counter in 0.. {
let combined = {
let mut combined = 0;
for i in 0..N {
combined |= data[counter + i];
}
combined
};
// Thanks to Gibonius for the suggestion to use u32::count_ones()
if combined.count_ones() == N as u32 {
return counter + N;
}
}
panic!("No valid sequence found");
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,81 +0,0 @@
#![feature(map_try_insert)]
const INPUT: &str = include_str!("input.txt");
mod part_1;
use part_1::part_1;
mod part_2;
use part_2::part_2;
#[derive(Debug)]
pub(crate) enum ConsoleLine {
MoveRoot,
MoveUp,
MoveDown(&'static str),
List,
ListOutputDir(&'static str),
ListOutputFile(&'static str, usize),
}
#[derive(Debug)]
pub(crate) struct ConsoleLineParseError;
impl ConsoleLine {
fn from_str(s: &'static str) -> Result<Self, ConsoleLineParseError> {
let result = match s.starts_with('$') {
true => match &s[2..4] {
"cd" => match s.chars().nth(5) {
Some('/') => Ok(ConsoleLine::MoveRoot),
Some('.') => Ok(ConsoleLine::MoveUp),
Some(_) => Ok(ConsoleLine::MoveDown(&s[5..])),
None => Err(ConsoleLineParseError),
},
"ls" => Ok(ConsoleLine::List),
_ => Err(ConsoleLineParseError),
},
false => match s.chars().next() {
Some(char) => match char.is_numeric() {
true => {
let split_index = s.char_indices().find(|char| char.1 == ' ');
match split_index {
Some(split_index) => {
let (file_size, file_name) = s.split_at(split_index.0);
// Remove leading ' '
let file_name = &file_name[1..];
let file_size = file_size.parse::<usize>();
match file_size {
Ok(file_size) => {
Ok(ConsoleLine::ListOutputFile(file_name, file_size))
}
Err(_) => Err(ConsoleLineParseError),
}
}
None => Err(ConsoleLineParseError),
}
}
false => Ok(ConsoleLine::ListOutputDir(&s[4..])),
},
None => Err(ConsoleLineParseError),
},
};
if let Ok(result) = result {
// println!("parsed: {result:?}");
Ok(result)
} else {
result
}
}
}
fn parse_input(input: &'static str) -> Vec<ConsoleLine> {
input
.lines()
.map(|line| ConsoleLine::from_str(line).expect("Invalid input"))
.collect()
}
pub fn main() {
let input = parse_input(INPUT);
part_1(&input);
part_2(&input);
}

View file

@ -1,59 +0,0 @@
use std::collections::HashMap;
use crate::ConsoleLine;
pub(crate) fn part_1(input: &Vec<ConsoleLine>) -> usize {
let mut current_directory: Vec<&'static str> = vec![];
let mut directory_sizes = HashMap::<String, usize>::new();
for line in input {
match line {
ConsoleLine::MoveRoot => {
while current_directory.len() > 1 {
current_directory.pop();
}
}
ConsoleLine::MoveUp => {
current_directory.pop();
}
ConsoleLine::MoveDown(new_dir) => {
current_directory.push(new_dir);
}
ConsoleLine::List => {}
ConsoleLine::ListOutputDir(_dir_name) => {}
ConsoleLine::ListOutputFile(_file_name, file_size) => {
for length in 0..=current_directory.len() {
let parent_directory = current_directory[0..length].join("/");
if let Err(mut a) = directory_sizes.try_insert(parent_directory, *file_size) {
let t = a.entry.get_mut();
*t += a.value;
};
}
}
}
}
let result = directory_sizes
.iter()
.filter_map(|(_, v)| if *v <= 100_000 { Some(v) } else { None })
.sum();
println!("Part 1: {result}",);
result
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_1(&crate::parse_input(crate::INPUT)), 1084134);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_1(&crate::parse_input(SAMPLE_INPUT)), 95437);
}
}

View file

@ -1,72 +0,0 @@
use std::collections::HashMap;
use crate::ConsoleLine;
pub(crate) fn part_2(input: &Vec<ConsoleLine>) -> usize {
const TOTAL_SPACE: usize = 70_000_000;
const NEEDED_SPACE: usize = 30_000_000;
let mut current_directory: Vec<&'static str> = vec![];
let mut directory_sizes = HashMap::<String, usize>::new();
for line in input {
match line {
ConsoleLine::MoveRoot => {
while current_directory.len() > 1 {
current_directory.pop();
}
}
ConsoleLine::MoveUp => {
current_directory.pop();
}
ConsoleLine::MoveDown(new_dir) => {
current_directory.push(new_dir);
}
ConsoleLine::List => {}
ConsoleLine::ListOutputDir(_dir_name) => {}
ConsoleLine::ListOutputFile(_file_name, file_size) => {
for length in 0..=current_directory.len() {
let parent_directory = current_directory[0..length].join("/");
if let Err(mut a) = directory_sizes.try_insert(parent_directory, *file_size) {
let t = a.entry.get_mut();
*t += a.value;
};
}
}
}
}
let available_space = TOTAL_SPACE - directory_sizes[""];
let required_space = NEEDED_SPACE - available_space;
let result = directory_sizes
.iter()
.filter_map(|(_directory_name, directory_size)| {
if *directory_size >= required_space {
Some(*directory_size)
} else {
None
}
})
.min()
.unwrap();
println!("Part 2: {result}",);
result
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_2(&crate::parse_input(crate::INPUT)), 6183184);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_2(&crate::parse_input(SAMPLE_INPUT)), 24933642);
}
}

View file

@ -1,23 +0,0 @@
$ cd /
$ ls
dir a
14848514 b.txt
8504156 c.dat
dir d
$ cd a
$ ls
dir e
29116 f
2557 g
62596 h.lst
$ cd e
$ ls
584 i
$ cd ..
$ cd ..
$ cd d
$ ls
4060174 j
8033020 d.log
5626152 d.ext
7214296 k

View file

@ -1,99 +0,0 @@
023322201321333021030055115233032255002015013044155106103011355435025324002515233340032023013101000
333001114104040220402023231114145321226614100664520643140442646451222053211251540001413110202310311
001122230342102202311114141015535535515054203105023201320052153606250133240404425023031241331132300
200333324214423413533144232012440022651463612352410034332230305463511214140020132330411142212122132
102231001140012234010224535134246522662353351650411444516502333264512265503131345351241014030131031
123304301244220202523215244250456660036136615601260455124040610534545066145403001311004201223131020
002003410244152204332045034034653220253344012342462512115252223350162403054433114541414402004230003
200103132341510422452452250254525020361416010364344643552146232455465641450614242024420434042322023
334030404131124213210110065630054201305051151553713765154353152015404165650352432220042240121431441
310413343322502004445560402155236460562124231544313721765226711114232542101026341112103205000204213
232113123250204533056410314645353415455472754633613676614123217267412616420454632514221110454141242
212320215533235344164103161651553275174711711164356766211341364224361343166521543245501043403313020
132311140310204051126312005021325536142561672714571554376563517456554662362641056124005412144432424
231444210534331154552403515511564757547561574455777217737432721253356756144650425243250053400131102
402305010405005545336224323172551713366727316646463352447124162453153245317302364400260244035250203
141021340213551650603550523267762213732351446246376356435541361325455465416164254305301451555014314
020311351332141136563303441244763611434365535243774772754265656372342514675761031061364550351222431
413245211550112425253426472765645176882866845564838257856366634524532753142526650514203343254534533
435452451101402442345414221334613563324588667748572632844384676268337331257112272444312406000210430
010335302204230321512415571174254452865672753726557623855355483625486653112141562116114316324324330
221535255034163464174647563575653473563783762385456872577376838278724787533322241360046164145143444
023200114430135341415733511326526724522547637566455625677487874884677748355767326531554460531505423
041325411513220355333664623324656723324354775368994776576453743226382234255146721766626165345032040
251500552152654263475146756832747868664284795636459947469897787877228355585665321152065265452205010
140403120623541575137615727682856477356763944336369569588959794665537746822241226172105532241014054
453231451142201467644523625687875786636878558948395383658853983478274336626223261322670214456000012
421401202553552263622464483244566634338573647446753646346899559455467362654676475666633635516251041
323131612232542573237614644344532373875676439947597665797366646687698528458322143111266523602124520
350402001311666477622377487567429458933773439373736474937847339863733784866824546353257615331613522
250022536362331172722668268236867398553738597646787654948564865538536978368448574575767731313436224
402502304364172157656277664376787847997386975947666779469869555838787877535542353742444675210555330
534146105561234616268536526749363399896897558457877796995459475968646953877355285715651641221535521
303646554131712176733825365433864398786578577698887656988984667665877535682343345654563777135012425
324510121102677116583635857975693374387486566897798478994684955676694383688884846856322762430431244
514510651516612266887483855356674543785959656848847555648447748596549489474486425724612453763154612
231062261547177317255662764857346469768747497764945945965757496698454569588782672772143151160442034
320163342042441177863252689394446487894788488755875979945694655996536354949538842337254673262442021
332245516535336165424866833774775969444884989558587897695567778655663877687674655723514215474233645
305304310765327184528544539776454864657499589567575587578857495776446886984958232865323375223161226
041321134716326427345342674747478687768869565659869667675778958466596675773462357464554753265120531
214135547421514268628575739385987456987579588577977997755957594894869954387663668252657636412005462
303014312474744334438854664364557544877859878676955887957766794676788758349967423548311115421012031
165600101766416548688563985883658885658968698975789866869555596449468493399749732764355275156263540
023235337273751276356326956636445746559765659596677778588597776965655557544476853383777537142222045
263022507373222354242473545837465487886578985999866897786966667659976798784598852254766575426052230
051533463326323676244499536339757747598658665666877776665556856698587598784344845678845431463000630
350253347271711387537784387454469565865799697798999978977698659775896784977364666572732246234315203
341005566337216558547638778897554744866597657879686786676958688799857477968856776862486125354403122
621400523354423736428594359887676575878885656668779879866568999864874549669688988364688346235212421
505135676316352285588875489864578745965769688688697676766658757779794959756587955783527662755755550
412201242457267256768457574464866864796989986797678879786798988756654489745697566438648525314315120
465513676443563625564338436498947956778678989979778889888765868665989946774539564524422761417235426
232566141256427682382546587547954498979759697699669866686878965577999966363744744433546335352521216
426641574412112675686545366888568858676989567798688877989897665567789554385448648853822213741324260
602662554527175344426766863695666656977788897678788977877689686966648487456799824486782375417461456
651655223645567747258565638365989956656677767968776687998958899596855768455367926645753536315666440
212101665433515738883643775536779945579976596567786779666997868695869664755484454857473235121532445
050653146543541364346323653736454948456785699959977797599687588797759765975388673684657445217361543
064052466421561857423457964965989558587599968966579676777587688855745463996659346764634531763304515
561551524332754584232789895869594554468566797988665678658758669559768854455376555847876562742331036
325314542655721556272469893855789755477667687765899758695565678476456955583865232637557334756250066
142312051576173167535685734664695895767875888777758989579876988865676775699635377648226576522411336
264405030674612265825464755969447459794894978557578676887898777658666398378833868636241721763463230
226106504172532322756823879646746684578495976958986858585948768946563458695562852538355727621152553
010455552047535263283644464733478545978574965849565776774485474589895848955474423534356723663335362
344641162242761347244832643748385795576889884668584468667945796945977446594377836734377545264505202
034234561142745745528645734559984454564945447687598468749845599859594766854257575231153232601521102
540240251242253675342846365745937738658974994554845749686786757743643844958548825225537647141563520
320206262105457111733842244254676634937587947685687474475998874887466954622334232535552551031406142
514054400340122471674738287345975345554989578889687665977944569694376357735848686622213124245443111
052523034313452374556723742753478844856887759998965975878847759763497772425467874322521153360256440
222351100013277574717265537284546936359665666859668677959565397475778974448826377463727135443542405
523350424041153637642545773628235636497539933545997447966795573653867437626874225421751645016443433
312215360245443761525542452352242557749988469436989969593867853433893324724227766423165014506020545
043301115145336365333177277445276796874975464449775989576653853847933547267577416233622000500250204
010430464664035143116714487846468273747588694587534759975435534953667857468842565117553510343230004
111523155243403247241622253657835525667595756477383976646535657887238383548526267564106666155410400
331143444424136613727453361363448436384873986369887364654778533252327534346555721777153155043314351
504400535003012413114454471286326822622755886597475895367832256758387882813774733523434423050344153
031223513454351150575175721474553686462624367655585284263625746377334236266723565566434350565141505
025403550435001645163142764332743577336357527577475885842585236426673634564751755732464325035342155
330421145016464561337162167576453887346346662377775778365787447636782124712553177545200210154304402
145134011342136360041775757661255522836536453757768526277233484847723214161226742551423535541545141
120424442054514402401215773774217135788666446728752473458828676541113522171226164646163420350045352
320300042111566320001225347233316661324787538457643633368888833762234461732376203555404440133510432
040041531054536240250125277267321574523425854345828833847341557475227253772735231005626405434053110
132032504525425163004536034651157757674257322776353873743315142663344157512332514161361250434024042
412131202502245064331035365341616236636215157647137215154547671162456657640014205623004340003440042
023402254450222445315156123064462256711636662722324113154653243672151665651410655544242445235033214
030244442213354225245214420026615315266333321464545152275426214253367063445442123421222354522130443
000404231340354415013353552601201031525655623675321422372514761615551410213215314045514055253413013
424431424142012102050025660124656001446655324426514434456334347361251512153650510232214515000212124
210444432021415253200025444324242403030613314565321154125546321420536312644040231522244324413232134
304213344021421403321314610146511434231323466075612476301612210064435402534231034321214151220134113
002213301410344533212501252101020156640662021153562032241365344241433044503534355443400214003434001
022314333231043300404453132012064266633361244266541036223442060142103261113425041124401240222232000
311003213421304332112132501310051205416305264342531341103003055416252025531115042105141422320032103
133213004320332415205534404040532521244601552314401414553622300634114003055144015221303103000233300
121313142330141112135522531401154344545521012501566652210433310564254034403545252414443110303020313

View file

@ -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;
pub fn main() {
part_1(INPUT);
part_2(INPUT);
}

View file

@ -1,78 +0,0 @@
pub(crate) fn part_1(input: &'static str) -> usize {
let mut visible = vec![vec![false; input.lines().next().unwrap().len()]; input.lines().count()];
// Left-to-right
{
for (line_idx, line) in input.lines().enumerate() {
let mut biggest_char_in_line = '\0';
for (char_idx, char) in line.char_indices() {
if char > biggest_char_in_line {
visible[line_idx][char_idx] = true;
biggest_char_in_line = char;
}
}
}
}
// Right-to-left
{
for (line_idx, line) in input.lines().enumerate() {
let mut biggest_char_in_line = '\0';
for (char_idx, char) in line.char_indices().rev() {
if char > biggest_char_in_line {
visible[line_idx][char_idx] = true;
biggest_char_in_line = char;
}
}
}
}
// Top-to-bottom
{
let mut biggest_char_in_column = vec!['\0'; input.lines().next().unwrap().len()];
for (line_idx, line) in input.lines().enumerate() {
for (char_idx, char) in line.char_indices() {
if char > biggest_char_in_column[char_idx] {
visible[line_idx][char_idx] = true;
biggest_char_in_column[char_idx] = char;
}
}
}
}
// Bottom-to-top
{
let mut biggest_char_in_column = vec!['\0'; input.lines().next().unwrap().len()];
for (line_idx, line) in input.lines().enumerate().collect::<Vec<_>>().iter().rev() {
for (char_idx, char) in line.char_indices() {
if char > biggest_char_in_column[char_idx] {
visible[*line_idx][char_idx] = true;
biggest_char_in_column[char_idx] = char;
}
}
}
}
let result = visible.iter().flatten().filter(|v| **v).count();
println!("Part 1: {result}");
result
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_1(crate::INPUT), 1676);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_1(SAMPLE_INPUT), 21);
}
}

View file

@ -1,54 +0,0 @@
pub(crate) fn part_2(input: &'static str) -> usize {
let trees = input
.lines()
.map(|line| line.bytes().map(|byte| byte - b'0').collect::<Vec<_>>())
.enumerate()
.collect::<Vec<_>>();
let max_y = trees.len();
let max = trees
.iter()
.flat_map(|(y, line)| {
line.iter().enumerate().map(|(x, v)| {
let y = *y;
if y == 0 || x == 0 || x >= line.len() - 1 || y >= max_y - 1 {
return 0;
}
let left = &line[..x];
let right = &line[(x + 1)..];
let up = (0..y).map(|i| trees[i].1[x]);
let mut down = ((y + 1)..max_y).map(|i| trees[i].1[x]);
let score = |pos: Option<usize>, default: usize| pos.unwrap_or(default) + 1;
score(up.rev().position(|n| n >= *v), y.saturating_sub(1))
* score(down.position(|n| n >= *v), max_y.saturating_sub(y + 2))
* score(left.iter().rev().position(|n| n >= v), x.saturating_sub(1))
* score(
right.iter().position(|n| n >= v),
line.len().saturating_sub(x + 2),
)
})
})
.max()
.unwrap();
println!("Part 2: {max}");
max
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_2(crate::INPUT), 313200);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_2(SAMPLE_INPUT), 8);
}
}

View file

@ -1,5 +0,0 @@
30373
25512
65332
33549
35390

File diff suppressed because it is too large Load diff

View file

@ -1,62 +0,0 @@
#![feature(exclusive_range_pattern)]
const INPUT: &str = include_str!("input.txt");
mod part_1;
use part_1::part_1;
mod part_2;
use part_2::part_2;
#[derive(Clone, Copy, Debug)]
pub(crate) enum Direction {
Up,
Down,
Left,
Right,
}
impl From<Direction> for (i64, i64) {
fn from(value: Direction) -> Self {
match value {
Direction::Up => (0, 1),
Direction::Down => (0, -1),
Direction::Left => (-1, 0),
Direction::Right => (1, 0),
}
}
}
pub(crate) struct Move(Direction, i64);
impl Move {
fn from_string(string: &'static str) -> Self {
let (direction, distance) = string.split_at(2);
let direction = match direction.chars().next().unwrap() {
'U' => Direction::Up,
'D' => Direction::Down,
'L' => Direction::Left,
'R' => Direction::Right,
_ => panic!("Non-direction character found"),
};
Self(
direction,
distance
.parse()
.unwrap_or_else(|_| panic!("Found non-numeric input {distance}")),
)
}
}
pub(crate) fn distance_between_points(point_a: &(i64, i64), point_b: &(i64, i64)) -> (i64, i64) {
(point_a.0 - point_b.0, point_a.1 - point_b.1)
}
pub(crate) fn parse_input(input: &'static str) -> Vec<Move> {
input.lines().map(Move::from_string).collect()
}
pub fn main() {
let input = parse_input(INPUT);
part_1(&input);
part_2(&input);
}

View file

@ -1,55 +0,0 @@
use std::collections::HashSet;
use crate::Move;
pub(crate) fn part_1(input: &[Move]) -> usize {
let mut head_position = (0i64, 0i64);
let mut tail_position = (0i64, 0i64);
let mut visited_tail_positions = HashSet::new();
for head_movement in input.iter() {
for _ in 0..head_movement.1 {
match head_movement.0 {
crate::Direction::Up => head_position.1 += 1,
crate::Direction::Down => head_position.1 -= 1,
crate::Direction::Right => head_position.0 += 1,
crate::Direction::Left => head_position.0 -= 1,
}
let point_distance = crate::distance_between_points(&head_position, &tail_position);
match point_distance {
(2, 0) => tail_position.0 += 1,
(-2, 0) => tail_position.0 -= 1,
(0, 2) => tail_position.1 += 1,
(0, -2) => tail_position.1 -= 1,
(_, 2) => tail_position = (head_position.0, tail_position.1 + 1),
(2, _) => tail_position = (tail_position.0 + 1, head_position.1),
(_, -2) => tail_position = (head_position.0, tail_position.1 - 1),
(-2, _) => tail_position = (tail_position.0 - 1, head_position.1),
_ => {}
};
visited_tail_positions.insert(tail_position);
}
}
println!("Part 1: {:?}", visited_tail_positions.len());
visited_tail_positions.len()
}
#[cfg(test)]
mod tests {
const SAMPLE_INPUT: &str = include_str!("sample_input.txt");
#[test]
fn test_with_solution() {
assert_eq!(super::part_1(&crate::parse_input(crate::INPUT)), 6271);
}
#[test]
fn test_with_sample_solution() {
assert_eq!(super::part_1(&crate::parse_input(SAMPLE_INPUT)), 13);
}
}

Some files were not shown because too many files have changed in this diff Show more