This commit is contained in:
Tyrel Souza 2022-12-09 16:41:14 -05:00
parent 042b10fe8d
commit b2ad0448ba
17 changed files with 3158 additions and 0 deletions

30
2015/day01.py Normal file
View File

@ -0,0 +1,30 @@
import shared
from collections import Counter
def pt1(inp):
floor = 0
chars = [x for x in inp]
c = Counter(chars)
floor += c['(']
floor -= c[')']
print(floor)
def pt2(inp):
floor = 0
chars = [x for x in inp]
for idx, c in enumerate(chars):
if c == '(':
floor +=1
if c == ')':
floor -= 1
if floor == -1:
print(idx+1)
break
if __name__ == "__main__":
with open(shared.get_fname(1), "r") as f:
inp = f.read().rstrip()
pt1(inp)
pt2(inp)

50
2015/day02.py Normal file
View File

@ -0,0 +1,50 @@
import shared
from collections import Counter
def get_paper(l,w,h):
sides = [
(l*w),
(w*h),
(h*l)
]
smallest = min(sides)
sides = [2*x for x in sides]
sides.append(smallest)
return sum(sides)
def pt1(boxes):
box_papers = []
for box in boxes:
size = get_paper(*box)
box_papers.append(size)
print(sum(box_papers))
def get_ribbon(l,w,h):
dims = sorted([l,w,h])[:-1]
ribbon = sum([2*x for x in dims])
ribbon += (l*w*h)
return ribbon
def pt2(boxes):
box_ribbons = []
for box in boxes:
size = get_ribbon(*box)
box_ribbons.append(size)
print(sum(box_ribbons))
def main():
test = [[2,3,4]]
pt1(test)
pt2(test)
print('---')
with open(shared.get_fname(2), "r") as f:
inp = [x.rstrip() for x in f.readlines()]
boxes = [list(map(int,x.split("x"))) for x in inp]
pt1(boxes)
pt2(boxes)
if __name__ == "__main__":
main()

67
2015/day03.py Normal file
View File

@ -0,0 +1,67 @@
import shared
import matrix
from collections import Counter
import numpy as np
size = 75
def pt2(dirs):
r = size
c = size
mx = np.array(matrix.matrix_of_size(r*2+1,c*2+1))
mx[r][c] = '2' # initial house
for d in dirs[::2]:
mx,r,c = move(mx, r, c, d)
r=size
c=size
for d in dirs[1::2]:
mx,r,c = move(mx, r, c, d)
matrix.pmx(mx,pad=False,space=False)
count(mx)
def pt1(dirs):
r = size
c = size
mx = np.array(matrix.matrix_of_size(r*2+1,c*2+1))
mx[r][c] = '1' # initial house
for d in dirs:
mx,r,c = move(mx, r, c, d)
matrix.pmx(mx,pad=False,space=False)
count(mx)
def move(mx, r, c, d):
h, w = mx.shape
d_r = 0
d_c = 0
match d:
case '<':
d_c = -1
case '>':
d_c = 1
case '^':
d_r = -1
case 'v':
d_r = 1
c += d_c
r += d_r
mx[r][c] += 1
return mx,r,c
def add_pad(mx, d):
return np.pad(mx, d, mode='constant', constant_values=0)
def count(mx):
flat = np.ravel(mx).tolist()
total = len([x for x in flat if x])
print(total)
def main():
with open(shared.get_fname(3), "r") as f:
inp = [x for x in f.read().rstrip()]
pt1(inp)
pt2(inp)
if __name__ == "__main__":
main()

31
2015/day04.py Normal file
View File

@ -0,0 +1,31 @@
import hashlib
def hsh(st, ct=5):
return hashlib.md5(st.encode('utf-8')).hexdigest()[:ct] == ("0"*ct)
def pt1(seed):
idx = 0
while True:
idx +=1
if hsh(f"{seed}{idx}"):
break
print(idx)
def pt2(seed):
idx = 0
while True:
idx +=1
if hsh(f"{seed}{idx}", 6):
break
print(idx)
def main():
inp = "iwrupvqb"
pt1(inp)
pt2(inp)
if __name__ == "__main__":
main()

59
2015/day05.py Normal file
View File

