Added full days 1-3 2018, full days 1-11 2015, first star day 12 2015
This commit is contained in:
commit
3d819bf6b7
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,12 @@
|
|||
with open('day1-input', 'r') as file:
|
||||
data = file.readlines()
|
||||
print(data[0].count('(') - data[0].count(')')) # Part 1
|
||||
f = 0
|
||||
for i, c in enumerate(data[0]):
|
||||
if c == '(':
|
||||
f += 1
|
||||
else:
|
||||
f -= 1
|
||||
if f < 0:
|
||||
print(i+1) # Part 2
|
||||
break
|
|
@ -0,0 +1,23 @@
|
|||
data = '3113322113'
|
||||
|
||||
def iterate(s):
|
||||
lastchar = s[0]
|
||||
lastcount = 1
|
||||
output = []
|
||||
for c in s[1:] + '\x00':
|
||||
if c == lastchar:
|
||||
lastcount += 1
|
||||
else:
|
||||
output += [str(lastcount), lastchar] # [lastchar]*lastcount
|
||||
lastchar = c
|
||||
lastcount = 1
|
||||
return ''.join(output)
|
||||
|
||||
s = data
|
||||
for i in range(40):
|
||||
s = iterate(s)
|
||||
print(len(s)) # Part 1
|
||||
s2 = s
|
||||
for i in range(10): # equivalent to 50 times from starting input. Doesn't really save time though.
|
||||
s2 = iterate(s2)
|
||||
print(len(s2)) # Part 2
|
|
@ -0,0 +1,48 @@
|
|||
data = 'cqjxjnds'
|
||||
#import numpy as np
|
||||
#base26m = np.array([26**n for n in range(7, -1, -1)], dtype=np.int64)
|
||||
#def increment(s):
|
||||
#digits = [ord(c)-97 for c in s]
|
||||
#base26 = np.dot(base26m, digits)
|
||||
#num = base26 + 1
|
||||
#digits2 = []
|
||||
#while num:
|
||||
#digits2.append(num % 26)
|
||||
#num //= 26
|
||||
#digits2 += [0]*(8-len(digits2))
|
||||
#return ''.join([chr(d+97) for d in reversed(digits2)])
|
||||
|
||||
def increment(s):
|
||||
if 'a' <= s[-1] < 'z':
|
||||
inc = 2 if s[-1] in 'hnk' else 1
|
||||
return s[:-1] + chr(ord(s[-1])+inc)
|
||||
else:
|
||||
return increment(s[:-1]) + 'a'
|
||||
|
||||
def is_valid(s):
|
||||
#if 'i' in s or 'o' in s or 'l' in s:
|
||||
#return False
|
||||
straight = False
|
||||
for a, b, c in zip(s[:-2], s[1:-1], s[2:]):
|
||||
if ord(a) == ord(b)-1 == ord(c)-2:
|
||||
straight = True
|
||||
break
|
||||
if not straight:
|
||||
return False
|
||||
pairs = set()
|
||||
for a, b in zip(s[:-1], s[1:]):
|
||||
if a == b:
|
||||
pairs.add(a)
|
||||
if len(pairs) >= 2:
|
||||
return True
|
||||
return False
|
||||
|
||||
password = increment(data)
|
||||
while not is_valid(password):
|
||||
password = increment(password)
|
||||
print(password) # Part 1 -- cqkkaabc is not correct?! - actually cqjxxyzz
|
||||
|
||||
password2 = increment(password)
|
||||
while not is_valid(password2):
|
||||
password2 = increment(password2)
|
||||
print(password2) # Part 2
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,15 @@
|
|||
import json
|
||||
number_sum = 0.0
|
||||
def parse_int(val):
|
||||
i = int(val)
|
||||
global number_sum
|
||||
number_sum += i
|
||||
return i
|
||||
def parse_float(val):
|
||||
i = float(val)
|
||||
global number_sum
|
||||
number_sum += i
|
||||
return i
|
||||
with open('day12-input', 'r') as file:
|
||||
data = json.load(file, parse_float=parse_float, parse_int=parse_int)
|
||||
print(number_sum) # Part 1
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,17 @@
|
|||
with open('day2-input', 'r') as file:
|
||||
data = [l.strip('\n') for l in file]
|
||||
dimensions = [[int(x) for x in d.split('x')] for d in data]
|
||||
|
||||
def area(l, w, h):
|
||||
sides = [l*w, w*h, h*l]
|
||||
slack = min(sides)
|
||||
return 2*sum(sides) + slack
|
||||
|
||||
print(sum([area(*present) for present in dimensions])) # Part 1
|
||||
|
||||
def ribbon(l, w, h):
|
||||
perimeter = 2 * (sum([l,w,h])-max([l,w,h]))
|
||||
volume = l*w*h
|
||||
return perimeter + volume
|
||||
|
||||
print(sum([ribbon(*present) for present in dimensions])) # Part 2
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,47 @@
|
|||
with open('day3-input', 'r') as file:
|
||||
data = file.readlines()
|
||||
|
||||
x = 0
|
||||
y = 0
|
||||
houses = set()
|
||||
houses.add((x, y))
|
||||
for c in data[0]:
|
||||
if c == '>':
|
||||
x += 1
|
||||
elif c == '<':
|
||||
x -= 1
|
||||
elif c == '^':
|
||||
y += 1
|
||||
elif c == 'v':
|
||||
y -= 1
|
||||
houses.add((x, y))
|
||||
print(len(houses)) # Part 1
|
||||
|
||||
x1 = 0
|
||||
y1 = 0
|
||||
x2 = 0
|
||||
y2 = 0
|
||||
houses2 = set()
|
||||
houses2.add((0, 0))
|
||||
for i, c in enumerate(data[0]):
|
||||
if i%2:
|
||||
if c == '>':
|
||||
x1 += 1
|
||||
elif c == '<':
|
||||
x1 -= 1
|
||||
elif c == '^':
|
||||
y1 += 1
|
||||
elif c == 'v':
|
||||
y1 -= 1
|
||||
houses2.add((x1, y1))
|
||||
else:
|
||||
if c == '>':
|
||||
x2 += 1
|
||||
elif c == '<':
|
||||
x2 -= 1
|
||||
elif c == '^':
|
||||
y2 += 1
|
||||
elif c == 'v':
|
||||
y2 -= 1
|
||||
houses2.add((x2, y2))
|
||||
print(len(houses2)) # Part 2
|
|
@ -0,0 +1,15 @@
|
|||
data = 'yzbqklnj'
|
||||
from hashlib import md5
|
||||
i = 0
|
||||
while True:
|
||||
i += 1
|
||||
if md5(f'{data}{i}'.encode('utf-8')).hexdigest().startswith('00000'):
|
||||
print(i) # Part 1
|
||||
break
|
||||
|
||||
i -= 1 # Just in case the first hit was 6 zeros
|
||||
while True:
|
||||
i += 1
|
||||
if md5(f'{data}{i}'.encode('utf-8')).hexdigest().startswith('000000'):
|
||||
print(i) # Part 2
|
||||
break
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,34 @@
|
|||
with open('day5-input', 'r') as file:
|
||||
data = [l.strip('\n') for l in file]
|
||||
|
||||
naughty_substrings = ['ab', 'cd', 'pq', 'xy']
|
||||
vowels = set(['a', 'e', 'i', 'o', 'u'])
|
||||
def is_nice(s):
|
||||
for n in naughty_substrings:
|
||||
if n in s:
|
||||
return False
|
||||
v_count = 0
|
||||
rep_count = 0
|
||||
last_char = ''
|
||||
for c in s:
|
||||
if c in vowels:
|
||||
v_count += 1
|
||||
if c == last_char:
|
||||
rep_count += 1
|
||||
last_char = c
|
||||
return v_count >= 3 and rep_count > 0
|
||||
print(len([s for s in data if is_nice(s)])) # Part 1
|
||||
|
||||
def is_nice2(s):
|
||||
spaced_rep = False
|
||||
for a, b in zip(s[:-2], s[2:]):
|
||||
if a == b:
|
||||
spaced_rep = True
|
||||
break
|
||||
if not spaced_rep:
|
||||
return False
|
||||
for a, b in zip(s[:-1], s[1:]):
|
||||
if s.count(a+b) > 1:
|
||||
return True
|
||||
return False
|
||||
print(len([s for s in data if is_nice2(s)])) # Part 2
|
|
@ -0,0 +1,300 @@
|
|||
turn on 887,9 through 959,629
|
||||
turn on 454,398 through 844,448
|
||||
turn off 539,243 through 559,965
|
||||
turn off 370,819 through 676,868
|
||||
turn off 145,40 through 370,997
|
||||
turn off 301,3 through 808,453
|
||||
turn on 351,678 through 951,908
|
||||
toggle 720,196 through 897,994
|
||||
toggle 831,394 through 904,860
|
||||
toggle 753,664 through 970,926
|
||||
turn off 150,300 through 213,740
|
||||
turn on 141,242 through 932,871
|
||||
toggle 294,259 through 474,326
|
||||
toggle 678,333 through 752,957
|
||||
toggle 393,804 through 510,976
|
||||
turn off 6,964 through 411,976
|
||||
turn off 33,572 through 978,590
|
||||
turn on 579,693 through 650,978
|
||||
turn on 150,20 through 652,719
|
||||
turn off 782,143 through 808,802
|
||||
turn off 240,377 through 761,468
|
||||
turn off 899,828 through 958,967
|
||||
turn on 613,565 through 952,659
|
||||
turn on 295,36 through 964,978
|
||||
toggle 846,296 through 969,528
|
||||
turn off 211,254 through 529,491
|
||||
turn off 231,594 through 406,794
|
||||
turn off 169,791 through 758,942
|
||||
turn on 955,440 through 980,477
|
||||
toggle 944,498 through 995,928
|
||||
turn on 519,391 through 605,718
|
||||
toggle 521,303 through 617,366
|
||||
turn off 524,349 through 694,791
|
||||
toggle 391,87 through 499,792
|
||||
toggle 562,527 through 668,935
|
||||
turn off 68,358 through 857,453
|
||||
toggle 815,811 through 889,828
|
||||
turn off 666,61 through 768,87
|
||||
turn on 27,501 through 921,952
|
||||
turn on 953,102 through 983,471
|
||||
turn on 277,552 through 451,723
|
||||
turn off 64,253 through 655,960
|
||||
turn on 47,485 through 734,977
|
||||
turn off 59,119 through 699,734
|
||||
toggle 407,898 through 493,955
|
||||
toggle 912,966 through 949,991
|
||||
turn on 479,990 through 895,990
|
||||
toggle 390,589 through 869,766
|
||||
toggle 593,903 through 926,943
|
||||
toggle 358,439 through 870,528
|
||||
turn off 649,410 through 652,875
|
||||
turn on 629,834 through 712,895
|
||||
toggle 254,555 through 770,901
|
||||
toggle 641,832 through 947,850
|
||||
turn on 268,448 through 743,777
|
||||
turn off 512,123 through 625,874
|
||||
turn off 498,262 through 930,811
|
||||
turn off 835,158 through 886,242
|
||||
toggle 546,310 through 607,773
|
||||
turn on 501,505 through 896,909
|
||||
turn off 666,796 through 817,924
|
||||
toggle 987,789 through 993,809
|
||||
toggle 745,8 through 860,693
|
||||
toggle 181,983 through 731,988
|
||||
turn on 826,174 through 924,883
|
||||
turn on 239,228 through 843,993
|
||||
turn on 205,613 through 891,667
|
||||
toggle 867,873 through 984,896
|
||||
turn on 628,251 through 677,681
|
||||
toggle 276,956 through 631,964
|
||||
turn on 78,358 through 974,713
|
||||
turn on 521,360 through 773,597
|
||||
turn off 963,52 through 979,502
|
||||
turn on 117,151 through 934,622
|
||||
toggle 237,91 through 528,164
|
||||
turn on 944,269 through 975,453
|
||||
toggle 979,460 through 988,964
|
||||
turn off 440,254 through 681,507
|
||||
toggle 347,100 through 896,785
|
||||
turn off 329,592 through 369,985
|
||||
turn on 931,960 through 979,985
|
||||
toggle 703,3 through 776,36
|
||||
toggle 798,120 through 908,550
|
||||
turn off 186,605 through 914,709
|
||||
turn off 921,725 through 979,956
|
||||
toggle 167,34 through 735,249
|
||||
turn on 726,781 through 987,936
|
||||
toggle 720,336 through 847,756
|
||||
turn on 171,630 through 656,769
|
||||
turn off 417,276 through 751,500
|
||||
toggle 559,485 through 584,534
|
||||
turn on 568,629 through 690,873
|
||||
toggle 248,712 through 277,988
|
||||
toggle 345,594 through 812,723
|
||||
turn off 800,108 through 834,618
|
||||
turn off 967,439 through 986,869
|
||||
turn on 842,209 through 955,529
|
||||
turn on 132,653 through 357,696
|
||||
turn on 817,38 through 973,662
|
||||
turn off 569,816 through 721,861
|
||||
turn on 568,429 through 945,724
|
||||
turn on 77,458 through 844,685
|
||||
turn off 138,78 through 498,851
|
||||
turn on 136,21 through 252,986
|
||||
turn off 2,460 through 863,472
|
||||
turn on 172,81 through 839,332
|
||||
turn on 123,216 through 703,384
|
||||
turn off 879,644 through 944,887
|
||||
toggle 227,491 through 504,793
|
||||
toggle 580,418 through 741,479
|
||||
toggle 65,276 through 414,299
|
||||
toggle 482,486 through 838,931
|
||||
turn off 557,768 through 950,927
|
||||
turn off 615,617 through 955,864
|
||||
turn on 859,886 through 923,919
|
||||
turn on 391,330 through 499,971
|
||||
toggle 521,835 through 613,847
|
||||
turn on 822,787 through 989,847
|
||||
turn on 192,142 through 357,846
|
||||
turn off 564,945 through 985,945
|
||||
turn off 479,361 through 703,799
|
||||
toggle 56,481 through 489,978
|
||||
turn off 632,991 through 774,998
|
||||
toggle 723,526 through 945,792
|
||||
turn on 344,149 through 441,640
|
||||
toggle 568,927 through 624,952
|
||||
turn on 621,784 through 970,788
|
||||
toggle 665,783 through 795,981
|
||||
toggle 386,610 through 817,730
|
||||
toggle 440,399 through 734,417
|
||||
toggle 939,201 through 978,803
|
||||
turn off 395,883 through 554,929
|
||||
turn on 340,309 through 637,561
|
||||
turn off 875,147 through 946,481
|
||||
turn off 945,837 through 957,922
|
||||
turn off 429,982 through 691,991
|
||||
toggle 227,137 through 439,822
|
||||
toggle 4,848 through 7,932
|
||||
turn off 545,146 through 756,943
|
||||
turn on 763,863 through 937,994
|
||||
turn on 232,94 through 404,502
|
||||
turn off 742,254 through 930,512
|
||||
turn on 91,931 through 101,942
|
||||
toggle 585,106 through 651,425
|
||||
turn on 506,700 through 567,960
|
||||
turn off 548,44 through 718,352
|
||||
turn off 194,827 through 673,859
|
||||
turn off 6,645 through 509,764
|
||||
turn off 13,230 through 821,361
|
||||
turn on 734,629 through 919,631
|
||||
toggle 788,552 through 957,972
|
||||
toggle 244,747 through 849,773
|
||||
turn off 162,553 through 276,887
|
||||
turn off 569,577 through 587,604
|
||||
turn off 799,482 through 854,956
|
||||
turn on 744,535 through 909,802
|
||||
toggle 330,641 through 396,986
|
||||
turn off 927,458 through 966,564
|
||||
toggle 984,486 through 986,913
|
||||
toggle 519,682 through 632,708
|
||||
turn on 984,977 through 989,986
|
||||
toggle 766,423 through 934,495
|
||||
turn on 17,509 through 947,718
|
||||
turn on 413,783 through 631,903
|
||||
turn on 482,370 through 493,688
|
||||
turn on 433,859 through 628,938
|
||||
turn off 769,549 through 945,810
|
||||
turn on 178,853 through 539,941
|
||||
turn off 203,251 through 692,433
|
||||
turn off 525,638 through 955,794
|
||||
turn on 169,70 through 764,939
|
||||
toggle 59,352 through 896,404
|
||||
toggle 143,245 through 707,320
|
||||
turn off 103,35 through 160,949
|
||||
toggle 496,24 through 669,507
|
||||
turn off 581,847 through 847,903
|
||||
turn on 689,153 through 733,562
|
||||
turn on 821,487 through 839,699
|
||||
turn on 837,627 through 978,723
|
||||
toggle 96,748 through 973,753
|
||||
toggle 99,818 through 609,995
|
||||
turn on 731,193 through 756,509
|
||||
turn off 622,55 through 813,365
|
||||
turn on 456,490 through 576,548
|
||||
turn on 48,421 through 163,674
|
||||
turn off 853,861 through 924,964
|
||||
turn off 59,963 through 556,987
|
||||
turn on 458,710 through 688,847
|
||||
toggle 12,484 through 878,562
|
||||
turn off 241,964 through 799,983
|
||||
turn off 434,299 through 845,772
|
||||
toggle 896,725 through 956,847
|
||||
turn on 740,289 through 784,345
|
||||
turn off 395,840 through 822,845
|
||||
turn on 955,224 through 996,953
|
||||
turn off 710,186 through 957,722
|
||||
turn off 485,949 through 869,985
|
||||
turn on 848,209 through 975,376
|
||||
toggle 221,241 through 906,384
|
||||
turn on 588,49 through 927,496
|
||||
turn on 273,332 through 735,725
|
||||
turn on 505,962 through 895,962
|
||||
toggle 820,112 through 923,143
|
||||
turn on 919,792 through 978,982
|
||||
toggle 489,461 through 910,737
|
||||
turn off 202,642 through 638,940
|
||||
turn off 708,953 through 970,960
|
||||
toggle 437,291 through 546,381
|
||||
turn on 409,358 through 837,479
|
||||
turn off 756,279 through 870,943
|
||||
turn off 154,657 through 375,703
|
||||
turn off 524,622 through 995,779
|
||||
toggle 514,221 through 651,850
|
||||
toggle 808,464 through 886,646
|
||||
toggle 483,537 through 739,840
|
||||
toggle 654,769 through 831,825
|
||||
turn off 326,37 through 631,69
|
||||
turn off 590,570 through 926,656
|
||||
turn off 881,913 through 911,998
|
||||
turn on 996,102 through 998,616
|
||||
turn off 677,503 through 828,563
|
||||
turn on 860,251 through 877,441
|
||||
turn off 964,100 through 982,377
|
||||
toggle 888,403 through 961,597
|
||||
turn off 632,240 through 938,968
|
||||
toggle 731,176 through 932,413
|
||||
turn on 5,498 through 203,835
|
||||
turn on 819,352 through 929,855
|
||||
toggle 393,813 through 832,816
|
||||
toggle 725,689 through 967,888
|
||||
turn on 968,950 through 969,983
|
||||
turn off 152,628 through 582,896
|
||||
turn off 165,844 through 459,935
|
||||
turn off 882,741 through 974,786
|
||||
turn off 283,179 through 731,899
|
||||
toggle 197,366 through 682,445
|
||||
turn on 106,309 through 120,813
|
||||
toggle 950,387 through 967,782
|
||||
turn off 274,603 through 383,759
|
||||
turn off 155,665 through 284,787
|
||||
toggle 551,871 through 860,962
|
||||
turn off 30,826 through 598,892
|
||||
toggle 76,552 through 977,888
|
||||
turn on 938,180 through 994,997
|
||||
toggle 62,381 through 993,656
|
||||
toggle 625,861 through 921,941
|
||||
turn on 685,311 through 872,521
|
||||
turn on 124,934 through 530,962
|
||||
turn on 606,379 through 961,867
|
||||
turn off 792,735 through 946,783
|
||||
turn on 417,480 through 860,598
|
||||
toggle 178,91 through 481,887
|
||||
turn off 23,935 through 833,962
|
||||
toggle 317,14 through 793,425
|
||||
turn on 986,89 through 999,613
|
||||
turn off 359,201 through 560,554
|
||||
turn off 729,494 through 942,626
|
||||
turn on 204,143 through 876,610
|
||||
toggle 474,97 through 636,542
|
||||
turn off 902,924 through 976,973
|
||||
turn off 389,442 through 824,638
|
||||
turn off 622,863 through 798,863
|
||||
turn on 840,622 through 978,920
|
||||
toggle 567,374 through 925,439
|
||||
turn off 643,319 through 935,662
|
||||
toggle 185,42 through 294,810
|
||||
turn on 47,124 through 598,880
|
||||
toggle 828,303 through 979,770
|
||||
turn off 174,272 through 280,311
|
||||
turn off 540,50 through 880,212
|
||||
turn on 141,994 through 221,998
|
||||
turn on 476,695 through 483,901
|
||||
turn on 960,216 through 972,502
|
||||
toggle 752,335 through 957,733
|
||||
turn off 419,713 through 537,998
|
||||
toggle 772,846 through 994,888
|
||||
turn on 881,159 through 902,312
|
||||
turn off 537,651 through 641,816
|
||||
toggle 561,947 through 638,965
|
||||
turn on 368,458 through 437,612
|
||||
turn on 290,149 through 705,919
|
||||
turn on 711,918 through 974,945
|
||||
toggle 916,242 through 926,786
|
||||
toggle 522,272 through 773,314
|
||||
turn on 432,897 through 440,954
|
||||
turn off 132,169 through 775,380
|
||||
toggle 52,205 through 693,747
|
||||
toggle 926,309 through 976,669
|
||||
turn off 838,342 through 938,444
|
||||
turn on 144,431 through 260,951
|
||||
toggle 780,318 through 975,495
|
||||
turn off 185,412 through 796,541
|
||||
turn on 879,548 through 892,860
|
||||
turn on 294,132 through 460,338
|
||||
turn on 823,500 through 899,529
|
||||
turn off 225,603 through 483,920
|
||||
toggle 717,493 through 930,875
|
||||
toggle 534,948 through 599,968
|
||||
turn on 522,730 through 968,950
|
||||
turn off 102,229 through 674,529
|
|
@ -0,0 +1,33 @@
|
|||
with open('day6-input', 'r') as file:
|
||||
data = [l.strip('\n') for l in file]
|
||||
import numpy as np
|
||||
lights = np.zeros((1000,1000), dtype=np.int8)
|
||||
|
||||
for line in data:
|
||||
tokens = line.split(' ')
|
||||
x1, y1 = [int(i) for i in tokens[-3].split(',')]
|
||||
x2, y2 = [int(i)+1 for i in tokens[-1].split(',')] # inclusive
|
||||
if tokens[0] == 'toggle':
|
||||
lights[x1:x2, y1:y2] ^= 1
|
||||
else: # elif tokens[0] == 'turn':
|
||||
if tokens[1] == 'on':
|
||||
lights[x1:x2, y1:y2] = 1
|
||||
else: # Off
|
||||
lights[x1:x2, y1:y2] = 0
|
||||
print(np.sum(lights)) # Part 1
|
||||
|
||||
lights2 = np.zeros((1000,1000), dtype=np.int32)
|
||||
|
||||
for line in data:
|
||||
tokens = line.split(' ')
|
||||
x1, y1 = [int(i) for i in tokens[-3].split(',')]
|
||||
x2, y2 = [int(i)+1 for i in tokens[-1].split(',')] # inclusive
|
||||
if tokens[0] == 'toggle':
|
||||
lights2[x1:x2, y1:y2] += 2
|
||||
else: # elif tokens[0] == 'turn':
|
||||
if tokens[1] == 'on':
|
||||
lights2[x1:x2, y1:y2] += 1
|
||||
else: # Off
|
||||
lights2[x1:x2, y1:y2] -= 1
|
||||
np.clip(lights2[x1:x2, y1:y2], 0, None, out=lights2[x1:x2, y1:y2])
|
||||
print(np.sum(lights2)) # Part 2
|
|
@ -0,0 +1,339 @@
|
|||
lf AND lq -> ls
|
||||
iu RSHIFT 1 -> jn
|
||||
bo OR bu -> bv
|
||||
gj RSHIFT 1 -> hc
|
||||
et RSHIFT 2 -> eu
|
||||
bv AND bx -> by
|
||||
is OR it -> iu
|
||||
b OR n -> o
|
||||
gf OR ge -> gg
|
||||
NOT kt -> ku
|
||||
ea AND eb -> ed
|
||||
kl OR kr -> ks
|
||||
hi AND hk -> hl
|
||||
au AND av -> ax
|
||||
lf RSHIFT 2 -> lg
|
||||
dd RSHIFT 3 -> df
|
||||
eu AND fa -> fc
|
||||
df AND dg -> di
|
||||
ip LSHIFT 15 -> it
|
||||
NOT el -> em
|
||||
et OR fe -> ff
|
||||
fj LSHIFT 15 -> fn
|
||||
t OR s -> u
|
||||
ly OR lz -> ma
|
||||
ko AND kq -> kr
|
||||
NOT fx -> fy
|
||||
et RSHIFT 1 -> fm
|
||||
eu OR fa -> fb
|
||||
dd RSHIFT 2 -> de
|
||||
NOT go -> gp
|
||||
kb AND kd -> ke
|
||||
hg OR hh -> hi
|
||||
jm LSHIFT 1 -> kg
|
||||
NOT cn -> co
|
||||
jp RSHIFT 2 -> jq
|
||||
jp RSHIFT 5 -> js
|
||||
1 AND io -> ip
|
||||
eo LSHIFT 15 -> es
|
||||
1 AND jj -> jk
|
||||
g AND i -> j
|
||||
ci RSHIFT 3 -> ck
|
||||
gn AND gp -> gq
|
||||
fs AND fu -> fv
|
||||
lj AND ll -> lm
|
||||
jk LSHIFT 15 -> jo
|
||||
iu RSHIFT 3 -> iw
|
||||
NOT ii -> ij
|
||||
1 AND cc -> cd
|
||||
bn RSHIFT 3 -> bp
|
||||
NOT gw -> gx
|
||||
NOT ft -> fu
|
||||
jn OR jo -> jp
|
||||
iv OR jb -> jc
|
||||
hv OR hu -> hw
|
||||
19138 -> b
|
||||
gj RSHIFT 5 -> gm
|
||||
hq AND hs -> ht
|
||||
dy RSHIFT 1 -> er
|
||||
ao OR an -> ap
|
||||
ld OR le -> lf
|
||||
bk LSHIFT 1 -> ce
|
||||
bz AND cb -> cc
|
||||
bi LSHIFT 15 -> bm
|
||||
il AND in -> io
|
||||
af AND ah -> ai
|
||||
as RSHIFT 1 -> bl
|
||||
lf RSHIFT 3 -> lh
|
||||
er OR es -> et
|
||||
NOT ax -> ay
|
||||
ci RSHIFT 1 -> db
|
||||
et AND fe -> fg
|
||||
lg OR lm -> ln
|
||||
k AND m -> n
|
||||
hz RSHIFT 2 -> ia
|
||||
kh LSHIFT 1 -> lb
|
||||
NOT ey -> ez
|
||||
NOT di -> dj
|
||||
dz OR ef -> eg
|
||||
lx -> a
|
||||
NOT iz -> ja
|
||||
gz LSHIFT 15 -> hd
|
||||
ce OR cd -> cf
|
||||
fq AND fr -> ft
|
||||
at AND az -> bb
|
||||
ha OR gz -> hb
|
||||
fp AND fv -> fx
|
||||
NOT gb -> gc
|
||||
ia AND ig -> ii
|
||||
gl OR gm -> gn
|
||||
0 -> c
|
||||
NOT ca -> cb
|
||||
bn RSHIFT 1 -> cg
|
||||
c LSHIFT 1 -> t
|
||||
iw OR ix -> iy
|
||||
kg OR kf -> kh
|
||||
dy OR ej -> ek
|
||||
km AND kn -> kp
|
||||
NOT fc -> fd
|
||||
hz RSHIFT 3 -> ib
|
||||
NOT dq -> dr
|
||||
NOT fg -> fh
|
||||
dy RSHIFT 2 -> dz
|
||||
kk RSHIFT 2 -> kl
|
||||
1 AND fi -> fj
|
||||
NOT hr -> hs
|
||||
jp RSHIFT 1 -> ki
|
||||
bl OR bm -> bn
|
||||
1 AND gy -> gz
|
||||
gr AND gt -> gu
|
||||
db OR dc -> dd
|
||||
de OR dk -> dl
|
||||
as RSHIFT 5 -> av
|
||||
lf RSHIFT 5 -> li
|
||||
hm AND ho -> hp
|
||||
cg OR ch -> ci
|
||||
gj AND gu -> gw
|
||||
ge LSHIFT 15 -> gi
|
||||
e OR f -> g
|
||||
fp OR fv -> fw
|
||||
fb AND fd -> fe
|
||||
cd LSHIFT 15 -> ch
|
||||
b RSHIFT 1 -> v
|
||||
at OR az -> ba
|
||||
bn RSHIFT 2 -> bo
|
||||
lh AND li -> lk
|
||||
dl AND dn -> do
|
||||
eg AND ei -> ej
|
||||
ex AND ez -> fa
|
||||
NOT kp -> kq
|
||||
NOT lk -> ll
|
||||
x AND ai -> ak
|
||||
jp OR ka -> kb
|
||||
NOT jd -> je
|
||||
iy AND ja -> jb
|
||||
jp RSHIFT 3 -> jr
|
||||
fo OR fz -> ga
|
||||
df OR dg -> dh
|
||||
gj RSHIFT 2 -> gk
|
||||
gj OR gu -> gv
|
||||
NOT jh -> ji
|
||||
ap LSHIFT 1 -> bj
|
||||
NOT ls -> lt
|
||||
ir LSHIFT 1 -> jl
|
||||
bn AND by -> ca
|
||||
lv LSHIFT 15 -> lz
|
||||
ba AND bc -> bd
|
||||
cy LSHIFT 15 -> dc
|
||||
ln AND lp -> lq
|
||||
x RSHIFT 1 -> aq
|
||||
gk OR gq -> gr
|
||||
NOT kx -> ky
|
||||
jg AND ji -> jj
|
||||
bn OR by -> bz
|
||||
fl LSHIFT 1 -> gf
|
||||
bp OR bq -> br
|
||||
he OR hp -> hq
|
||||
et RSHIFT 5 -> ew
|
||||
iu RSHIFT 2 -> iv
|
||||
gl AND gm -> go
|
||||
x OR ai -> aj
|
||||
hc OR hd -> he
|
||||
lg AND lm -> lo
|
||||
lh OR li -> lj
|
||||
da LSHIFT 1 -> du
|
||||
fo RSHIFT 2 -> fp
|
||||
gk AND gq -> gs
|
||||
bj OR bi -> bk
|
||||
lf OR lq -> lr
|
||||
cj AND cp -> cr
|
||||
hu LSHIFT 15 -> hy
|
||||
1 AND bh -> bi
|
||||
fo RSHIFT 3 -> fq
|
||||
NOT lo -> lp
|
||||
hw LSHIFT 1 -> iq
|
||||
dd RSHIFT 1 -> dw
|
||||
dt LSHIFT 15 -> dx
|
||||
dy AND ej -> el
|
||||
an LSHIFT 15 -> ar
|
||||
aq OR ar -> as
|
||||
1 AND r -> s
|
||||
fw AND fy -> fz
|
||||
NOT im -> in
|
||||
et RSHIFT 3 -> ev
|
||||
1 AND ds -> dt
|
||||
ec AND ee -> ef
|
||||
NOT ak -> al
|
||||
jl OR jk -> jm
|
||||
1 AND en -> eo
|
||||
lb OR la -> lc
|
||||
iu AND jf -> jh
|
||||
iu RSHIFT 5 -> ix
|
||||
bo AND bu -> bw
|
||||
cz OR cy -> da
|
||||
iv AND jb -> jd
|
||||
iw AND ix -> iz
|
||||
lf RSHIFT 1 -> ly
|
||||
iu OR jf -> jg
|
||||
NOT dm -> dn
|
||||
lw OR lv -> lx
|
||||
gg LSHIFT 1 -> ha
|
||||
lr AND lt -> lu
|
||||
fm OR fn -> fo
|
||||
he RSHIFT 3 -> hg
|
||||
aj AND al -> am
|
||||
1 AND kz -> la
|
||||
dy RSHIFT 5 -> eb
|
||||
jc AND je -> jf
|
||||
cm AND co -> cp
|
||||
gv AND gx -> gy
|
||||
ev OR ew -> ex
|
||||
jp AND ka -> kc
|
||||
fk OR fj -> fl
|
||||
dy RSHIFT 3 -> ea
|
||||
NOT bs -> bt
|
||||
NOT ag -> ah
|
||||
dz AND ef -> eh
|
||||
cf LSHIFT 1 -> cz
|
||||
NOT cv -> cw
|
||||
1 AND cx -> cy
|
||||
de AND dk -> dm
|
||||
ck AND cl -> cn
|
||||
x RSHIFT 5 -> aa
|
||||
dv LSHIFT 1 -> ep
|
||||
he RSHIFT 2 -> hf
|
||||
NOT bw -> bx
|
||||
ck OR cl -> cm
|
||||
bp AND bq -> bs
|
||||
as OR bd -> be
|
||||
he AND hp -> hr
|
||||
ev AND ew -> ey
|
||||
1 AND lu -> lv
|
||||
kk RSHIFT 3 -> km
|
||||
b AND n -> p
|
||||
NOT kc -> kd
|
||||
lc LSHIFT 1 -> lw
|
||||
km OR kn -> ko
|
||||
id AND if -> ig
|
||||
ih AND ij -> ik
|
||||
jr AND js -> ju
|
||||
ci RSHIFT 5 -> cl
|
||||
hz RSHIFT 1 -> is
|
||||
1 AND ke -> kf
|
||||
NOT gs -> gt
|
||||
aw AND ay -> az
|
||||
x RSHIFT 2 -> y
|
||||
ab AND ad -> ae
|
||||
ff AND fh -> fi
|
||||
ci AND ct -> cv
|
||||
eq LSHIFT 1 -> fk
|
||||
gj RSHIFT 3 -> gl
|
||||
u LSHIFT 1 -> ao
|
||||
NOT bb -> bc
|
||||
NOT hj -> hk
|
||||
kw AND ky -> kz
|
||||
as AND bd -> bf
|
||||
dw OR dx -> dy
|
||||
br AND bt -> bu
|
||||
kk AND kv -> kx
|
||||
ep OR eo -> eq
|
||||
he RSHIFT 1 -> hx
|
||||
ki OR kj -> kk
|
||||
NOT ju -> jv
|
||||
ek AND em -> en
|
||||
kk RSHIFT 5 -> kn
|
||||
NOT eh -> ei
|
||||
hx OR hy -> hz
|
||||
ea OR eb -> ec
|
||||
s LSHIFT 15 -> w
|
||||
fo RSHIFT 1 -> gh
|
||||
kk OR kv -> kw
|
||||
bn RSHIFT 5 -> bq
|
||||
NOT ed -> ee
|
||||
1 AND ht -> hu
|
||||
cu AND cw -> cx
|
||||
b RSHIFT 5 -> f
|
||||
kl AND kr -> kt
|
||||
iq OR ip -> ir
|
||||
ci RSHIFT 2 -> cj
|
||||
cj OR cp -> cq
|
||||
o AND q -> r
|
||||
dd RSHIFT 5 -> dg
|
||||
b RSHIFT 2 -> d
|
||||
ks AND ku -> kv
|
||||
b RSHIFT 3 -> e
|
||||
d OR j -> k
|
||||
NOT p -> q
|
||||
NOT cr -> cs
|
||||
du OR dt -> dv
|
||||
kf LSHIFT 15 -> kj
|
||||
NOT ac -> ad
|
||||
fo RSHIFT 5 -> fr
|
||||
hz OR ik -> il
|
||||
jx AND jz -> ka
|
||||
gh OR gi -> gj
|
||||
kk RSHIFT 1 -> ld
|
||||
hz RSHIFT 5 -> ic
|
||||
as RSHIFT 2 -> at
|
||||
NOT jy -> jz
|
||||
1 AND am -> an
|
||||
ci OR ct -> cu
|
||||
hg AND hh -> hj
|
||||
jq OR jw -> jx
|
||||
v OR w -> x
|
||||
la LSHIFT 15 -> le
|
||||
dh AND dj -> dk
|
||||
dp AND dr -> ds
|
||||
jq AND jw -> jy
|
||||
au OR av -> aw
|
||||
NOT bf -> bg
|
||||
z OR aa -> ab
|
||||
ga AND gc -> gd
|
||||
hz AND ik -> im
|
||||
jt AND jv -> jw
|
||||
z AND aa -> ac
|
||||
jr OR js -> jt
|
||||
hb LSHIFT 1 -> hv
|
||||
hf OR hl -> hm
|
||||
ib OR ic -> id
|
||||
fq OR fr -> fs
|
||||
cq AND cs -> ct
|
||||
ia OR ig -> ih
|
||||
dd OR do -> dp
|
||||
d AND j -> l
|
||||
ib AND ic -> ie
|
||||
as RSHIFT 3 -> au
|
||||
be AND bg -> bh
|
||||
dd AND do -> dq
|
||||
NOT l -> m
|
||||
1 AND gd -> ge
|
||||
y AND ae -> ag
|
||||
fo AND fz -> gb
|
||||
NOT ie -> if
|
||||
e AND f -> h
|
||||
x RSHIFT 3 -> z
|
||||
y OR ae -> af
|
||||
hf AND hl -> hn
|
||||
NOT h -> i
|
||||
NOT hn -> ho
|
||||
he RSHIFT 5 -> hh
|
|
@ -0,0 +1,53 @@
|
|||
with open('day7-input', 'r') as file:
|
||||
data = [l.strip('\n') for l in file]
|
||||
|
||||
bin_ops = {'AND': int.__and__, 'OR': int.__or__, 'RSHIFT': int.__rshift__, 'LSHIFT': int.__lshift__}
|
||||
|
||||
class dict_int_giver(dict):
|
||||
def __init__(self, kvs=[], readonly=None):
|
||||
super().__init__(kvs)
|
||||
self.readonly = set()
|
||||
if readonly:
|
||||
self.readonly = set(readonly)
|
||||
def __getitem__(self, key):
|
||||
try:
|
||||
return int(key.replace(',', ''))
|
||||
except ValueError:
|
||||
return dict.get(self, key, None)
|
||||
def __setitem__(self, key, value):
|
||||
if key in self.readonly:
|
||||
return
|
||||
dict.__setitem__(self, key, value)
|
||||
|
||||
def run_circuit(identifiers):
|
||||
queue = [line for line in data]
|
||||
while queue:
|
||||
line = queue.pop(0)
|
||||
tokens = line.split(' ')
|
||||
output = tokens[-1]
|
||||
input = tokens[:-2]
|
||||
if len(input) == 1: # Can only be a -> b
|
||||
i = identifiers[input[0]]
|
||||
if i is not None:
|
||||
identifiers[output] = i
|
||||
else:
|
||||
queue.append(line)
|
||||
elif len(input) == 2: # Can only be NOT a -> b. a must be identifier.
|
||||
if input[1] in identifiers:
|
||||
identifiers[output] = identifiers[input[1]] ^ 0xFFFF # 16bit values
|
||||
else:
|
||||
queue.append(line)
|
||||
elif len(input) == 3: # Can be any of the binary operators
|
||||
i = identifiers[input[0]]
|
||||
j = identifiers[input[2]]
|
||||
if i is not None and j is not None:
|
||||
identifiers[output] = bin_ops[input[1]](i, j) & 0xFFFF
|
||||
else:
|
||||
queue.append(line)
|
||||
|
||||
identifiers_1 = dict_int_giver()
|
||||
run_circuit(identifiers_1)
|
||||
print(identifiers_1['a']) # Part 1
|
||||
identifiers_2 = dict_int_giver([ ['b', identifiers_1['a'] ] ], ['b'])
|
||||
run_circuit(identifiers_2)
|
||||
print(identifiers_2['a']) # Part 2
|
|
@ -0,0 +1,300 @@
|
|||
"\xa8br\x8bjr\""
|
||||
"nq"
|
||||
"zjrfcpbktjmrzgsz\xcaqsc\x03n\"huqab"
|
||||
"daz\\zyyxddpwk"
|
||||
"draes\xa2n\\g\x27ek\"lj\"\\viqych"
|
||||
"nnx\\krnrfomdnt\x2flbl\xd2xpo\"cp\"k"
|
||||
"kwdaapalq"
|
||||
"u\"ptk"
|
||||
"ckhorczuiudfjmmcc\\u\"wozqxibsfjma"
|
||||
"ydctdrxat\"pd\"lwi\"bjesevfw\xe8"
|
||||
"v\"\xa8rrzep\"\"r"
|
||||
"nbydghkfvmq\\\xe0\"lfsrsvlsj\"i\x61liif"
|
||||
"jsas\"u"
|
||||
"odipikxlo"
|
||||
"\"rnubsgwltqkbsu\"pcpcs"
|
||||
"eitk\\f\\mhcqqoym\\ji"
|
||||
"vnedc"
|
||||
"\"lhcaurdqzyjyu"
|
||||
"haxzsa\"zcn\"y\"foclgtjfcnv\"m\x68krc"
|
||||
"\"eoeggg\"tmiydvcay\"vfavc"
|
||||
"snqvyqoncwxcvwbdktoywch"
|
||||
"rnfgjsyr\xd5wacy"
|
||||
"ik\"hebrpvsts"
|
||||
"txw"
|
||||
"\x15pxtdkogd\"urbm\"gevhh\"nxr\x3erxtk"
|
||||
"cetqtcy"
|
||||
"inleep\\mgl"
|
||||
"uflwbxvww\x2cxzezqnaply\"yh\"qlllzk"
|
||||
"eepak\"xqtedzt"
|
||||
"na\x61qzfieafvyrsnwkssznohjmc"
|
||||
"yceaonylz\xc1\\jrlbbkzwsidfi"
|
||||
"ybqafngkcqpbp"
|
||||
"\xaft"
|
||||
"yidjpaobqydso"
|
||||
"ju\\ldxig\\lrdrhjcmm\x77rc"
|
||||
"tylacqeslnwj\x48ds\"tjxa"
|
||||
"efbfm"
|
||||
"\\fxkgoprgdcjgyajykg\\dtbrz"
|
||||
"eujvva"
|
||||
"h\x7acwfpikme\\vwthyvrqdnx\""
|
||||
"rbpbrxm\\\"\"\"voxx"
|
||||
"ykiw\"tkb\\lforu\"rsf\\tf\"x\"rqti"
|
||||
"e\\wh\x77aqeugiq\\ihhfqfuaij"
|
||||
"g\"t\\o"
|
||||
"nxzo\"hf\\xp"
|
||||
"dxiaqfo\xea"
|
||||
"kali\\zczhiqkqzybjj\"fgdjnik"
|
||||
"zdkgrqmdv"
|
||||
"bimxim\xb6lrwsaj\"ui\"a"
|
||||
"\"rrznitibgx\\olpsjmjqzctxaubdifsq"
|
||||
"zb\"khzixaacmhuzmlymoformipdzml"
|
||||
"qfwi"
|
||||
"hjwsxfpphttjy\"\"zixais\xbblgnqfto"
|
||||
"puj\\qmyu\"nqgaqfthbwjokbmrpbhpi"
|
||||
"cyxdpkh\\\""
|
||||
"q"
|
||||
"m"
|
||||
"tbxdzzllarlo"
|
||||
"gbtys"
|
||||
"gytilk\\vlqxvcuutjunrqc"
|
||||
"uugkvcuzan\\eyhb"
|
||||
"yaxr\"genlbgw\"\\uc"
|
||||
"nrgecjeip\\sjdvgqaqxwsqactopu"
|
||||
"pu\"r\"txpyrkfny\\zmwfneyvwmnkkdipv"
|
||||
"jm\xa3bhwvq"
|
||||
"qxojmnml\"w\x9airr"
|
||||
"xbzsuihs\x4dcedy\xaclrhgii\\\""
|
||||
"drgjirusrekrwmvxllwdm"
|
||||
"\x28hfxnfpycmpnkku\"csuf\xaarxlqyg\"x"
|
||||
"\"zvz\\rmg\"\\sxxoifffyqfyn\"iq\"ps"
|
||||
"\"z"
|
||||
"zbwkmk\"sgzos\x93gtc\""
|
||||
"bvm\x28aa\\\\\"pywuhaniox\\z\\hbp\xd7mold"
|
||||
"aszgvsyna"
|
||||
"qf\"vdwuss"
|
||||
"lnohni\"qwiacjsjegstlbfq\\kyjhyd"
|
||||
"c\\naawulxlqplnacvytspry\xf5ytxxqq"
|
||||
"razwqmsqgbaaxcd\\f"
|
||||
"radggyrjrg\"zx"
|
||||
"\"pu\x11t\\ajcjuieinlkvya"
|
||||
"veggiskh"
|
||||
"eglfhjxiet\"kouqfskwsy\"hpthsldel"
|
||||
"mv\xc1b\"f\\shrssnjwcpmurepdxdlcj"
|
||||
"dlayjd\"suvzotgdtc"
|
||||
"\xa9pvxeopn"
|
||||
"lpplsaxy\"oiwaq"
|
||||
"hqwh\\lusv"
|
||||
"hykykwlx\"\xa5atkgh\\d\x63dff"
|
||||
"vfktanpjy\"xxetc"
|
||||
"dnhwkgjnsmsswfuelvihvjl\"jtf"
|
||||
"x\"dwvzra\"nbbsewftehczgbvfzd\"rau"
|
||||
"csfi\"mzejnjqkqupwadrgti\"von"
|
||||
"xckf\xf7xsm\\pgvlpetjndpyblais\\z"
|
||||
"yecy\x6fuj\x58bwpgeuiw\"mdu"
|
||||
"fgb"
|
||||
"c\\lx\x3efthet\xfdelgvwvpem"
|
||||
"kgyrmarvfwjinlowt"
|
||||
"yzte"
|
||||
"vc\"z"
|
||||
"sxevqfzmmdwsuu\""
|
||||
"fxbaercmcy\xb6md"
|
||||
"f"
|
||||
"m\x44gqbcppho\\b"
|
||||
"gtafr\x57m\x11jy\"\"erwmmpiwjkbckuw"
|
||||
"ufdjt\"kssprzxqixzxmq\x58q"
|
||||
"yzbyo\"lfdbyaxexyfbnyv\\\xe8xmre"
|
||||
"u\x43ntr\\\\byyfjr\"iveujvnwsqbnpuvrta"
|
||||
"us\xf6bai"
|
||||
"c\\edh"
|
||||
"tzckolphexfq\\\x23\xfbdqv\\\"m"
|
||||
"yjafhbvhhj\x1b\"bplb"
|
||||
"\"o"
|
||||
"rubahvmp\""
|
||||
"qmkukrnrmqumh"
|
||||
"wdpxyvyidhwjf\\nabbijwhr\xc5bksvy\"p"
|
||||
"u\"prlpg\""
|
||||
"nsvcquyxbwilsxxemf\xd9leq"
|
||||
"y\xcetxuafl"
|
||||
"it"
|
||||
"kwdlysf\\xjpelae"
|
||||
"viwh\x58wpjjlnvryuti\x2chngrx\\nhtkui"
|
||||
"vhn\x9ehre\xc3ncsqbozms\"nl"
|
||||
"ytc\xa3mgeeogjcqavmmmd"
|
||||
"xzlexlitseozoxtpzzutfq"
|
||||
"cish\x07lmovj"
|
||||
"ekbflwqzaiivdr\"pq\\azrfbntqwkn"
|
||||
"uc\"xdbegmlmhksofzohavtrnxf"
|
||||
"xfdnrdqdrcjzbe"
|
||||
"ndg\"ckgrpisib\"rg\"p\\lmpfzlssnvk"
|
||||
"witfjwpbyyzlop"
|
||||
"zonlww\"emrbcsgdtrg\"rjzy\x64zqntlw"
|
||||
"dvgb\"zn\\vrbzema\"ckmd"
|
||||
"\\vdlmxhlvldk\"pmzazeip"
|
||||
"\"\"r"
|
||||
"rsntinv"
|
||||
"iy"
|
||||
"lr\x20efh"
|
||||
"csgexlb\"zqdavlxxhtdbh\"\"\x0fkpvhiphm"
|
||||
"ouwhp\"ogbft"
|
||||
"cm\\ckltng\"dw\x8brf\xf0eppgckd"
|
||||
"zmnlsgalhpkejsizfsbtnfliu\"nhc"
|
||||
"pnrkaayqvwpdjbhcrbb\"yfeq\"aq"
|
||||
"ozh\\hoxow\x2csrtr\\r\""
|
||||
"bqxabj\"u\\s"
|
||||
"cpsjti\"gy"
|
||||
"aa\"p\\nki\\ajijkqev"
|
||||
"q\"\"lfdentjgd\\"
|
||||
"bmokvpoebutfki"
|
||||
"pielvcbne\xf6efvzxn"
|
||||
"kx"
|
||||
"zlgmqagcrbhrwtwtmmg"
|
||||
"aiyhmntcqjbpv\xb5hhswxbryoedvos"
|
||||
"tdpaxrb"
|
||||
"fu\"\x7dttkyvhrlwko"
|
||||
"oirc\\\"cqlnqffjqt\\k"
|
||||
"edxlia\\tcyby"
|
||||
"jpeybgwfayerfrfbvfog\"ol"
|
||||
"ysr"
|
||||
"bzwzilgwfugjk"
|
||||
"tlcc\x75nukvwjgftetjcs\xaecwc"
|
||||
"dsqssa\"vzrf\"sewbp\\ahhlmhbeihlh"
|
||||
"qtgmjck\"n\"guki\"gmdivwqxismqj"
|
||||
"\"f"
|
||||
"wuorvlovucngbzdszqpikyk"
|
||||
"dfrdsacoukmgvhbq\"\"iwto"
|
||||
"\"ey\"ch\\wcgioe\\\"ouvligmsw"
|
||||
"ciqlszzgs"
|
||||
"\\tzyrkaoi\"sopjaq"
|
||||
"lmtnv"
|
||||
"ar\"fqoroigiertjjlm\"ymgi\\kkjewsxd"
|
||||
"wehcimlvudpxtamdn\"rwy"
|
||||
"hr\"zvrwthr\"vruzqfrldn\"b"
|
||||
"sggekodkiwvym\"mhsco"
|
||||
"ltlkfbrrdvk\\"
|
||||
"uut\"sfjnz\"\\ef"
|
||||
"hxilg\\"
|
||||
"zsredsiwlzrpedibn"
|
||||
"vtfi"
|
||||
"\\h"
|
||||
"qekfrc\xf6wduodbwrguqcng\\n"
|
||||
"\"lljlfdrxftwidn\\pkv\xd9ij"
|
||||
"mrvgqynpehkliuijlpp"
|
||||
"gikjph"
|
||||
"yoxcdrdt\"wbaurnyhoyxoihu"
|
||||
"onmomwuxuammbzxe"
|
||||
"rnrr\\twviz\x61gqaljr\x0dmtw"
|
||||
"r\"vupaoi"
|
||||
"l"
|
||||
"sei"
|
||||
"jwxtdtbkd\\kxd"
|
||||
"\x22v\\"
|
||||
"ahd"
|
||||
"j\"bjqxs"
|
||||
"\\i\x24gglxub\\nzsajokt"
|
||||
"lviwpu\"uxdlh\\zuy\"xqy\"ytdzlx\"r"
|
||||
"kptfmys"
|
||||
"fwxzikfhczkjwyjszqdbkepaeellc"
|
||||
"nlqpsvbrbd\\ns"
|
||||
"qryuwkjiodw\"\"vaqyq\"dmyifm"
|
||||
"tw\x15kdmaudjl\\zorhp\"alwh"
|
||||
"aatrvczesykekkjfyb\"kb"
|
||||
"usqcutbqbxxhucwxo\xc1ltb\"j\"bghjcvws"
|
||||
"ilhsrnzxkz"
|
||||
"bianqfdfdhvw"
|
||||
"hqibqs\x7ax\"qoxqoaqtcsz"
|
||||
"htxtoojbbauztwxuiq\\ngyfy\\obzc"
|
||||
"rxn\\moxlj"
|
||||
"mtus\x84erh\"dbe"
|
||||
"asx\x50huvsitcxadt"
|
||||
"\"bugggtnrc\"\"kl\"hmpu\x83hqrvhpo"
|
||||
"ewisbp\"\"vuzf\\w\x5fvalszdhl"
|
||||
"scusplpwxfnxu\x57\"zynpn\x99xerc\\ri"
|
||||
"m\\kinmkke\x0cl"
|
||||
"xhuzit\x7fd"
|
||||
"kfbo\x04\x50ruqirn"
|
||||
"t\"\"xpbdscmdoug"
|
||||
"punvpsgnbgyxe\"sptmpz"
|
||||
"bxukkazijr"
|
||||
"nxyrcdaoo\"rjkk\"wntehcvcip\"vrd"
|
||||
"rdpvqskmihqaw"
|
||||
"p\\gwdhtqnpgthod"
|
||||
"nwnuf\"\"yebycearom\"nqym\"\xd4sii\xccle"
|
||||
"alda\"ptspo\"wkkv\"zoi\"hkb\"vnntyd"
|
||||
"ixpgpfzbqv"
|
||||
"znui\"\\fzn\x03qozabh\"rva\"pv\x67"
|
||||
"e\"zswmwuk"
|
||||
"hcccygwfa"
|
||||
"ngmace\\rtyllolr\"\x68bw"
|
||||
"\\c\"jyufbry\"ryo\"xpo\x26ecninfeckh\\s"
|
||||
"hdnpngtuc\"dzbvvosn\x31fwtpzbrt"
|
||||
"hesbpd\xd4"
|
||||
"dsdbstuzrdfmrnyntufs\"dmv"
|
||||
"d\xeeibcwhcvkt"
|
||||
"fvzwrsfjdqdmy\"\"v"
|
||||
"ns\"dqafz\\lkyoflnazv\"mn\x37\"o\"yj\"e"
|
||||
"dypilgbwzccayxa\"bnmuernx"
|
||||
"q\xa9ztqrhreb\"\"kxfeyodqb"
|
||||
"iz\xa5qjxqulaawuwz\"rqmpcj\\yel"
|
||||
"z\"\\pq\"\"y\x67zpjtn"
|
||||
"ifxqvivp\"kiiftdoe"
|
||||
"jxzebj\"\x35\"qr\"ecglcutuoyywqumcs\"kk"
|
||||
"q"
|
||||
"yob\x85qmpuwexptczbkrl"
|
||||
"cjiavv\"uudpozvibyycnmxhxpxmpjoz"
|
||||
"xro\\uiqyrcid"
|
||||
"nod\\k"
|
||||
"d\"neiec"
|
||||
"tqyrqvwyvmz\\pzgzzcqsqsrgbqbtapoz"
|
||||
"r\"xvocpeuxfxslgueb\x05kzyyie\"aoec"
|
||||
"\"du\\uirlhcbgv\\cjqhfreqnvn"
|
||||
"zp\x04\x15\"pbjwhrjtmiba"
|
||||
"\\cv\""
|
||||
"k\"rwnb\\hiu\"rqd\"rc\\nyakrhly"
|
||||
"klrmafjzandiddodgz"
|
||||
"xipzhqzhvlpykzcuppx"
|
||||
"zdvrvn\xd0mtfvpylbn\\\\sxcznrzugwznl"
|
||||
"ody\\pvm\"kpjiudzhxazirgxzvumeat\"o"
|
||||
"kllvhdp\"prjikzrrc\"adgpegc\\\"gk"
|
||||
"sqtpug\xbcaauxaamw"
|
||||
"wegxxrrxdvpivrqievfeokmnojsk"
|
||||
"\\bo"
|
||||
"gijhz"
|
||||
"ylowluvabwrigssdgtxdwsiorxev\xdd"
|
||||
"\""
|
||||
"ghnsrnsqtxpygikahkrl"
|
||||
"\"rcfqkbjf\"sgxg\"vnd\\rotn"
|
||||
"ap\"smgsuexjrbuqs\"mpbstogj\"x"
|
||||
"koaunz\\sgt\"opv"
|
||||
"yialiuzwix"
|
||||
"yp\"ndxgwzml\"bt"
|
||||
"lpcjxmggfsy\\szbxccarjkqzasqkb\xcfd\x0c"
|
||||
"x"
|
||||
"mgakc"
|
||||
"vjieunoh\x73fjwx"
|
||||
"erbvv\"qulsd"
|
||||
"mimycrbfhqkarmz"
|
||||
"tihfbgcszuej\"c\xfbvoqskkhbgpaddioo"
|
||||
"mziavkwrmekriqghw"
|
||||
"izk\\tnjd\\ed\\emokvjoc"
|
||||
"c\"nhbqzndro\\g"
|
||||
"usfngdo"
|
||||
"aypljdftvptt"
|
||||
"ym\"afvq\xbcc"
|
||||
"zabi\"wjpvugwhl"
|
||||
"ebvptcjqjhc\"n\"p\"dxrphegr\\"
|
||||
"mzlqqxokhye\xd9\\rffhnzs"
|
||||
"hnipqknwpsjakanuewe"
|
||||
"rqgbfcjdrmiz\"h"
|
||||
"kzzp\\z\\txmkwaouxictybwx"
|
||||
"yzmspjkqrteiydswlvb"
|
||||
"gjpxklgpzv\"txri\\hotpuiukzzzd"
|
||||
"p\"rxergtbsxmjmkeeqwvoagnki\""
|
||||
"santipvuiq"
|
||||
"\"ihjqlhtwbuy\"hdkiv\"mtiqacnf\\"
|
||||
"oliaggtqyyx"
|
||||
"fwwnpmbb"
|
||||
"yrtdrieazfxyyneo"
|
||||
"nywbv\\"
|
||||
"twc\\ehfqxhgomgrgwpxyzmnkioj"
|
||||
"qludrkkvljljd\\xvdeum\x4e"
|
|
@ -0,0 +1,13 @@
|
|||
with open('day8-input', 'r') as file:
|
||||
data = [l.strip('\n') for l in file]
|
||||
|
||||
count = 0
|
||||
for line in data:
|
||||
count += len(line) - len(line.encode('utf-8').decode('unicode-escape')) + 2 # Overall quotes aren't removed by encoding
|
||||
print(count) # Part 1
|
||||
|
||||
import json
|
||||
count2 = 0
|
||||
for line in data:
|
||||
count2 += len(json.dumps(line)) - len(line)
|
||||
print(count2) # Part 2
|
|
@ -0,0 +1,28 @@
|
|||
Faerun to Norrath = 129
|
||||
Faerun to Tristram = 58
|
||||
Faerun to AlphaCentauri = 13
|
||||
Faerun to Arbre = 24
|
||||
Faerun to Snowdin = 60
|
||||
Faerun to Tambi = 71
|
||||
Faerun to Straylight = 67
|
||||
Norrath to Tristram = 142
|
||||
Norrath to AlphaCentauri = 15
|
||||
Norrath to Arbre = 135
|
||||
Norrath to Snowdin = 75
|
||||
Norrath to Tambi = 82
|
||||
Norrath to Straylight = 54
|
||||
Tristram to AlphaCentauri = 118
|
||||
Tristram to Arbre = 122
|
||||
Tristram to Snowdin = 103
|
||||
Tristram to Tambi = 49
|
||||
Tristram to Straylight = 97
|
||||
AlphaCentauri to Arbre = 116
|
||||
AlphaCentauri to Snowdin = 12
|
||||
AlphaCentauri to Tambi = 18
|
||||
AlphaCentauri to Straylight = 91
|
||||
Arbre to Snowdin = 129
|
||||
Arbre to Tambi = 53
|
||||
Arbre to Straylight = 40
|
||||
Snowdin to Tambi = 15
|
||||
Snowdin to Straylight = 99
|
||||
Tambi to Straylight = 70
|
|
@ -0,0 +1,28 @@
|
|||
with open('day9-input', 'r') as file:
|
||||
data = [l.strip('\n') for l in file]
|
||||
|
||||
towns = set()
|
||||
distances = {}
|
||||
def get_distance(town1, town2):
|
||||
if town2 < town1:
|
||||
return distances[(town2, town1)]
|
||||
else:
|
||||
return distances[(town1, town2)]
|
||||
def set_distance(town1, town2, value):
|
||||
if town2 < town1:
|
||||
distances[(town2, town1)] = value
|
||||
else:
|
||||
distances[(town1, town2)] = value
|
||||
|
||||
for line in data:
|
||||
town1, _, town2, _, distance = line.split(' ')
|
||||
towns.add(town1)
|
||||
towns.add(town2)
|
||||
set_distance(town1, town2, int(distance))
|
||||
|
||||
from itertools import permutations
|
||||
route_distances = []
|
||||
for route in permutations(towns):
|
||||
route_distances.append(sum([get_distance(a, b) for a, b in zip(route[:-1], route[1:])]))
|
||||
print(min(route_distances)) # Part 1
|
||||
print(max(route_distances)) # Part 2
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,13 @@
|
|||
with open('day1-input', 'r') as file:
|
||||
data = file.readlines()
|
||||
nums = [int(d.rstrip('\n')) for d in data]
|
||||
print(sum(nums)) # Part 1 answer
|
||||
|
||||
from itertools import cycle
|
||||
iterator = cycle(nums)
|
||||
while(True):
|
||||
f += next(iterator)
|
||||
if f in freqs:
|
||||
print(f) # Part 2 answer
|
||||
break
|
||||
freqs.add(f)
|
|
@ -0,0 +1,250 @@
|
|||
pnebjqralgdgckzfifvtxywomu
|
||||
pnebjqsalrdgcqzfihotxhwomu
|
||||
pneajqsalrdgckzfihytxywoml
|
||||
pnepjqsalrwgckztihvtxywomu
|
||||
pnhbjqsalrdgckzfimvtxywodu
|
||||
pnwbjqsdlrdgckzfihvnxywomu
|
||||
inebjqnalrdgckzfihvtxzwomu
|
||||
pnebjssalhdgckzfihvtsywomu
|
||||
pnebjqjalrdgckzfiavtxywoku
|
||||
vnebjqsalrdgckzfihvbxmwomu
|
||||
phebjksaurdgckzfihvtxywomu
|
||||
pneojqealrdgckzhihvtxywomu
|
||||
snebjqsalrdgckzqihvtxyzomu
|
||||
pnebjqsalrtackzfihvtxswomu
|
||||
bnebjqlalrdgckzfihvtxywhmu
|
||||
pnebjqfalrdgckzfijvtxywomi
|
||||
fnehjbsalrdgckzfihvtxywomu
|
||||
pnebjasalrdgckzdihvtxqwomu
|
||||
pnebjhsaljdgckzfihvtxywmmu
|
||||
pnebjqsalrdgckzfihvsxykoau
|
||||
pnebjqsalrdgckzbihvtdywomc
|
||||
pnobjqsalrxgckzfihvtxywomh
|
||||
pnebjqstlrdgchzfihvtxywnmu
|
||||
pnebjquaxrdgckzfihvtxywolu
|
||||
pqebjqsalrdgcdzfihvtcywomu
|
||||
xnabjqsalrdgckzfihvtxywmmu
|
||||
rnebjqsalrdgckzfihvtxmwouu
|
||||
vaebjqsalrdgckcfihvtxywomu
|
||||
pnebjqsalrpgcnzfihvbxywomu
|
||||
pcvbjqsalrdjckzfihvtxywomu
|
||||
pneyjqsafrdgckzfihdtxywomu
|
||||
pxedjqsalrdgckzfihvtxyzomu
|
||||
pnebjqsalrdgctzfihnyxywomu
|
||||
pnebjqsalrdgckzfihvtnylsmu
|
||||
pnebjqsalrdyckzfihvbxycomu
|
||||
fnebjqsalrdgckzfihvtxtwomc
|
||||
pnobjqsalrdgckdfihvtxywomh
|
||||
pqebjqsalrdgcqzfihvtxywymu
|
||||
pnebxqsalrdgckzficvtwywomu
|
||||
pnebjqshlragczzfihvtxywomu
|
||||
pnebqqsalrdackzfihttxywomu
|
||||
pnebjqsalrdsckwfbhvtxywomu
|
||||
pnehjqsalrdgcuzfxhvtxywomu
|
||||
pnebjqsavrdgckzfihvexywomn
|
||||
pnebunsalrdgckzfihvtxywomi
|
||||
pnebjxsalrdgckzfmhvtpywomu
|
||||
rnebjqsalrdghkzfihztxywomu
|
||||
pnebjqsalrigcbzfihvfxywomu
|
||||
pnebqqsalrggckzfihvtxyromu
|
||||
pnebjqsalrdgchzfihvtxylmmu
|
||||
pnebeqsalrdgckzdihvtxywoms
|
||||
pnebjqsalrdgckzzihvfxywozu
|
||||
pnzbjgsalrtgckzfihvtxywomu
|
||||
pnebjqsaledgckzjihvtxzwomu
|
||||
pnebjqsalydgckqfihvtxywouu
|
||||
pnebjqsalrdgckufihvqxdwomu
|
||||
pnebjqsylrdgckzfihvdxyjomu
|
||||
pnemjqsalrdgckzeihvtxywoqu
|
||||
plebjasalrdgckzfihvtxywomb
|
||||
pnebjqsadrdgckufihvtxyfomu
|
||||
pbebjqsaardgckzfihvtxmwomu
|
||||
pnebjqsalrdgcmzfihotxywgmu
|
||||
pnebjqsaprdgcizfihvtxywhmu
|
||||
pnebjqsalrkgcuzfihvtlywomu
|
||||
pnebjqsalrdnckzfihvtxysomg
|
||||
pnebjqdafrdgckzfihctxywomu
|
||||
pnebjqsalrdgckzfihutxkwomp
|
||||
pnebvqsalrdgclzfimvtxywomu
|
||||
pnebjqralrdgcktfihvtxiwomu
|
||||
pneujqsalrdsckzfzhvtxywomu
|
||||
pnebfqgalrdgckzfihvtxywjmu
|
||||
pneyjqsalrkgckzfihctxywomu
|
||||
pndbjqsalrdgckzfjhvtxywouu
|
||||
pneljnsalrdgcozfihvtxywomu
|
||||
phebjqsalrdgckzfihxtxdwomu
|
||||
pnlbjqsalrhgckzfzhvtxywomu
|
||||
pnebjqsalrsgckzfiovtxywwmu
|
||||
pncbjqsalrdgfkzfivvtxywomu
|
||||
nnebjqsalrdgckzfthvtxycomu
|
||||
pnebjqwalsdgckzfixvtxywomu
|
||||
pnebjtsalrdgcfzfimvtxywomu
|
||||
pnebjqsvlrdgckzfihutxfwomu
|
||||
pnebjmsalrdgckzkxhvtxywomu
|
||||
pnekjqsllrdgckzfinvtxywomu
|
||||
pneijqsxlrdgckzfihvtxywjmu
|
||||
wnxbjqsafrdgckzfihvtxywomu
|
||||
pnebjqskledgokzfihvtxywomu
|
||||
pnebjqvalrdgckzfihvtxytoju
|
||||
pneqjqsalrdgckzfilvthywomu
|
||||
pnebjqsalrdgckzfihvokywomf
|
||||
bnebjqsalrdgckufihvtxywimu
|
||||
pnebjqsaurdgckzfihvtrywosu
|
||||
pnebjmsaludgckzfihvtxywomn
|
||||
pnebdqsalrdgcktfihvtxywodu
|
||||
pnebjqjylzdgckzfihvtxywomu
|
||||
piebjqsalrdgcrzfihstxywomu
|
||||
pnebjqsaurdgckwfnhvtxywomu
|
||||
pnebxqsajrdgcjzfihvtxywomu
|
||||
pnebjqsalrdghsdfihvtxywomu
|
||||
pnebcqsxlrdgckzfihvtxyaomu
|
||||
pnefjqsalrdgckzfuhvtxyworu
|
||||
pnebjqsalrdlcksfihvteywomu
|
||||
pnebjqlalrgackzfihvtxywomu
|
||||
pnebdqsalrdickzfihvtxdwomu
|
||||
pneujksalrdgctzfihvtxywomu
|
||||
pnebjqsalrduckzfihvsxywomf
|
||||
pnebjqsalrdgckcfihotxywomd
|
||||
envbjqsalsdgckzfihvtxywomu
|
||||
pnebjqsalzdgcvzzihvtxywomu
|
||||
pnebjqsalrdyckzflhvyxywomu
|
||||
pnebjqsalrdglkzfihstxymomu
|
||||
pnebmqsalrdgokzfihvtxywoml
|
||||
pnebjqsylrdnckzfihatxywomu
|
||||
pnebjqaflndgckzfihvtxywomu
|
||||
pneboqsagragckzfihvtxywomu
|
||||
peebjqstlndgckzfihvtxywomu
|
||||
onebjqsklrdgckzfihvtxmwomu
|
||||
pnebjqjnlrdgckrfihvtxywomu
|
||||
pnebjqsalrhgckzfihvqxywomh
|
||||
pnebjqsalrdgckzzihvtxowomw
|
||||
pnebjgsalrdgckffihltxywomu
|
||||
znebaqsalcdgckzfihvtxywomu
|
||||
pnnbjqeasrdgckzfihvtxywomu
|
||||
rnebjqaalrxgckzfihvtxywomu
|
||||
pnebjqsalrdgckaxphvtxywomu
|
||||
pnebjcnalrdgnkzfihvtxywomu
|
||||
pnebjasalbdgckzmihvtxywomu
|
||||
pnebjqsalrdgckefjhvtmywomu
|
||||
pnebjqsalrdgmkzfihvtxyoomb
|
||||
pnebjqsalrkgckogihvtxywomu
|
||||
pnwbjqsalrdgckztihvtxywomt
|
||||
pnebjqsalrdgckzfihotgnwomu
|
||||
pnebjqsdlrrgckzfihvtxyaomu
|
||||
pnebvasalrdgckzfihvtsywomu
|
||||
pnebrqqalrvgckzfihvtxywomu
|
||||
tnebjqsglrdgqkzfihvtxywomu
|
||||
pnebjqsatrsgckifihvtxywomu
|
||||
pneboqsalrdgckzfihvkxywomi
|
||||
pnezaqsalrdgcktfihvtxywomu
|
||||
pnebjqsnlrdgckzfihvfxqwomu
|
||||
pneajqsaxrmgckzfihvtxywomu
|
||||
pnebjosalodgckzfihvxxywomu
|
||||
pnebjqsalndgckmfihvtfywomu
|
||||
pneejqsalidgckzfihgtxywomu
|
||||
pnecjqsalrdgckzfihptxiwomu
|
||||
tnebjqsalrdgckznihvxxywomu
|
||||
ptebjqsalrdgckzfimvtxywomm
|
||||
wnebjqsalndgckzfihvtxywoju
|
||||
fnebmqsplrdgckzfihvtxywomu
|
||||
pnlbjqsalrdghkzficvtxywomu
|
||||
pnebjqsesrdgckzdihvtxywomu
|
||||
pnebjqsalregokzfirvtxywomu
|
||||
pnebjtualrtgckzfihvtxywomu
|
||||
pnebjwsdlrdgckzfihvtxywoml
|
||||
pnlbjqsayrdgckzfqhvtxywomu
|
||||
pnebjwsalpdgckzfihvtxywomc
|
||||
pnqbjqsalcdgckzhihvtxywomu
|
||||
pneujqsalrdgckzfhhvtxrwomu
|
||||
pnebjqsalqdgcizfihvtxywimu
|
||||
pnebjqsacldgckzfihvwxywomu
|
||||
puebjqsalrdgckzfbhvtxyeomu
|
||||
pnebjqsalrdgcyimihvtxywomu
|
||||
pnebjlsalrdgckzfihvtxiwome
|
||||
pnebfusalrdgckzfihvtxywodu
|
||||
pnebjqsalrdgvazfirvtxywomu
|
||||
pnebjqsalrdgckyfohvtxywomz
|
||||
gnenjqsalrdgckzfihvtxynomu
|
||||
mnebjqsalrdgckhfihvtxycomu
|
||||
phebjqsalrdgckzfihvtxtworu
|
||||
pnebjqsalrdgdkzfihvtxywfmj
|
||||
pneveqsairdgckzfihvtxywomu
|
||||
pnebjqsalcdlckzfihvtxywomg
|
||||
pneajqsalrdgckzfihvtxygoxu
|
||||
puebjqdclrdgckzfihvtxywomu
|
||||
tuebjqsalrdgckzfihvtxywoou
|
||||
pwenjqsalrdgckzfihvtxywomg
|
||||
pnebjqsalrdgckzfihhltywomu
|
||||
pnebjqsalrdgchzqievtxywomu
|
||||
pnegjqsalrdgckzfiovtxywdmu
|
||||
pnebjaralrqgckzfihvtxywomu
|
||||
pnebjqsalrdrckzfimvtxywomm
|
||||
pnebjqsalrdgckzfpgvtxewomu
|
||||
pnebjqsalrdhcqzfihitxywomu
|
||||
pnebjqsalrjgckefihmtxywomu
|
||||
pnebjcsalrdgcksfikvtxywomu
|
||||
pnebjqsalrdgckzfihvtxywdjc
|
||||
pnebjqsazrjgckzjihvtxywomu
|
||||
pnfbjqsclrdgckzfihvtxybomu
|
||||
pnebjqsalrdgckuqihvtxyaomu
|
||||
pfpbjzsalrdgckzfihvtxywomu
|
||||
pnevjqsalrdgckwfihytxywomu
|
||||
pnebjqsqlrkgckzfihvtvywomu
|
||||
pneejqsalrdlckzfihvtxywopu
|
||||
pnebjqsalcdgxkzfihvtxywomd
|
||||
pneqjqsalrdgcvzzihvtxywomu
|
||||
pnvbjqsalydgctzfihvtxywomu
|
||||
pnebjqsalrdgckzzihvfxywomn
|
||||
pnybjqsaerdgckzfihstxywomu
|
||||
pnobjqsalrdkckzfihvtxywomv
|
||||
pnebjqsalridckzfihvtxywfmu
|
||||
pnhbjqsaludgckyfihvtxywomu
|
||||
pnetjqsaprdgykzfihvtxywomu
|
||||
wnebjqsalrdvcfzfihvtxywomu
|
||||
pnetjqsalrdmckwfihvtxywomu
|
||||
pnebjysalrdgcszfihvtxnwomu
|
||||
pnebjqsrlrdgckzfihvtxywkhu
|
||||
pnubjqsplrdgcjzfihvtxywomu
|
||||
pnebjqsalrdzckzficjtxywomu
|
||||
pnebjqsalregckzfinvtxywoku
|
||||
pnebjqsalrcgckyfivvtxywomu
|
||||
pyenjqsalrdgckzfihvnxywomu
|
||||
prebjqsalrdnckzfihvtxysomg
|
||||
pnebjnsalrdgchzfihvaxywomu
|
||||
pnebjqsalrdgckzfihxagywomu
|
||||
pnebjqsalrdgckzvihvtoywoml
|
||||
pnebjqsilrdgckzfihvtfywgmu
|
||||
pnebjqmalrdgckzfihvtvawomu
|
||||
pnebqqsalrdgckzfiuvtfywomu
|
||||
pneqjqsalrdgckzfihvqxywomi
|
||||
pnebjesalrsgckzfihvtxywmmu
|
||||
znebjqsblrdgckzfihvlxywomu
|
||||
pnebjqsalrdgckzfuhvtlyworu
|
||||
pnebjqsylrdgckzfihvqxpwomu
|
||||
onebjqsalfdgckifihvtxywomu
|
||||
pnebjusalrdgckzfihvtxywyml
|
||||
pnebjssflrdgckzfigvtxywomu
|
||||
pnebjfsdzrdgckzfihvtxywomu
|
||||
pnebjqsalrdgcktfihvixywocu
|
||||
gnebjqnaqrdgckzfihvtxywomu
|
||||
pnebjqsaqrugckzfihhtxywomu
|
||||
pnebjqsxlrdgckzfihvtxlwosu
|
||||
pnebjzsalrdgckzmihvtxywovu
|
||||
pnebgqsalrdgckzfizvtxyjomu
|
||||
pnebjqsmlrdgckzfihvtxywsmi
|
||||
pnebjqsakmdgckzjihvtxywomu
|
||||
pnebjqdglrdgckvfihvtxywomu
|
||||
pnebmhsalrdgckxfihvtxywomu
|
||||
pneejqsalrdlckzfihvnxywomu
|
||||
bnebjqsalmdgckzfihvfxywomu
|
||||
bnebjnsalrdgcizfihvtxywomu
|
||||
pnebjqsalhdgcdzfihvbxywomu
|
||||
pnebjqsjlrdgckzfihvgiywomu
|
||||
pnebjisalrdgckzfihvtxywqmi
|
||||
pdebjqsalrdickzfihhtxywomu
|
||||
pnebjqsalrdkckzfihvjeywomu
|
||||
pneyjqsalrqgckzfihvtxywohu
|
||||
pnebjqsalrdgckcfihvtxjlomu
|
||||
plebqwsalrdgckzfihvtxywomu
|
||||
pnebjqlalrdgckzfihetxynomu
|
||||
sngbjqsalrdgckzfihvmxywomu
|
|
@ -0,0 +1,34 @@
|
|||
with open('day2-input') as file:
|
||||
data = file.readlines()
|
||||
lines = [d.rstrip('\n') for d in data]
|
||||
twos = 0
|
||||
threes = 0
|
||||
for line in lines:
|
||||
charcounts = {}
|
||||
for c in line:
|
||||
if c in charcounts:
|
||||
charcounts[c] += 1
|
||||
else:
|
||||
charcounts[c] = 1
|
||||
if 2 in charcounts.values():
|
||||
twos += 1
|
||||
if 3 in charcounts.values():
|
||||
threes += 1
|
||||
print(twos * threes) # Part 1
|
||||
|
||||
def diff(s1, s2):
|
||||
count = 0
|
||||
common = []
|
||||
for c1, c2 in zip(s1, s2):
|
||||
if c1 != c2:
|
||||
count += 1
|
||||
else:
|
||||
common.append(c1)
|
||||
return count, common
|
||||
|
||||
for i, line in enumerate(lines):
|
||||
for line2 in lines[i:]:
|
||||
count, common = diff(line, line2)
|
||||
if count == 1:
|
||||
print(line, line2, ''.join(common)) # Part 2
|
||||
break
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,21 @@
|
|||
with open('day3-input', 'r') as file:
|
||||
data = [l.strip('\n') for l in file]
|
||||
|
||||
import numpy as np
|
||||
fabric = np.zeros((1000, 1000), dtype=np.int32)
|
||||
|
||||
for line in data:
|
||||
tokens = line.split(' ')
|
||||
w, h = [int(i) for i in tokens[-1].split('x')]
|
||||
x, y = [int(i) for i in tokens[-2].rstrip(':').split(',')]
|
||||
fabric[x:x+w, y:y+h] += 1
|
||||
|
||||
print((fabric > 1).sum()) # Part 1
|
||||
|
||||
for line in data:
|
||||
tokens = line.split(' ')
|
||||
w, h = [int(i) for i in tokens[-1].split('x')]
|
||||
x, y = [int(i) for i in tokens[-2].rstrip(':').split(',')]
|
||||
if fabric[x:x+w, y:y+h].sum() == w*h:
|
||||
print(tokens[0]) # Part 2
|
||||
break
|
Loading…
Reference in New Issue