Compare commits

...

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

47 changed files with 4398 additions and 151771 deletions

3
.gitignore vendored
View file

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

24
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Start",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/c/day3.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/c/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

17
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,17 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Run build script",
"command": "./build-all.ps1",
"options": {
"cwd": "${workspaceFolder}/c/"
},
"group": {
"kind": "build",
"isDefault": true
},
}
]
}

View file

@ -4,5 +4,10 @@
"path": "." "path": "."
} }
], ],
"settings": {} "settings": {
"files.associations": {
"*.lock": "yarnlock",
"stdlib.h": "c"
}
}
} }

File diff suppressed because one or more lines are too long

View file

@ -1,132 +0,0 @@
{
"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)"
]
}
]
}

File diff suppressed because it is too large Load diff

View file

@ -1,104 +0,0 @@
{
"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)"
]
}
]
}

File diff suppressed because one or more lines are too long

View file

@ -1,123 +0,0 @@
{
"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))"
]
}
]
}

View file

@ -1 +0,0 @@
yzbqklnj

View file

@ -1,112 +0,0 @@
{
"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)"
]
}
]
}

File diff suppressed because it is too large Load diff

View file

@ -1,119 +0,0 @@
{
"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
}

View file

@ -1,300 +0,0 @@
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

View file

@ -1,152 +0,0 @@
{
"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

View file

@ -1,55 +0,0 @@
{
"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": {}
}
]
}

View file

@ -1,5 +0,0 @@
# 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

@ -1,339 +0,0 @@
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