@ -0,0 +1,59 @@
import shared
import matrix
from collections import Counter
import numpy as np
letters = [x for x in 'abcdefghijklmnopqrstuvwxyz']
letter_doubles = [x+x for x in letters]
vowels = [x for x in 'aeiou']
no = ['ab','cd','pq','xy']
def check_pt1(s):
any_no = [True for x in no if x in s]
if any_no:
return False
vowel_count = 0
for l in s:
if l in vowels:
vowel_count += 1
if vowel_count < 3:
return False
for d in letter_doubles:
if d in s:
return True
return False
def pt1(strs):
okay = [s for s in strs if check_pt1(s)]
print(len(okay))
def check_pt2(s):
for idx in range(len(s)-1):
me = s[idx:idx+2]
index = s.rindex(me)
if index and index != idx and index != idx+1:
break
else:
return False
for idx in range(len(s)-2):
me = s[idx:idx+3]
if me[0] == me[2]:
return True
return False
def pt2(strs):
okay = [s for s in strs if check_pt2(s)]
print(len(okay))
def main():
with open(shared.get_fname(5), "r") as f:
inp = [x.rstrip() for x in f.readlines()]
pt1(inp)
pt2(inp)
if __name__ == "__main__":
main()

68
2015/day06.py Normal file
View File

@ -0,0 +1,68 @@
import shared
import matrix
import numpy as np
from scanf import scanf
def instruction_parse_p1(mx, inst):
if inst.startswith("turn"):
d, x1,y1, x2,y2 = scanf("turn %s %d,%d through %d,%d", inst)
x2+=1 # inclusive
y2+=1
if d == 'on':
mx[y1:y2,x1:x2] = 1
if d == 'off':
mx[y1:y2,x1:x2] = 0
elif inst.startswith("toggle"):
x1,y1, x2,y2 = scanf("toggle %d,%d through %d,%d", inst)
x2+=1
y2+=1
mx[y1:y2,x1:x2] ^= 1
def instruction_parse_p2(mx, inst):
if inst.startswith("turn"):
d, x1,y1, x2,y2 = scanf("turn %s %d,%d through %d,%d", inst)
if d == 'on':
dx = 1
if d == 'off':
dx = -1
mx[y1:y2+1,x1:x2+1] += dx
mx[mx<0] = 0
elif inst.startswith("toggle"):
x1,y1, x2,y2 = scanf("toggle %d,%d through %d,%d", inst)
dx = 2
mx[y1:y2+1,x1:x2+1] += dx
#mx[mx < 0] = 0
def pt1(instructions):
mx = np.array(matrix.matrix_of_size(1001,1001))
for inst in instructions:
instruction_parse_p1(mx, inst)
print(count(mx))
def pt2(instructions):
mx = np.array(matrix.matrix_of_size(1000,1000))
for inst in instructions:
instruction_parse_p2(mx, inst)
print(_sum(mx))
def count(mx):
flat = np.ravel(mx).tolist()
total = len([x for x in flat if x])
return total
def _sum(mx):
flat = [x for x in np.ravel(mx).tolist() if x]
return sum(flat)
def main():
with open(shared.get_fname(6), "r") as f:
inp = [x.rstrip() for x in f.readlines()]
pt1(inp)
pt2(inp)
print("=17836115")
if __name__ == "__main__":
main()

16
2015/day07.py Normal file
View File

@ -0,0 +1,16 @@
import shared
import matrix
import numpy as np
def pt1(inp):
print(inp)
def main():
with open(shared.get_fname(7), "r") as f:
inp = [x.rstrip() for x in f.readlines()]
pt1(inp)
#pt2(inp)
if __name__ == "__main__":
main()

1
2015/full/day01.txt Normal file

File diff suppressed because one or more lines are too long

1000
2015/full/day02.txt Normal file

File diff suppressed because it is too large Load Diff

1
2015/full/day03.txt Normal file

File diff suppressed because one or more lines are too long

1000
2015/full/day05.txt Normal file

File diff suppressed because it is too large Load Diff

300
2015/full/day06.txt Normal file
View File

@ -0,0 +1,300 @@
turn on 489,959 through 759,964
turn off 820,516 through 871,914
turn off 427,423 through 929,502
turn on 774,14 through 977,877
turn on 410,146 through 864,337
turn on 931,331 through 939,812
turn off 756,53 through 923,339
turn off 313,787 through 545,979
turn off 12,823 through 102,934
toggle 756,965 through 812,992
turn off 743,684 through 789,958
toggle 120,314 through 745,489
toggle 692,845 through 866,994
turn off 587,176 through 850,273
turn off 674,321 through 793,388
toggle 749,672 through 973,965
turn on 943,30 through 990,907
turn on 296,50 through 729,664
turn on 212,957 through 490,987
toggle 171,31 through 688,88
turn off 991,989 through 994,998
turn off 913,943 through 958,953
turn off 278,258 through 367,386
toggle 275,796 through 493,971
turn off 70,873 through 798,923
toggle 258,985 through 663,998
turn on 601,259 through 831,486
turn off 914,94 through 941,102
turn off 558,161 through 994,647
turn on 119,662 through 760,838
toggle 378,775 through 526,852
turn off 384,670 through 674,972
turn off 249,41 through 270,936
turn on 614,742 through 769,780
turn on 427,70 through 575,441
turn on 410,478 through 985,753
turn off 619,46 through 931,342
turn on 284,55 through 768,922
turn off 40,592 through 728,685
turn on 825,291 through 956,950
turn on 147,843 through 592,909
turn off 218,675 through 972,911
toggle 249,291 through 350,960
turn off 556,80 through 967,675
toggle 609,148 through 968,279
toggle 217,605 through 961,862
toggle 407,177 through 548,910
toggle 400,936 through 599,938
turn off 721,101 through 925,455
turn on 268,631 through 735,814
toggle 549,969 through 612,991
toggle 553,268 through 689,432
turn off 817,668 through 889,897
toggle 801,544 through 858,556
toggle 615,729 through 832,951
turn off 427,477 through 958,948
turn on 164,49 through 852,946
turn on 542,449 through 774,776
turn off 923,196 through 980,446
toggle 90,310 through 718,846
turn off 657,215 through 744,252
turn off 800,239 through 811,712
turn on 502,90 through 619,760
toggle 649,512 through 862,844
turn off 334,903 through 823,935
turn off 630,233 through 839,445
turn on 713,67 through 839,865
turn on 932,50 through 982,411
turn off 480,729 through 984,910
turn on 100,219 through 796,395
turn on 758,108 through 850,950
turn off 427,276 through 439,938
turn on 178,284 through 670,536
toggle 540,27 through 625,102
turn off 906,722 through 936,948
toggle 345,418 through 859,627
toggle 175,775 through 580,781
toggle 863,28 through 929,735
turn off 824,858 through 905,973
toggle 752,312 through 863,425
turn on 985,716 through 988,852
turn off 68,504 through 763,745
toggle 76,209 through 810,720
turn off 657,607 through 676,664
toggle 596,869 through 896,921
turn off 915,411 through 968,945
turn off 368,39 through 902,986
turn on 11,549 through 393,597
turn off 842,893 through 976,911
toggle 274,106 through 581,329
toggle 406,403 through 780,950
toggle 408,988 through 500,994
toggle 217,73 through 826,951
turn on 917,872 through 961,911
toggle 394,34 through 510,572
toggle 424,603 through 583,626
toggle 106,159 through 755,738
turn off 244,610 through 472,709
turn on 350,265 through 884,690
turn on 688,184 through 928,280
toggle 279,443 through 720,797
turn off 615,493 through 888,610
toggle 118,413 through 736,632
turn on 798,782 through 829,813
turn off 250,934 through 442,972
turn on 68,503 through 400,949
toggle 297,482 through 313,871
toggle 710,3 through 839,859
turn on 125,300 through 546,888
toggle 482,39 through 584,159
turn off 536,89 through 765,962
turn on 530,518 through 843,676
turn on 994,467 through 994,676
turn on 623,628 through 744,927
toggle 704,912 through 837,983
turn on 154,364 through 517,412
toggle 344,409 through 780,524
turn off 578,740 through 725,879
turn on 251,933 through 632,957
turn on 827,705 through 971,789
toggle 191,282 through 470,929
toggle 324,525 through 446,867
toggle 534,343 through 874,971
toggle 550,650 through 633,980
toggle 837,404 through 881,915
toggle 338,881 through 845,905
turn on 469,462 through 750,696
turn on 741,703 through 892,870
turn off 570,215 through 733,562
turn on 445,576 through 870,775
turn on 466,747 through 554,878
turn off 820,453 through 868,712
turn off 892,706 through 938,792
turn off 300,238 through 894,746
turn off 306,44 through 457,444
turn off 912,569 through 967,963
toggle 109,756 through 297,867
turn on 37,546 through 41,951
turn on 321,637 through 790,910
toggle 66,50 through 579,301
toggle 933,221 through 933,791
turn on 486,676 through 878,797
turn on 417,231 through 556,317
toggle 904,468 through 981,873
turn on 417,675 through 749,712
turn on 692,371 through 821,842
toggle 324,73 through 830,543
turn on 912,490 through 977,757
turn off 634,872 through 902,949
toggle 266,779 through 870,798
turn on 772,982 through 990,996
turn off 607,46 through 798,559
turn on 295,602 through 963,987
turn on 657,86 through 944,742
turn off 334,639 through 456,821
turn off 997,667 through 997,670
turn off 725,832 through 951,945
turn off 30,120 through 952,984
turn on 860,965 through 917,976
toggle 471,997 through 840,998
turn off 319,307 through 928,504
toggle 823,631 through 940,908
toggle 969,984 through 981,993
turn off 691,319 through 865,954
toggle 911,926 through 938,929
turn on 953,937 through 968,991
toggle 914,643 through 975,840
turn on 266,982 through 436,996
turn off 101,896 through 321,932
turn off 193,852 through 751,885
turn off 576,532 through 863,684
turn on 761,456 through 940,783
turn on 20,290 through 398,933
turn off 435,335 through 644,652
turn on 830,569 through 905,770
turn off 630,517 through 905,654
turn on 664,53 through 886,976
toggle 275,416 through 408,719
turn on 370,621 through 515,793
turn on 483,373 through 654,749
turn on 656,786 through 847,928
turn off 532,752 through 945,974
toggle 301,150 through 880,792
turn off 951,488 through 958,952
turn on 207,729 through 882,828
toggle 694,532 through 973,961
toggle 676,639 through 891,802
turn off 653,6 through 905,519
toggle 391,109 through 418,312
turn on 877,423 through 957,932
turn on 340,145 through 563,522
turn off 978,467 through 988,895
turn off 396,418 through 420,885
turn off 31,308 through 816,316
turn on 107,675 through 758,824
turn on 61,82 through 789,876
turn on 750,743 through 754,760
toggle 88,733 through 736,968
turn off 754,349 through 849,897
toggle 157,50 through 975,781
turn off 230,231 through 865,842
turn off 516,317 through 630,329
turn off 697,820 through 829,903
turn on 218,250 through 271,732
toggle 56,167 through 404,431
toggle 626,891 through 680,927
toggle 370,207 through 791,514
toggle 860,74 through 949,888
turn on 416,527 through 616,541
turn off 745,449 through 786,908
turn on 485,554 through 689,689
turn on 586,62 through 693,141
toggle 506,759 through 768,829
turn on 473,109 through 929,166
turn on 760,617 through 773,789
toggle 595,683 through 618,789
turn off 210,775 through 825,972
toggle 12,426 through 179,982
turn on 774,539 through 778,786
turn on 102,498 through 121,807
turn off 706,897 through 834,965
turn off 678,529 through 824,627
turn on 7,765 through 615,870
turn off 730,872 through 974,943
turn off 595,626 through 836,711
turn off 215,424 through 841,959
toggle 341,780 through 861,813
toggle 507,503 through 568,822
turn on 252,603 through 349,655
toggle 93,521 through 154,834
turn on 565,682 through 951,954
turn on 544,318 through 703,418
toggle 756,953 through 891,964
turn on 531,123 through 856,991
turn on 148,315 through 776,559
turn off 925,835 through 963,971
turn on 895,944 through 967,964
turn off 102,527 through 650,747
toggle 626,105 through 738,720
turn off 160,75 through 384,922
toggle 813,724 through 903,941
turn on 207,107 through 982,849
toggle 750,505 through 961,697
toggle 105,410 through 885,819
turn on 226,104 through 298,283
turn off 224,604 through 508,762
turn on 477,368 through 523,506
turn off 477,901 through 627,936
turn off 887,131 through 889,670
turn on 896,994 through 938,999
toggle 401,580 through 493,728
toggle 987,184 through 991,205
turn on 821,643 through 882,674
toggle 784,940 through 968,959
turn off 251,293 through 274,632
turn off 339,840 through 341,844
turn off 675,351 through 675,836
toggle 918,857 through 944,886
toggle 70,253 through 918,736
turn off 612,604 through 772,680
turn off 277,40 through 828,348
toggle 692,139 through 698,880
toggle 124,446 through 883,453
toggle 969,932 through 990,945
toggle 855,692 through 993,693
toggle 722,472 through 887,899
toggle 978,149 through 985,442
toggle 837,540 through 916,889
turn off 612,2 through 835,82
toggle 560,767 through 878,856
turn on 461,734 through 524,991
toggle 206,824 through 976,912
turn on 826,610 through 879,892
turn on 577,699 through 956,933
turn off 9,250 through 50,529
turn off 77,657 through 817,677
turn on 68,419 through 86,426
turn on 991,720 through 992,784
turn on 668,20 through 935,470
turn off 133,418 through 613,458
turn off 487,286 through 540,328
toggle 247,874 through 840,955
toggle 301,808 through 754,970
turn off 34,194 through 578,203
turn off 451,49 through 492,921
turn on 907,256 through 912,737
turn off 479,305 through 702,587
turn on 545,583 through 732,749
toggle 11,16 through 725,868
turn on 965,343 through 986,908
turn on 674,953 through 820,965
toggle 398,147 through 504,583
turn off 778,194 through 898,298
turn on 179,140 through 350,852
turn off 241,118 through 530,832
turn off 41,447 through 932,737
turn off 820,663 through 832,982
turn on 550,460 through 964,782
turn on 31,760 through 655,892
toggle 628,958 through 811,992