@ -1,16 +0,0 @@
{
"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

@ -1,64 +0,0 @@
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

@ -1,66 +0,0 @@
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

@ -1,69 +0,0 @@
{
"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

@ -1,67 +0,0 @@
# 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,5 +0,0 @@
# 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

@ -1,300 +0,0 @@
"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

@ -1,16 +0,0 @@
{
"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

@ -1,9 +0,0 @@
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

@ -1,15 +0,0 @@
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

@ -1,69 +0,0 @@
{
"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

@ -1,67 +0,0 @@
# 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

@ -1,5 +0,0 @@
# 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

@ -1,16 +0,0 @@
{
"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

@ -1,6 +0,0 @@
import * as fs from "fs";
const input = fs.readFileSync("input").toString();
async function main() {}
main().then(console.log).catch(console.error);

View file

@ -1,6 +0,0 @@
import * as fs from "fs";
const input = fs.readFileSync("input").toString();
async function main() {}
main().then(console.log).catch(console.error);

View file

@ -1,69 +0,0 @@
{
"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

@ -1,67 +0,0 @@
# 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==

3
c/build-all.ps1 Executable file
View file

@ -0,0 +1,3 @@
# gcc day1/*.c -o day1.exe -Og -g -Wall -Werror -std=c17
# gcc day2/*.c -o day2.exe -Og -g -Wall -Werror -std=c17
gcc day3/*.c -o day3.exe -Og -g -Wall -Werror -std=c17

2000
c/day1/input.txt Normal file

File diff suppressed because it is too large Load diff

96
c/day1/main.c Normal file
View file

@ -0,0 +1,96 @@
// https://adventofcode.com/2021/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DAY 1
#define INPUT_LENGTH 2000
static int parsedInput[INPUT_LENGTH];
void parseInput(char const *const input)
{
char const *curLine = input;
unsigned int lineNum = 0;
while (curLine)
{
char const *nextLine = strchr(curLine, '\n');
int curLineLen = nextLine ? nextLine - curLine : strlen(curLine);
char *const tempStr = malloc(curLineLen + 1);
memcpy(tempStr, curLine, curLineLen);
tempStr[curLineLen] = '\0';
parsedInput[lineNum] = _atoi64(tempStr);
free(tempStr);
curLine = nextLine ? nextLine + 1 : NULL;
lineNum++;
}
}
char const *const part1()
{
static const unsigned char MEASUREMENTS = 2;
int result = 0;
for (unsigned int i = MEASUREMENTS - 1; i < INPUT_LENGTH; i++)
{
if (parsedInput[i] > parsedInput[i - 1])
{
result++;
}
}
char *const resultString = malloc(sizeof(char) * 10);
sprintf(resultString, "%d", result);
return resultString;
};
char const *const part2()
{
static const unsigned char MEASUREMENTS = 3;
int result = 0;
for (unsigned int i = MEASUREMENTS; i < INPUT_LENGTH; i++)
{
int measurementWindowA = parsedInput[i - 3] + parsedInput[i - 2] + parsedInput[i - 1];
int measurementWindowB = parsedInput[i - 2] + parsedInput[i - 1] + parsedInput[i - 0];
if (measurementWindowB > measurementWindowA)
{
result++;
}
}
char *const resultString = malloc(sizeof(char) * 10);
sprintf(resultString, "%d", result);
return resultString;
};
int main(void)
{
char *const fileName = malloc(sizeof(char) * sizeof("dayXX/input.txt"));
sprintf(fileName, "day%d/input.txt", DAY);
FILE *inputFile = fopen(fileName, "r");
if (inputFile == NULL)
{
printf("Failed to open input file %s.\n", fileName);
return 1;
}
fseek(inputFile, 0, SEEK_END);
long length = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);
char *const input = malloc(length);
if (input != NULL)
{
fread(input, 1, length, inputFile);
}
fclose(inputFile);
parseInput(input);
printf("Day %d\n", DAY);
printf("Part 1:\n%s\n", part1());
printf("--------------\n");
printf("Part 2:\n%s\n\n", part2());
return 0;
}

1000
c/day2/input.txt Normal file

File diff suppressed because it is too large Load diff

132
c/day2/main.c Normal file
View file

@ -0,0 +1,132 @@
// https://adventofcode.com/2021/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DAY 2
#define INPUT_LENGTH 1000
struct Order
{
enum Direction
{
FORWARD,
DOWN,
UP,
} direction;
int amount;
} parsedInput[INPUT_LENGTH];
void parseInput(char *const input)
{
char *pch = strtok(input, " \n");
int orderNum = 0;
while (pch != NULL)
{
switch (pch[0])
{
case 'f':
parsedInput[orderNum].direction = FORWARD;
break;
case 'd':
parsedInput[orderNum].direction = DOWN;
break;
case 'u':
parsedInput[orderNum].direction = UP;
break;
default:
printf("Unknown direction: %s\n", pch);
exit(EXIT_FAILURE);
}
pch = strtok(NULL, " \n");
parsedInput[orderNum].amount = _atoi64(pch);
pch = strtok(NULL, " \n");
orderNum++;
}
}
char const *const part1()
{
static unsigned int horizontal = 0;
static unsigned int depth = 0;
for (unsigned int i = 0; i < INPUT_LENGTH; i++)
{
switch (parsedInput[i].direction)
{
case FORWARD:
horizontal += parsedInput[i].amount;
break;
case DOWN:
depth += parsedInput[i].amount;
break;
case UP:
depth -= parsedInput[i].amount;
break;
}
}
char *const result = malloc(sizeof(char) * 50);
sprintf(result, "X: %d, Y: %d; Result: %d", horizontal, depth, horizontal * depth);
return result;
};
char const *const part2()
{
static unsigned int horizontal = 0;
static unsigned int depth = 0;
static unsigned int aim = 0;
for (unsigned int i = 0; i < INPUT_LENGTH; i++)
{
switch (parsedInput[i].direction)
{
case FORWARD:
horizontal += parsedInput[i].amount;
depth += parsedInput[i].amount * aim;
break;
case DOWN:
aim += parsedInput[i].amount;
break;
case UP:
aim -= parsedInput[i].amount;
break;
}
}
char *const result = malloc(sizeof(char) * 50);
sprintf(result, "X: %d, Y: %d; Result: %d", horizontal, depth, horizontal * depth);
return result;
};
int main(void)
{
char *const fileName = malloc(sizeof(char) * sizeof("dayXX/input.txt"));
sprintf(fileName, "day%d/input.txt", DAY);
FILE *inputFile = fopen(fileName, "r");
if (inputFile == NULL)
{
printf("Failed to open input file %s.\n", fileName);
return 1;
}
fseek(inputFile, 0, SEEK_END);
long length = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);
char *const input = malloc(length);
if (input != NULL)
{
fread(input, 1, length, inputFile);
}
fclose(inputFile);
parseInput(input);
printf("Day %d\n", DAY);
printf("Part 1:\n%s\n", part1());
printf("--------------\n");
printf("Part 2:\n%s\n\n", part2());
return 0;
}

1000
c/day3/input.txt Normal file

File diff suppressed because it is too large Load diff

119
c/day3/main.c Normal file
View file

@ -0,0 +1,119 @@
// https://adventofcode.com/2021/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DAY 3
#define INPUT_LENGTH 1000
#define INPUT_BIT_SIZE 12
unsigned int parsedInput[INPUT_LENGTH];
void parseInput(char *const input)
{
char const *curLine = input;
unsigned int lineNum = 0;
while (lineNum < INPUT_LENGTH)
{
char const *nextLine = strchr(curLine, '\n');
int curLineLen = nextLine ? nextLine - curLine : strlen(curLine);
char *const tempStr = malloc(curLineLen + 1);
memcpy(tempStr, curLine, curLineLen);
tempStr[curLineLen] = '\0';
parsedInput[lineNum] = strtol(tempStr, NULL, 2);
free(tempStr);
curLine = nextLine ? nextLine + 1 : NULL;
lineNum++;
}
}
char const *const part1()
{
unsigned int ones[INPUT_BIT_SIZE] = {0};
for (unsigned int input_i = 0; input_i < INPUT_LENGTH; input_i++)
{
for (unsigned char i = 0; i < INPUT_BIT_SIZE; i++)
{
ones[i] += (parsedInput[input_i] >> i) & 1;
}
}
char gammaStr[INPUT_BIT_SIZE + 1];
sprintf(gammaStr, "%c%c%c%c%c%c%c%c%c%c%c%c",
ones[INPUT_BIT_SIZE - 1] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 2] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 3] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 4] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 5] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 6] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 7] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 8] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 9] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 10] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 11] > INPUT_LENGTH / 2 ? '1' : '0',
ones[INPUT_BIT_SIZE - 12] > INPUT_LENGTH / 2 ? '1' : '0');
char epsilonStr[INPUT_BIT_SIZE + 1];
sprintf(epsilonStr, "%c%c%c%c%c%c%c%c%c%c%c%c",
ones[INPUT_BIT_SIZE - 1] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 2] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 3] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 4] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 5] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 6] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 7] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 8] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 9] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 10] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 11] > INPUT_LENGTH / 2 ? '0' : '1',
ones[INPUT_BIT_SIZE - 12] > INPUT_LENGTH / 2 ? '0' : '1');
long int gamma = strtol(gammaStr, NULL, 2);
long int epsilon = strtol(epsilonStr, NULL, 2);
char *const result = malloc(32);
sprintf(result, "%ld", gamma * epsilon);
return result;
};
char const *const part2()
{
return "UNSOLVED";
};
int main(void)
{
char *const fileName = malloc(sizeof(char) * sizeof("dayXX/input.txt"));
sprintf(fileName, "day%d/input.txt", DAY);
FILE *inputFile = fopen(fileName, "r");
if (inputFile == NULL)
{
printf("Failed to open input file %s.\n", fileName);
return 1;
}
fseek(inputFile, 0, SEEK_END);
long length = ftell(inputFile);
fseek(inputFile, 0, SEEK_SET);
char *const input = malloc(length);
if (input != NULL)
{
fread(input, 1, length, inputFile);
}
fclose(inputFile);
parseInput(input);
printf("Day %d\n", DAY);
printf("Part 1:\n%s\n", part1());
printf("--------------\n");
printf("Part 2:\n%s\n\n", part2());
return 0;
}