339
2015/full/day07.txt Normal file
View File

@ -0,0 +1,339 @@
NOT dq -> dr
kg OR kf -> kh
ep OR eo -> eq
44430 -> b
NOT gs -> gt
dd OR do -> dp
eg AND ei -> ej
y AND ae -> ag
jx AND jz -> ka
lf RSHIFT 2 -> lg
z AND aa -> ac
dy AND ej -> el
bj OR bi -> bk
kk RSHIFT 3 -> km
NOT cn -> co
gn AND gp -> gq
cq AND cs -> ct
eo LSHIFT 15 -> es
lg OR lm -> ln
dy OR ej -> ek
NOT di -> dj
1 AND fi -> fj
kf LSHIFT 15 -> kj
NOT jy -> jz
NOT ft -> fu
fs AND fu -> fv
NOT hr -> hs
ck OR cl -> cm
jp RSHIFT 5 -> js
iv OR jb -> jc
is OR it -> iu
ld OR le -> lf
NOT fc -> fd
NOT dm -> dn
bn OR by -> bz
aj AND al -> am
cd LSHIFT 15 -> ch
jp AND ka -> kc
ci OR ct -> cu
gv AND gx -> gy
de AND dk -> dm
x RSHIFT 5 -> aa
et RSHIFT 2 -> eu
x RSHIFT 1 -> aq
ia OR ig -> ih
bk LSHIFT 1 -> ce
y OR ae -> af
NOT ca -> cb
e AND f -> h
ia AND ig -> ii
ck AND cl -> cn
NOT jh -> ji
z OR aa -> ab
1 AND en -> eo
ib AND ic -> ie
NOT eh -> ei
iy AND ja -> jb
NOT bb -> bc
ha OR gz -> hb
1 AND cx -> cy
NOT ax -> ay
ev OR ew -> ex
bn RSHIFT 2 -> bo
er OR es -> et
eu OR fa -> fb
jp OR ka -> kb
ea AND eb -> ed
k AND m -> n
et RSHIFT 3 -> ev
et RSHIFT 5 -> ew
hz RSHIFT 1 -> is
ki OR kj -> kk
NOT h -> i
lv LSHIFT 15 -> lz
as RSHIFT 1 -> bl
hu LSHIFT 15 -> hy
iw AND ix -> iz
lf RSHIFT 1 -> ly
fp OR fv -> fw
1 AND am -> an
ap LSHIFT 1 -> bj
u LSHIFT 1 -> ao
b RSHIFT 5 -> f
jq AND jw -> jy
iu RSHIFT 3 -> iw
ih AND ij -> ik
NOT iz -> ja
de OR dk -> dl
iu OR jf -> jg
as AND bd -> bf
b RSHIFT 3 -> e
jq OR jw -> jx
iv AND jb -> jd
cg OR ch -> ci
iu AND jf -> jh
lx -> a
1 AND cc -> cd
ly OR lz -> ma
NOT el -> em
1 AND bh -> bi
fb AND fd -> fe
lf OR lq -> lr
bn RSHIFT 3 -> bp
bn AND by -> ca
af AND ah -> ai
cf LSHIFT 1 -> cz
dw OR dx -> dy
gj AND gu -> gw
jg AND ji -> jj
jr OR js -> jt
bl OR bm -> bn
gj RSHIFT 2 -> gk
cj OR cp -> cq
gj OR gu -> gv
b OR n -> o
o AND q -> r
bi LSHIFT 15 -> bm
dy RSHIFT 1 -> er
cu AND cw -> cx
iw OR ix -> iy
hc OR hd -> he
0 -> c
db OR dc -> dd
kk RSHIFT 2 -> kl
eq LSHIFT 1 -> fk
dz OR ef -> eg
NOT ed -> ee
lw OR lv -> lx
fw AND fy -> fz
dz AND ef -> eh
jp RSHIFT 3 -> jr
lg AND lm -> lo
ci RSHIFT 2 -> cj
be AND bg -> bh
lc LSHIFT 1 -> lw
hm AND ho -> hp
jr AND js -> ju
1 AND io -> ip
cm AND co -> cp
ib OR ic -> id
NOT bf -> bg
fo RSHIFT 5 -> fr
ip LSHIFT 15 -> it
jt AND jv -> jw
jc AND je -> jf
du OR dt -> dv
NOT fx -> fy
aw AND ay -> az
ge LSHIFT 15 -> gi
NOT ak -> al
fm OR fn -> fo
ff AND fh -> fi
ci RSHIFT 5 -> cl
cz OR cy -> da
NOT ey -> ez
NOT ju -> jv
NOT ls -> lt
kk AND kv -> kx
NOT ii -> ij
kl AND kr -> kt
jk LSHIFT 15 -> jo
e OR f -> g
NOT bs -> bt
hi AND hk -> hl
hz OR ik -> il
ek AND em -> en
ao OR an -> ap
dv LSHIFT 1 -> ep
an LSHIFT 15 -> ar
fo RSHIFT 1 -> gh
NOT im -> in
kk RSHIFT 1 -> ld
hw LSHIFT 1 -> iq
ec AND ee -> ef
hb LSHIFT 1 -> hv
kb AND kd -> ke
x AND ai -> ak
dd AND do -> dq
aq OR ar -> as
iq OR ip -> ir
dl AND dn -> do
iu RSHIFT 5 -> ix
as OR bd -> be
NOT go -> gp
fk OR fj -> fl
jm LSHIFT 1 -> kg
NOT cv -> cw
dp AND dr -> ds
dt LSHIFT 15 -> dx
et RSHIFT 1 -> fm
dy RSHIFT 3 -> ea
fp AND fv -> fx
NOT p -> q
dd RSHIFT 2 -> de
eu AND fa -> fc
ba AND bc -> bd
dh AND dj -> dk
lr AND lt -> lu
he RSHIFT 1 -> hx
ex AND ez -> fa
df OR dg -> dh
fj LSHIFT 15 -> fn
NOT kx -> ky
gk OR gq -> gr
dy RSHIFT 2 -> dz
gh OR gi -> gj
lj AND ll -> lm
x OR ai -> aj
bz AND cb -> cc
1 AND lu -> lv
as RSHIFT 3 -> au
ce OR cd -> cf
il AND in -> io
dd RSHIFT 1 -> dw
NOT lo -> lp
c LSHIFT 1 -> t
dd RSHIFT 3 -> df
dd RSHIFT 5 -> dg
lh AND li -> lk
lf RSHIFT 5 -> li
dy RSHIFT 5 -> eb
NOT kt -> ku
at OR az -> ba
x RSHIFT 3 -> z
NOT lk -> ll
lb OR la -> lc
1 AND r -> s
lh OR li -> lj
ln AND lp -> lq
kk RSHIFT 5 -> kn
ea OR eb -> ec
ci AND ct -> cv
b RSHIFT 2 -> d
jp RSHIFT 1 -> ki
NOT cr -> cs
NOT jd -> je
jp RSHIFT 2 -> jq
jn OR jo -> jp
lf RSHIFT 3 -> lh
1 AND ds -> dt
lf AND lq -> ls
la LSHIFT 15 -> le
NOT fg -> fh
at AND az -> bb
au AND av -> ax
kw AND ky -> kz
v OR w -> x
kk OR kv -> kw
ks AND ku -> kv
kh LSHIFT 1 -> lb
1 AND kz -> la
NOT kc -> kd
x RSHIFT 2 -> y
et OR fe -> ff
et AND fe -> fg
NOT ac -> ad
jl OR jk -> jm
1 AND jj -> jk
bn RSHIFT 1 -> cg
NOT kp -> kq
ci RSHIFT 3 -> ck
ev AND ew -> ey
1 AND ke -> kf
cj AND cp -> cr
ir LSHIFT 1 -> jl
NOT gw -> gx
as RSHIFT 2 -> at
iu RSHIFT 1 -> jn
cy LSHIFT 15 -> dc
hg OR hh -> hi
ci RSHIFT 1 -> db
au OR av -> aw
km AND kn -> kp
gj RSHIFT 1 -> hc
iu RSHIFT 2 -> iv
ab AND ad -> ae
da LSHIFT 1 -> du
NOT bw -> bx
km OR kn -> ko
ko AND kq -> kr
bv AND bx -> by
kl OR kr -> ks
1 AND ht -> hu
df AND dg -> di
NOT ag -> ah
d OR j -> k
d AND j -> l
b AND n -> p
gf OR ge -> gg
gg LSHIFT 1 -> ha
bn RSHIFT 5 -> bq
bo OR bu -> bv
1 AND gy -> gz
s LSHIFT 15 -> w
NOT ie -> if
as RSHIFT 5 -> av
bo AND bu -> bw
hz AND ik -> im
bp AND bq -> bs
b RSHIFT 1 -> v
NOT l -> m
bp OR bq -> br
g AND i -> j
br AND bt -> bu
t OR s -> u
hz RSHIFT 5 -> ic
gk AND gq -> gs
fl LSHIFT 1 -> gf
he RSHIFT 3 -> hg
gz LSHIFT 15 -> hd
hf OR hl -> hm
1 AND gd -> ge
fo OR fz -> ga
id AND if -> ig
fo AND fz -> gb
gr AND gt -> gu
he OR hp -> hq
fq AND fr -> ft
ga AND gc -> gd
fo RSHIFT 2 -> fp
gl OR gm -> gn
hg AND hh -> hj
NOT hn -> ho
gl AND gm -> go
he RSHIFT 5 -> hh
NOT gb -> gc
hq AND hs -> ht
hz RSHIFT 3 -> ib
hz RSHIFT 2 -> ia
fq OR fr -> fs
hx OR hy -> hz
he AND hp -> hr
gj RSHIFT 5 -> gm
hf AND hl -> hn
hv OR hu -> hw
NOT hj -> hk
gj RSHIFT 3 -> gl
fo RSHIFT 3 -> fq
he RSHIFT 2 -> hf

138
2015/matrix.py Normal file
View File

@ -0,0 +1,138 @@
split_word_to_int_list = lambda y: [int(w) for w in y]
split_line_to_int_list = lambda y: [int(w) for w in y.split(" ") if w]
def rotate(m, right=True): # -90
x = list(zip(*m[::-1]))
if right:
return x
return [list(reversed(y)) for y in x]
def load_matrix_file(name, func=None):
with open(name, "r") as f:
my_file = []
for line in f:
my_file.append(line.rstrip())
if func:
return [func(x) for x in my_file]
return [split_word_to_int_list(x) for x in my_file]
def get_neighbors(matrix, x, y):
neighbors = []
# left
try:
if x - 1 >= 0:
neighbors.append([(x - 1, y), matrix[y][x - 1]])
except IndexError:
pass
# right
try:
neighbors.append([(x + 1, y), matrix[y][x + 1]])
except IndexError:
pass
# up
try:
if y - 1 >= 0:
neighbors.append([(x, y - 1), matrix[y - 1][x]])
except IndexError:
pass
# down
try:
neighbors.append([(x, y + 1), matrix[y + 1][x]])
except IndexError:
pass
return neighbors
def get_neighbor_coords(matrix, c, r, diagonals=True):
height = len(matrix)
width = len(matrix[0])
if diagonals:
coords = (
(-1, -1), (0, -1), (1, -1),
(-1, 0), (1, 0),
(-1, 1), (0, 1), (1, 1),
)
else:
coords = (
(0, -1),
(-1, 0), (1, 0),
(0, 1),
)
neighbors = []
for _c, _r in coords:
try:
value = matrix[r + _r][c + _c] # Try to get a value error
if (r+_r>=0 and c+_c >= 0):
neighbors.append(
[{"c": c + _c, "r": r + _r}, value]
) # woo, no error, this coord is valid
except IndexError:
pass # okay we out of bounds boizzzz
return neighbors
def get_column(matrix, col):
pass
def matrix_of_size(width, height):
return [[0] * width for x in range(height)]
def get_size(matrix):
height = len(matrix)
width = len(matrix[0])
return height, width
def pmx(*matrices, _or='.', pad=True, space=True):
if len(matrices) > 1:
matrices = list(zip(*matrices))
for row in matrices:
r = []
for col in row:
r.append("".join([f"{int(x)or _or}".rjust(3) for x in col]))
print(" ".join(r))
else:
for row in matrices:
for c in row:
if pad:
f = lambda x: f"{int(x)or _or}".rjust(2)
if space:
f = lambda x: f"{int(x)or _or}".rjust(3)
else:
f = lambda x: f"{int(x)or _or}"
if space:
f = lambda x: f"{int(x)or _or} "
print("".join([f(x) for x in c]))
def ppmx(*matrices, _or=".", pad=True, space=True):
if len(matrices) > 1:
matrices = list(zip(*matrices))
for row in matrices:
r = []
for col in row:
r.append("".join([f"{x or '.'}".rjust(3) for x in col]))
print(" ".join(r))
else:
for row in matrices:
for c in row:
if pad:
f = lambda x: f"{x or '.'}".rjust(2)
if space:
f = lambda x: f"{x or '.'}".rjust(3)
else:
f = lambda x: f"{x or '.'}"
if space:
f = lambda x: f"{x or '.'} "
print("".join([f(x) for x in c]))
def p(*matrices):
pmx(*matrices, _or=" ", pad=False, space=False)

19
2015/sample.py Normal file
View File

@ -0,0 +1,19 @@
import shared
import matrix
from collections import Counter
import numpy as np
def pt1(inp):
pass
def pt1(inp):
pass
def main():
with open(shared.get_fname(7), "r") as f:
inp = [x.rstrip() for x in f.readlines()]
pt1(inp)
#pt2(inp)
if __name__ == "__main__":
main()

8
2015/samples/day07.txt Normal file
View File

@ -0,0 +1,8 @@
123 -> x
456 -> y
x AND y -> d
x OR y -> e
x LSHIFT 2 -> f
y RSHIFT 2 -> g
NOT x -> h
NOT y -> i

31
2015/shared.py Normal file
View File

@ -0,0 +1,31 @@
def get_fname(day: int) -> str:
import sys
if sys.argv[-1] == "--sample":
return f"samples/day{day:02}.txt"
else:
return f"full/day{day:02}.txt"
def load_file_char_matrix(name):
with open(name, "r") as f:
my_file = []
for line in f:
my_file.append(line.rstrip())
return [list(x) for x in my_file]
def load_file_int_matrix(name):
with open(name, "r") as f:
my_file = []
for line in f:
my_file.append(line.rstrip())
return [list(map(int, x)) for x in my_file]
def load_file_word_matrix(name):
with open(name, "r") as f:
my_file = []
for line in f:
my_file.append(line.rstrip())
return [x.split(" ") for x in my_file]