Initial commit
This commit is contained in:
commit
6f916c29d1
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def main():
|
||||
with open('day1', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
floor = 0
|
||||
position = 0
|
||||
for line in lines:
|
||||
for char in line:
|
||||
if char == '(':
|
||||
position += 1
|
||||
floor += 1
|
||||
elif char == ')':
|
||||
position += 1
|
||||
floor -= 1
|
||||
if floor == -1:
|
||||
print(f'{position = }')
|
||||
|
||||
print(f'{floor = }')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -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,36 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def parse_line(line, identifiers):
|
||||
elements = line.split()
|
||||
length = len(elements)
|
||||
match length:
|
||||
case 3: # Assignment
|
||||
return int(elements[0]), elements[2].strip()
|
||||
case 4: # NOT
|
||||
return ~identifiers[elements[1]], elements[3].strip()
|
||||
case 5: # AND OR LSHIFT RSHIFT
|
||||
match elements[1]:
|
||||
case 'AND':
|
||||
return identifiers[elements[0]] & identifiers[elements[2]], elements[4].strip()
|
||||
case 'OR':
|
||||
return identifiers[elements[0]] | identifiers[elements[2]], elements[4].strip()
|
||||
case 'LSHIFT':
|
||||
return identifiers[elements[0]] << int(elements[2]), elements[4].strip()
|
||||
case 'RSHIFT':
|
||||
return identifiers[elements[0]] >> int(elements[2]), elements[4].strip()
|
||||
|
||||
|
||||
def main():
|
||||
with open('day7.sample', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
identifiers = {}
|
||||
for line in lines:
|
||||
value, identifier = parse_line(line, identifiers)
|
||||
identifiers[identifier] = value
|
||||
|
||||
print(identifiers)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -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
|
|
@ -0,0 +1 @@
|
|||
R1, L4, L5, L5, R2, R2, L1, L1, R2, L3, R4, R3, R2, L4, L2, R5, L1, R5, L5, L2, L3, L1, R1, R4, R5, L3, R2, L4, L5, R1, R2, L3, R3, L3, L1, L2, R5, R4, R5, L5, R1, L190, L3, L3, R3, R4, R47, L3, R5, R79, R5, R3, R1, L4, L3, L2, R194, L2, R1, L2, L2, R4, L5, L5, R1, R1, L1, L3, L2, R5, L3, L3, R4, R1, R5, L4, R3, R1, L1, L2, R4, R1, L2, R4, R4, L5, R3, L5, L3, R1, R1, L3, L1, L1, L3, L4, L1, L2, R1, L5, L3, R2, L5, L3, R5, R3, L4, L2, R2, R4, R4, L4, R5, L1, L3, R3, R4, R4, L5, R4, R2, L3, R4, R2, R1, R2, L4, L2, R2, L5, L5, L3, R5, L5, L1, R4, L1, R1, L1, R4, L5, L3, R4, R1, L3, R4, R1, L3, L1, R1, R2, L4, L2, R1, L5, L4, L5
|
|
@ -0,0 +1,98 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def turn(direction, facing):
|
||||
match facing:
|
||||
case 'North':
|
||||
if direction == 'R':
|
||||
facing = 'East'
|
||||
else:
|
||||
facing = 'West'
|
||||
case 'East':
|
||||
if direction == 'R':
|
||||
facing = 'South'
|
||||
else:
|
||||
facing = 'North'
|
||||
case 'South':
|
||||
if direction == 'R':
|
||||
facing = 'West'
|
||||
else:
|
||||
facing = 'East'
|
||||
case 'West':
|
||||
if direction == 'R':
|
||||
facing = 'North'
|
||||
else:
|
||||
facing = 'South'
|
||||
return facing
|
||||
|
||||
|
||||
def check_locations(blocks, facing, x_coord, y_coord, locations):
|
||||
x_coord, y_coord = locations[-1]
|
||||
match facing:
|
||||
case 'North':
|
||||
for block in range(1, blocks + 1):
|
||||
if [x_coord + block, y_coord] in locations:
|
||||
return [x_coord + block, y_coord]
|
||||
locations.append([x_coord + block, y_coord])
|
||||
case 'East':
|
||||
for block in range(1, blocks + 1):
|
||||
if [x_coord, y_coord + block] in locations:
|
||||
return [x_coord, y_coord + block]
|
||||
locations.append([x_coord, y_coord + block])
|
||||
case 'South':
|
||||
for block in range(1, blocks + 1):
|
||||
if [x_coord - block, y_coord] in locations:
|
||||
return [x_coord - block, y_coord]
|
||||
locations.append([x_coord - block, y_coord])
|
||||
case 'West':
|
||||
for block in range(1, blocks + 1):
|
||||
if [x_coord, y_coord - block] in locations:
|
||||
return [x_coord, y_coord - block]
|
||||
locations.append([x_coord, y_coord - block])
|
||||
|
||||
|
||||
def walk(blocks, facing, x_coord, y_coord):
|
||||
match facing:
|
||||
case 'North':
|
||||
x_coord += blocks
|
||||
case 'East':
|
||||
y_coord += blocks
|
||||
case 'South':
|
||||
x_coord -= blocks
|
||||
case 'West':
|
||||
y_coord -= blocks
|
||||
return x_coord, y_coord
|
||||
|
||||
|
||||
def main():
|
||||
x_coord = 0
|
||||
y_coord = 0
|
||||
facing = 'North'
|
||||
|
||||
with open('day1', 'r') as file:
|
||||
line = file.readlines()[0][:-1]
|
||||
|
||||
sequences = line.split(', ')
|
||||
|
||||
locations = [[0,0]]
|
||||
hq_loc = []
|
||||
|
||||
for sequence in sequences:
|
||||
direction = sequence[0]
|
||||
blocks = int(sequence[1:])
|
||||
facing = turn(direction, facing)
|
||||
x_coord, y_coord = walk(blocks , facing, x_coord, y_coord)
|
||||
|
||||
for sequence in sequences:
|
||||
direction = sequence[0]
|
||||
blocks = int(sequence[1:])
|
||||
facing = turn(direction, facing)
|
||||
hq_loc = check_locations(blocks, facing, x_coord, y_coord, locations)
|
||||
if hq_loc:
|
||||
break
|
||||
|
||||
print(abs(x_coord) + abs(y_coord))
|
||||
print(abs(hq_loc[0]) + abs(hq_loc[1]))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1 @@
|
|||
181445682966897848665963472661939865313976877194312684993521259486517527961396717561854825453963181134379574918373213732184697746668399631642622373684425326112585283946462323363991753895647177797691214784149215198715986947573668987188746878678399624533792551651335979847131975965677957755571358934665327487287312467771187981424785514785421781781976477326712674311994735947987383516699897916595433228294198759715959469578766739518475118771755787196238772345762941477359483456641194685333528329581113788599843621326313592354167846466415943566183192946217689936174884493199368681514958669615226362538622898367728662941275658917124167353496334664239539753835439929664552886538885727235662548783529353611441231681613535447417941911479391558481443933134283852879511395429489152435996669232681215627723723565872291296878528334773391626672491878762288953597499218397146685679387438634857358552943964839321464529237533868734473777756775687759355878519113426969197211824325893376812556798483325994128743242544899625215765851923959798197562831313891371735973761384464685316273343541852758525318144681364492173465174512856618292785483181956548813344752352933634979165667651165776587656468598791994573513652324764687515345959621493346623821965554755615219855842969932269414839446887613738174567989512857785566352285988991946436148652839391593178736624957214917527759574235133666461988355855613377789115472297915429318142824465141688559333787512328799783539285826471818279818457674417354335454395644435889386297695625378256613558911695145397779576526397241795181294322797687168326696497256684943829666672341162656479563522892141714998477865114944671225898297338685958644728534192317628618817551492975251364233974374724968483637518876583946828819994321129556511537619253381981544394112184655586964655164192552352534626295996968762388827294873362719636616182786976922445125551927969267591395292198155775434997827738862786341543524544822321112131815475829945625787561369956264826651461575948462782869972654343749617939132353399334744265286151177931594514857563664329299713436914721119746932159456287267887878779218815883191236858656959258484139254446341
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def main():
|
||||
with open('day1', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
line = lines[0]
|
||||
total = 0
|
||||
first = False
|
||||
for index, num in enumerate(line):
|
||||
try:
|
||||
if line[index] == line[index + 1]:
|
||||
if first:
|
||||
total += int(num)
|
||||
else:
|
||||
total += int(line[index]) + int(line[index + 1])
|
||||
first = True
|
||||
except IndexError:
|
||||
if line[index] == line[0]:
|
||||
total += int(num)
|
||||
|
||||
print(total)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
lis = []
|
||||
for line in open("day4.sample"):
|
||||
print(line)
|
||||
for word in line.split():
|
||||
lis.append(word)
|
||||
|
||||
|
||||
|
||||
print([word for line in open("day4.sample") for word in line.split()])
|
||||
|
||||
|
||||
|
||||
print(lis, type(lis))
|
|
@ -0,0 +1,3 @@
|
|||
sayndz zfxlkl attjtww cti sokkmty brx fhh suelqbp
|
||||
xmuf znkhaes pggrlp zia znkhaes znkhaes
|
||||
nti rxr bogebb zdwrin
|
|
@ -0,0 +1,200 @@
|
|||
1844
|
||||
1123
|
||||
1490
|
||||
1478
|
||||
1108
|
||||
1120
|
||||
1594
|
||||
1101
|
||||
1831
|
||||
1146
|
||||
1084
|
||||
1535
|
||||
1016
|
||||
1722
|
||||
1388
|
||||
1188
|
||||
1351
|
||||
1477
|
||||
1215
|
||||
1678
|
||||
1159
|
||||
1558
|
||||
1581
|
||||
1400
|
||||
1550
|
||||
1306
|
||||
1852
|
||||
1745
|
||||
1224
|
||||
1896
|
||||
1596
|
||||
1005
|
||||
1499
|
||||
1797
|
||||
976
|
||||
1777
|
||||
1129
|
||||
1601
|
||||
1058
|
||||
1510
|
||||
1704
|
||||
1818
|
||||
1795
|
||||
1364
|
||||
1276
|
||||
1362
|
||||
1801
|
||||
1985
|
||||
1421
|
||||
1311
|
||||
1855
|
||||
1977
|
||||
1613
|
||||
1951
|
||||
2001
|
||||
1327
|
||||
1872
|
||||
1517
|
||||
1040
|
||||
1692
|
||||
1595
|
||||
1769
|
||||
1956
|
||||
1763
|
||||
1470
|
||||
1898
|
||||
1366
|
||||
1443
|
||||
312
|
||||
1685
|
||||
1014
|
||||
1409
|
||||
1717
|
||||
1105
|
||||
1290
|
||||
1703
|
||||
1732
|
||||
1939
|
||||
1790
|
||||
1164
|
||||
1225
|
||||
1474
|
||||
1713
|
||||
1413
|
||||
1906
|
||||
1488
|
||||
1931
|
||||
1702
|
||||
1848
|
||||
1668
|
||||
1737
|
||||
1614
|
||||
1719
|
||||
1647
|
||||
1171
|
||||
1508
|
||||
1035
|
||||
1133
|
||||
1179
|
||||
1180
|
||||
1472
|
||||
1414
|
||||
1659
|
||||
1820
|
||||
1544
|
||||
1697
|
||||
1175
|
||||
1033
|
||||
1805
|
||||
1576
|
||||
1196
|
||||
1597
|
||||
1739
|
||||
1291
|
||||
1103
|
||||
1457
|
||||
1514
|
||||
1462
|
||||
1619
|
||||
1683
|
||||
1338
|
||||
1604
|
||||
1372
|
||||
1653
|
||||
16
|
||||
1725
|
||||
1181
|
||||
1952
|
||||
1201
|
||||
1531
|
||||
1505
|
||||
1912
|
||||
1527
|
||||
1853
|
||||
1905
|
||||
1833
|
||||
1913
|
||||
1131
|
||||
1069
|
||||
1537
|
||||
1754
|
||||
1551
|
||||
1435
|
||||
1914
|
||||
1093
|
||||
1273
|
||||
1726
|
||||
1094
|
||||
1439
|
||||
1689
|
||||
1607
|
||||
1646
|
||||
1588
|
||||
1698
|
||||
1539
|
||||
1493
|
||||
1352
|
||||
1163
|
||||
1482
|
||||
1044
|
||||
1523
|
||||
1142
|
||||
1253
|
||||
1250
|
||||
1986
|
||||
1049
|
||||
1330
|
||||
1219
|
||||
1162
|
||||
1088
|
||||
1100
|
||||
1532
|
||||
1727
|
||||
1761
|
||||
1107
|
||||
1916
|
||||
1220
|
||||
1319
|
||||
1098
|
||||
1431
|
||||
1260
|
||||
1642
|
||||
1269
|
||||
1102
|
||||
1432
|
||||
1267
|
||||
1824
|
||||
1658
|
||||
1149
|
||||
1024
|
||||
1963
|
||||
1498
|
||||
1904
|
||||
1812
|
||||
1600
|
||||
1773
|
||||
1283
|
||||
1463
|
||||
1776
|
||||
1406
|
|
@ -0,0 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def main():
|
||||
with open('day1', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
numbers = []
|
||||
for line in lines:
|
||||
first = int(line.strip())
|
||||
for sec in lines:
|
||||
second = int(sec)
|
||||
if (first + second) == 2020:
|
||||
print(first,second, first * second)
|
||||
for thi in lines:
|
||||
third = int(thi)
|
||||
if (first + second + third) == 2020:
|
||||
print(first, second, third, first * second * third)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,6 @@
|
|||
1721
|
||||
979
|
||||
366
|
||||
299
|
||||
675
|
||||
1456
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def main():
|
||||
with open('day1', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
prev = lines[0]
|
||||
count = 0
|
||||
for line in lines[1:]:
|
||||
if int(prev) < int(line.strip()):
|
||||
count += 1
|
||||
prev = line
|
||||
|
||||
print(count)
|
||||
|
||||
prev = int(lines[0]) + int(lines[1]) + int(lines[2])
|
||||
count = 0
|
||||
for index in range(len(lines) - 3):
|
||||
if prev < int(lines[index+1]) + int(lines[index+2]) + int(lines[index+3]):
|
||||
count += 1
|
||||
prev = int(lines[index+1]) + int(lines[index+2]) + int(lines[index+3])
|
||||
|
||||
print(count)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,963 @@
|
|||
1026,284
|
||||
612,2
|
||||
355,653
|
||||
711,884
|
||||
1205,14
|
||||
971,348
|
||||
550,313
|
||||
1261,236
|
||||
1155,838
|
||||
33,487
|
||||
1287,690
|
||||
1230,722
|
||||
1230,110
|
||||
73,854
|
||||
1178,81
|
||||
216,719
|
||||
875,794
|
||||
900,334
|
||||
1277,61
|
||||
783,240
|
||||
1099,159
|
||||
303,528
|
||||
624,327
|
||||
108,322
|
||||
698,444
|
||||
990,397
|
||||
1131,856
|
||||
527,273
|
||||
1195,831
|
||||
1029,49
|
||||
1220,688
|
||||
177,724
|
||||
671,478
|
||||
1016,807
|
||||
385,141
|
||||
944,140
|
||||
1084,525
|
||||
984,893
|
||||
1265,243
|
||||
793,543
|
||||
334,581
|
||||
780,128
|
||||
326,669
|
||||
826,845
|
||||
609,38
|
||||
299,126
|
||||
828,758
|
||||
607,212
|
||||
818,313
|
||||
296,343
|
||||
127,421
|
||||
612,486
|
||||
571,294
|
||||
811,838
|
||||
192,45
|
||||
991,516
|
||||
80,546
|
||||
554,547
|
||||
592,33
|
||||
311,192
|
||||
1237,488
|
||||
1205,880
|
||||
1131,605
|
||||
542,410
|
||||
344,674
|
||||
284,284
|
||||
326,569
|
||||
976,581
|
||||
1292,795
|
||||
70,494
|
||||
847,320
|
||||
62,275
|
||||
842,705
|
||||
393,792
|
||||
678,294
|
||||
313,1
|
||||
559,775
|
||||
11,457
|
||||
646,544
|
||||
144,67
|
||||
559,878
|
||||
1066,782
|
||||
492,549
|
||||
45,682
|
||||
1128,84
|
||||
746,323
|
||||
291,585
|
||||
713,786
|
||||
774,86
|
||||
597,114
|
||||
1005,75
|
||||
488,446
|
||||
94,527
|
||||
269,589
|
||||
423,617
|
||||
258,591
|
||||
395,23
|
||||
1205,238
|
||||
340,420
|
||||
27,261
|
||||
587,792
|
||||
170,173
|
||||
972,254
|
||||
875,396
|
||||
1131,528
|
||||
850,2
|
||||
892,94
|
||||
490,873
|
||||
1081,628
|
||||
1041,254
|
||||
925,219
|
||||
1245,435
|
||||
969,109
|
||||
984,673
|
||||
627,411
|
||||
689,855
|
||||
711,487
|
||||
1294,668
|
||||
209,18
|
||||
981,2
|
||||
885,360
|
||||
1101,204
|
||||
499,201
|
||||
870,193
|
||||
435,794
|
||||
107,212
|
||||
1210,99
|
||||
639,864
|
||||
445,18
|
||||
564,766
|
||||
127,660
|
||||
1295,724
|
||||
62,705
|
||||
15,170
|
||||
595,775
|
||||
428,11
|
||||
189,325
|
||||
831,73
|
||||
380,735
|
||||
803,394
|
||||
898,100
|
||||
1243,344
|
||||
1099,253
|
||||
970,868
|
||||
865,38
|
||||
1227,854
|
||||
0,542
|
||||
490,318
|
||||
831,821
|
||||
373,428
|
||||
1193,652
|
||||
1074,542
|
||||
483,133
|
||||
1297,221
|
||||
1108,729
|
||||
726,848
|
||||
705,684
|
||||
202,506
|
||||
397,793
|
||||
536,86
|
||||
684,401
|
||||
1014,674
|
||||
1206,313
|
||||
1216,255
|
||||
134,849
|
||||
189,95
|
||||
706,661
|
||||
662,257
|
||||
396,863
|
||||
616,165
|
||||
1017,285
|
||||
917,254
|
||||
475,500
|
||||
377,658
|
||||
231,103
|
||||
261,550
|
||||
1014,253
|
||||
892,653
|
||||
1265,341
|
||||
492,245
|
||||
1261,96
|
||||
785,722
|
||||
1170,362
|
||||
933,210
|
||||
268,112
|
||||
961,75
|
||||
1260,233
|
||||
1253,667
|
||||
848,849
|
||||
1299,546
|
||||
1036,159
|
||||
1011,126
|
||||
385,723
|
||||
30,327
|
||||
47,682
|
||||
1309,208
|
||||
522,793
|
||||
406,570
|
||||
592,189
|
||||
499,873
|
||||
1216,415
|
||||
236,542
|
||||
1183,869
|
||||
586,59
|
||||
564,284
|
||||
130,807
|
||||
490,128
|
||||
870,253
|
||||
666,780
|
||||
1014,641
|
||||
1133,170
|
||||
1268,296
|
||||
805,394
|
||||
423,197
|
||||
62,640
|
||||
554,291
|
||||
162,128
|
||||
97,136
|
||||
1041,589
|
||||
644,478
|
||||
739,600
|
||||
202,729
|
||||
937,362
|
||||
1260,141
|
||||
900,784
|
||||
874,546
|
||||
766,719
|
||||
974,463
|
||||
140,362
|
||||
351,338
|
||||
1033,236
|
||||
915,863
|
||||
97,696
|
||||
386,784
|
||||
62,702
|
||||
370,200
|
||||
277,236
|
||||
800,84
|
||||
1019,585
|
||||
1213,422
|
||||
999,590
|
||||
564,653
|
||||
274,719
|
||||
179,366
|
||||
791,768
|
||||
1213,24
|
||||
728,795
|
||||
276,213
|
||||
1248,204
|
||||
279,178
|
||||
887,276
|
||||
609,856
|
||||
383,39
|
||||
522,81
|
||||
1230,784
|
||||
933,236
|
||||
783,660
|
||||
1190,162
|
||||
1111,137
|
||||
524,807
|
||||
343,438
|
||||
274,607
|
||||
960,420
|
||||
1277,385
|
||||
1303,154
|
||||
52,771
|
||||
776,21
|
||||
1084,291
|
||||
795,752
|
||||
358,551
|
||||
502,338
|
||||
564,654
|
||||
197,498
|
||||
694,165
|
||||
1298,619
|
||||
726,324
|
||||
229,360
|
||||
604,661
|
||||
175,681
|
||||
45,385
|
||||
1265,354
|
||||
1299,180
|
||||
1155,693
|
||||
38,378
|
||||
1119,635
|
||||
351,80
|
||||
1134,499
|
||||
530,542
|
||||
607,570
|
||||
898,336
|
||||
494,448
|
||||
124,240
|
||||
530,352
|
||||
209,316
|
||||
216,175
|
||||
845,325
|
||||
433,753
|
||||
281,10
|
||||
970,420
|
||||
756,547
|
||||
1150,448
|
||||
1300,332
|
||||
990,133
|
||||
120,162
|
||||
1211,198
|
||||
1041,108
|
||||
1006,824
|
||||
57,108
|
||||
281,532
|
||||
1227,600
|
||||
0,38
|
||||
248,324
|
||||
701,38
|
||||
874,644
|
||||
1029,532
|
||||
643,546
|
||||
390,544
|
||||
1074,459
|
||||
771,417
|
||||
701,89
|
||||
93,429
|
||||
522,529
|
||||
219,407
|
||||
254,99
|
||||
435,851
|
||||
1081,11
|
||||
1034,141
|
||||
440,865
|
||||
967,273
|
||||
644,561
|
||||
560,255
|
||||
811,761
|
||||
643,714
|
||||
335,628
|
||||
527,654
|
||||
991,826
|
||||
269,780
|
||||
1155,761
|
||||
666,562
|
||||
132,81
|
||||
606,124
|
||||
534,694
|
||||
100,99
|
||||
229,628
|
||||
1310,466
|
||||
1004,382
|
||||
385,780
|
||||
1186,318
|
||||
1131,842
|
||||
1197,135
|
||||
179,842
|
||||
698,2
|
||||
175,821
|
||||
226,603
|
||||
932,690
|
||||
776,648
|
||||
621,285
|
||||
445,876
|
||||
1148,345
|
||||
728,877
|
||||
350,70
|
||||
124,521
|
||||
136,301
|
||||
763,548
|
||||
641,634
|
||||
1026,532
|
||||
1213,792
|
||||
1257,821
|
||||
1017,39
|
||||
1213,266
|
||||
724,59
|
||||
1258,771
|
||||
242,794
|
||||
199,49
|
||||
966,674
|
||||
971,796
|
||||
587,316
|
||||
917,640
|
||||
574,348
|
||||
10,113
|
||||
997,893
|
||||
105,238
|
||||
366,826
|
||||
211,159
|
||||
385,675
|
||||
139,781
|
||||
1248,189
|
||||
684,45
|
||||
1134,171
|
||||
425,326
|
||||
281,49
|
||||
281,84
|
||||
639,58
|
||||
1171,304
|
||||
1215,471
|
||||
62,254
|
||||
980,626
|
||||
999,304
|
||||
1022,364
|
||||
621,833
|
||||
1096,865
|
||||
999,621
|
||||
557,248
|
||||
867,794
|
||||
952,220
|
||||
522,101
|
||||
534,200
|
||||
807,73
|
||||
90,508
|
||||
597,395
|
||||
627,483
|
||||
418,800
|
||||
788,81
|
||||
654,121
|
||||
1166,532
|
||||
62,749
|
||||
105,14
|
||||
1014,551
|
||||
976,133
|
||||
179,605
|
||||
518,558
|
||||
268,784
|
||||
1156,798
|
||||
818,766
|
||||
346,756
|
||||
246,336
|
||||
59,103
|
||||
1161,455
|
||||
350,672
|
||||
194,493
|
||||
160,448
|
||||
547,263
|
||||
1245,584
|
||||
780,364
|
||||
311,456
|
||||
428,413
|
||||
892,205
|
||||
310,738
|
||||
530,766
|
||||
97,430
|
||||
1178,365
|
||||
940,162
|
||||
585,773
|
||||
296,674
|
||||
197,844
|
||||
1263,212
|
||||
45,877
|
||||
177,170
|
||||
254,599
|
||||
999,276
|
||||
739,114
|
||||
269,227
|
||||
1252,112
|
||||
937,466
|
||||
477,394
|
||||
132,365
|
||||
18,795
|
||||
410,110
|
||||
612,408
|
||||
370,732
|
||||
97,422
|
||||
1248,749
|
||||
339,42
|
||||
780,542
|
||||
811,348
|
||||
557,136
|
||||
263,472
|
||||
154,798
|
||||
574,558
|
||||
527,212
|
||||
1283,821
|
||||
1222,397
|
||||
294,359
|
||||
956,294
|
||||
455,397
|
||||
373,84
|
||||
1091,234
|
||||
378,690
|
||||
1121,569
|
||||
1052,31
|
||||
398,46
|
||||
674,138
|
||||
293,609
|
||||
1300,751
|
||||
139,590
|
||||
776,694
|
||||
1,226
|
||||
1047,472
|
||||
723,887
|
||||
1253,114
|
||||
589,94
|
||||
780,318
|
||||
45,540
|
||||
315,348
|
||||
1139,166
|
||||
691,645
|
||||
783,269
|
||||
862,38
|
||||
1178,450
|
||||
15,724
|
||||
992,462
|
||||
229,180
|
||||
1133,410
|
||||
1238,547
|
||||
530,318
|
||||
124,542
|
||||
541,759
|
||||
1255,407
|
||||
920,544
|
||||
139,304
|
||||
380,159
|
||||
672,674
|
||||
77,138
|
||||
398,772
|
||||
1215,327
|
||||
77,756
|
||||
694,427
|
||||
776,226
|
||||
1146,889
|
||||
1275,297
|
||||
343,273
|
||||
664,798
|
||||
535,72
|
||||
1108,164
|
||||
385,640
|
||||
68,143
|
||||
264,145
|
||||
763,407
|
||||
919,198
|
||||
1220,571
|
||||
436,644
|
||||
314,868
|
||||
669,484
|
||||
339,98
|
||||
1265,682
|
||||
666,333
|
||||
763,346
|
||||
786,807
|
||||
428,525
|
||||
1176,849
|
||||
1113,844
|
||||
366,875
|
||||
155,469
|
||||
534,284
|
||||
1294,786
|
||||
477,113
|
||||
115,570
|
||||
648,313
|
||||
1178,345
|
||||
967,590
|
||||
949,39
|
||||
445,690
|
||||
372,136
|
||||
1277,487
|
||||
209,486
|
||||
57,780
|
||||
984,876
|
||||
396,591
|
||||
375,255
|
||||
1303,826
|
||||
236,459
|
||||
560,639
|
||||
822,446
|
||||
358,668
|
||||
1074,94
|
||||
833,394
|
||||
753,459
|
||||
1171,113
|
||||
1220,123
|
||||
299,521
|
||||
599,487
|
||||
326,893
|
||||
16,108
|
||||
99,696
|
||||
1171,590
|
||||
550,581
|
||||
952,332
|
||||
484,621
|
||||
115,63
|
||||
1158,445
|
||||
219,234
|
||||
1016,87
|
||||
479,73
|
||||
1005,819
|
||||
32,87
|
||||
130,87
|
||||
416,721
|
||||
780,373
|
||||
350,420
|
||||
1026,834
|
||||
683,768
|
||||
1094,47
|
||||
393,542
|
||||
557,292
|
||||
246,768
|
||||
385,499
|
||||
221,141
|
||||
1268,598
|
||||
390,145
|
||||
1041,590
|
||||
959,338
|
||||
1148,21
|
||||
313,561
|
||||
477,500
|
||||
855,621
|
||||
746,284
|
||||
872,847
|
||||
97,24
|
||||
927,39
|
||||
627,821
|
||||
887,343
|
||||
909,210
|
||||
284,532
|
||||
776,284
|
||||
914,591
|
||||
703,831
|
||||
816,448
|
||||
1260,661
|
||||
1205,126
|
||||
574,546
|
||||
763,375
|
||||
967,254
|
||||
507,38
|
||||
155,133
|
||||
498,89
|
||||
231,690
|
||||
373,466
|
||||
42,598
|
||||
586,54
|
||||
914,303
|
||||
919,646
|
||||
932,242
|
||||
826,621
|
||||
1252,782
|
||||
514,705
|
||||
933,535
|
||||
105,880
|
||||
1146,535
|
||||
1,208
|
||||
340,868
|
||||
176,499
|
||||
557,198
|
||||
574,110
|
||||
994,254
|
||||
701,805
|
||||
917,577
|
||||
319,516
|
||||
460,786
|
||||
564,688
|
||||
1230,558
|
||||
1265,877
|
||||
937,84
|
||||
905,84
|
||||
1186,206
|
||||
952,551
|
||||
633,595
|
||||
277,210
|
||||
667,9
|
||||
18,99
|
||||
246,322
|
||||
1155,166
|
||||
537,354
|
||||
882,861
|
||||
120,873
|
||||
206,572
|
||||
94,415
|
||||
820,784
|
||||
701,465
|
||||
967,142
|
||||
957,101
|
||||
703,324
|
||||
609,651
|
||||
274,383
|
||||
393,688
|
||||
997,113
|
||||
627,768
|
||||
1213,214
|
||||
974,350
|
||||
418,206
|
||||
296,641
|
||||
246,558
|
||||
1258,186
|
||||
291,521
|
||||
1248,254
|
||||
536,808
|
||||
47,212
|
||||
1183,234
|
||||
1042,110
|
||||
156,89
|
||||
152,21
|
||||
127,436
|
||||
587,887
|
||||
833,113
|
||||
1033,882
|
||||
937,458
|
||||
90,386
|
||||
1036,735
|
||||
638,108
|
||||
947,309
|
||||
15,836
|
||||
400,795
|
||||
107,498
|
||||
326,18
|
||||
194,625
|
||||
1253,141
|
||||
445,130
|
||||
418,653
|
||||
518,593
|
||||
1242,751
|
||||
171,728
|
||||
18,771
|
||||
65,352
|
||||
47,324
|
||||
1108,506
|
||||
68,751
|
||||
875,548
|
||||
314,474
|
||||
1108,165
|
||||
709,821
|
||||
140,189
|
||||
1205,432
|
||||
408,770
|
||||
293,386
|
||||
708,771
|
||||
919,248
|
||||
736,722
|
||||
1233,756
|
||||
736,348
|
||||
1216,639
|
||||
97,628
|
||||
832,395
|
||||
875,487
|
||||
878,0
|
||||
930,607
|
||||
671,836
|
||||
390,413
|
||||
547,487
|
||||
373,234
|
||||
599,407
|
||||
452,602
|
||||
45,341
|
||||
937,884
|
||||
1283,633
|
||||
269,108
|
||||
831,521
|
||||
751,343
|
||||
52,571
|
||||
981,238
|
||||
90,123
|
||||
288,19
|
||||
818,245
|
||||
1158,415
|
||||
811,693
|
||||
1272,50
|
||||
783,436
|
||||
1091,711
|
||||
97,214
|
||||
435,407
|
||||
261,102
|
||||
1056,99
|
||||
788,549
|
||||
656,121
|
||||
301,351
|
||||
423,103
|
||||
162,649
|
||||
1253,780
|
||||
45,212
|
||||
492,128
|
||||
242,346
|
||||
189,773
|
||||
1042,784
|
||||
1000,556
|
||||
547,346
|
||||
13,708
|
||||
293,855
|
||||
221,96
|
||||
319,628
|
||||
433,798
|
||||
279,271
|
||||
773,710
|
||||
835,366
|
||||
761,768
|
||||
1061,532
|
||||
55,212
|
||||
1014,103
|
||||
567,666
|
||||
654,38
|
||||
1198,410
|
||||
503,73
|
||||
343,254
|
||||
288,530
|
||||
803,856
|
||||
805,439
|
||||
372,758
|
||||
12,275
|
||||
530,373
|
||||
358,332
|
||||
689,61
|
||||
296,114
|
||||
1158,21
|
||||
592,861
|
||||
619,645
|
||||
425,646
|
||||
281,845
|
||||
433,141
|
||||
1241,325
|
||||
154,544
|
||||
721,94
|
||||
1178,338
|
||||
10,562
|
||||
499,56
|
||||
724,54
|
||||
492,560
|
||||
933,658
|
||||
827,133
|
||||
1081,360
|
||||
1068,336
|
||||
325,892
|
||||
53,821
|
||||
994,864
|
||||
170,621
|
||||
440,641
|
||||
527,240
|
||||
1297,673
|
||||
1175,96
|
||||
311,276
|
||||
1183,421
|
||||
858,602
|
||||
1245,459
|
||||
306,512
|
||||
541,154
|
||||
1123,304
|
||||
1148,128
|
||||
534,668
|
||||
626,45
|
||||
736,336
|
||||
267,343
|
||||
492,101
|
||||
638,332
|
||||
231,791
|
||||
1108,542
|
||||
1061,756
|
||||
587,344
|
||||
1178,556
|
||||
713,114
|
||||
361,855
|
||||
244,602
|
||||
1211,696
|
||||
828,880
|
||||
910,795
|
||||
537,710
|
||||
1288,196
|
||||
164,318
|
||||
304,420
|
||||
65,584
|
||||
1026,648
|
||||
72,547
|
||||
982,225
|
||||
959,80
|
||||
320,761
|
||||
11,546
|
||||
525,396
|
||||
902,770
|
||||
1183,436
|
||||
984,18
|
||||
820,873
|
||||
492,345
|
||||
999,456
|
||||
862,892
|
||||
1146,318
|
||||
944,530
|
||||
187,304
|
||||
1047,696
|
||||
971,98
|
||||
1235,722
|
||||
279,324
|
||||
57,786
|
||||
518,348
|
||||
10,332
|
||||
154,350
|
||||
344,220
|
||||
249,756
|
||||
269,171
|
||||
636,67
|
||||
740,784
|
||||
1186,542
|
||||
1029,845
|
||||
808,21
|
||||
59,775
|
||||
391,696
|
||||
756,603
|
||||
704,770
|
||||
313,551
|
||||
373,884
|
||||
967,459
|
||||
749,429
|
||||
780,688
|
||||
277,12
|
||||
300,369
|
||||
885,646
|
||||
918,472
|
||||
1041,171
|
||||
606,770
|
||||
277,882
|
||||
425,86
|
||||
1099,511
|
||||
1056,599
|
||||
1265,509
|
||||
1033,12
|
||||
1156,544
|
||||
739,294
|
||||
933,684
|
||||
499,838
|
||||
416,173
|
||||
641,260
|
||||
300,525
|
||||
194,269
|
||||
378,652
|
||||
1163,285
|
||||
713,443
|
||||
281,18
|
||||
643,9
|
||||
1053,325
|
||||
1186,240
|
||||
274,511
|
||||
23,204
|
||||
567,228
|
||||
186,257
|
||||
268,110
|
||||
592,77
|
||||
887,103
|
||||
769,154
|
||||
683,73
|
||||
1223,228
|
||||
479,521
|
||||
281,789
|
||||
1046,145
|
||||
1084,883
|
||||
557,602
|
||||
662,637
|
||||
628,600
|
||||
105,126
|
||||
440,193
|
||||
1198,484
|
||||
482,758
|
||||
997,561
|
||||
490,466
|
||||
136,546
|
||||
736,546
|
||||
956,525
|
||||
|
||||
fold along x=655
|
||||
fold along y=447
|
||||
fold along x=327
|
||||
fold along y=223
|
||||
fold along x=163
|
||||
fold along y=111
|
||||
fold along x=81
|
||||
fold along y=55
|
||||
fold along x=40
|
||||
fold along y=27
|
||||
fold along y=13
|
||||
fold along y=6
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def get_max_coords(points):
|
||||
max_x = 0
|
||||
max_y = 0
|
||||
for x, y in points:
|
||||
if int(x) > max_x:
|
||||
max_x = int(x)
|
||||
if int(y) > max_y:
|
||||
max_y = int(y)
|
||||
return max_x, max_y
|
||||
|
||||
|
||||
def print_coords(points, max_x, max_y):
|
||||
for y in range(max_y + 1):
|
||||
for x in range(max_x + 1):
|
||||
if [f'{x}',f'{y}'] in points:
|
||||
print('#', end='')
|
||||
else:
|
||||
print('.', end='')
|
||||
print()
|
||||
|
||||
|
||||
def fold_y(points, temp_points, line):
|
||||
for x, y in points:
|
||||
x = int(x)
|
||||
y = int(y)
|
||||
if y > line:
|
||||
new_y = line - (y - line)
|
||||
temp_points.append([f'{x}', f'{new_y}'])
|
||||
else:
|
||||
temp_points.append([f'{x}', f'{y}'])
|
||||
|
||||
|
||||
def fold_x(points, temp_points, line):
|
||||
for x, y in points:
|
||||
x = int(x)
|
||||
y = int(y)
|
||||
if x > line:
|
||||
new_x = line - (x - line)
|
||||
temp_points.append([f'{new_x}', f'{y}'])
|
||||
else:
|
||||
temp_points.append([f'{x}' ,f'{y}'])
|
||||
|
||||
|
||||
def do_instructions(instructions, points):
|
||||
first = True
|
||||
for axis, line in instructions:
|
||||
line = int(line)
|
||||
temp_points = []
|
||||
match axis:
|
||||
case 'y':
|
||||
fold_y(points, temp_points, line)
|
||||
case 'x':
|
||||
fold_x(points, temp_points, line)
|
||||
if first:
|
||||
get_uniq = [tuple(point) for point in temp_points]
|
||||
print(len(set(tuple(get_uniq))))
|
||||
first = False
|
||||
points = temp_points
|
||||
return points
|
||||
|
||||
|
||||
def main():
|
||||
with open('day13', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
instructions = []
|
||||
points = []
|
||||
for line in lines:
|
||||
line = line.strip().split(',')
|
||||
if len(line) == 2:
|
||||
points.append(line)
|
||||
elif line[0] == '':
|
||||
pass
|
||||
else:
|
||||
line = line[0].split()
|
||||
instructions.append(line[2].split('='))
|
||||
|
||||
points = do_instructions(instructions, points)
|
||||
max_x, max_y = get_max_coords(points)
|
||||
print_coords(points, max_x, max_y)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,21 @@
|
|||
6,10
|
||||
0,14
|
||||
9,10
|
||||
0,3
|
||||
10,4
|
||||
4,11
|
||||
6,0
|
||||
6,12
|
||||
4,1
|
||||
0,13
|
||||
10,12
|
||||
3,4
|
||||
3,0
|
||||
8,4
|
||||
1,10
|
||||
2,14
|
||||
8,10
|
||||
9,0
|
||||
|
||||
fold along y=7
|
||||
fold along x=5
|
|
@ -0,0 +1,102 @@
|
|||
KBKPHKHHNBCVCHPSPNHF
|
||||
|
||||
OP -> H
|
||||
CF -> C
|
||||
BB -> V
|
||||
KH -> O
|
||||
CV -> S
|
||||
FV -> O
|
||||
FS -> K
|
||||
KO -> C
|
||||
PP -> S
|
||||
SH -> K
|
||||
FH -> O
|
||||
NF -> H
|
||||
PN -> P
|
||||
BO -> H
|
||||
OK -> K
|
||||
PO -> P
|
||||
SF -> K
|
||||
BF -> P
|
||||
HH -> S
|
||||
KP -> H
|
||||
HB -> N
|
||||
NP -> V
|
||||
KK -> P
|
||||
PF -> P
|
||||
BK -> V
|
||||
OF -> H
|
||||
FO -> S
|
||||
VC -> P
|
||||
FK -> B
|
||||
NK -> S
|
||||
CB -> B
|
||||
PV -> C
|
||||
CO -> N
|
||||
BN -> C
|
||||
HV -> H
|
||||
OC -> N
|
||||
NB -> O
|
||||
CS -> S
|
||||
HK -> C
|
||||
VS -> F
|
||||
BH -> C
|
||||
PC -> S
|
||||
KC -> O
|
||||
VO -> P
|
||||
FB -> K
|
||||
BV -> V
|
||||
VN -> N
|
||||
ON -> F
|
||||
VH -> H
|
||||
CN -> O
|
||||
HO -> O
|
||||
SV -> O
|
||||
SS -> H
|
||||
KF -> N
|
||||
SP -> C
|
||||
NS -> V
|
||||
SO -> F
|
||||
BC -> P
|
||||
HC -> C
|
||||
FP -> H
|
||||
OH -> S
|
||||
OB -> S
|
||||
HF -> V
|
||||
SC -> B
|
||||
SN -> N
|
||||
VK -> C
|
||||
NC -> V
|
||||
VV -> S
|
||||
SK -> K
|
||||
PK -> K
|
||||
PS -> N
|
||||
KB -> S
|
||||
KS -> C
|
||||
NN -> C
|
||||
OO -> C
|
||||
BS -> B
|
||||
NV -> H
|
||||
FF -> P
|
||||
FC -> N
|
||||
OS -> H
|
||||
KN -> N
|
||||
VP -> B
|
||||
PH -> N
|
||||
NH -> S
|
||||
OV -> O
|
||||
FN -> V
|
||||
CP -> B
|
||||
NO -> V
|
||||
CK -> C
|
||||
VF -> B
|
||||
HS -> B
|
||||
KV -> K
|
||||
VB -> H
|
||||
SB -> S
|
||||
BP -> S
|
||||
CC -> F
|
||||
HP -> B
|
||||
PB -> P
|
||||
HN -> P
|
||||
CH -> O
|
|
@ -0,0 +1,75 @@
|
|||
#!/usr/bin/env python3
|
||||
from collections import Counter
|
||||
|
||||
|
||||
def create_semi_memo(tenth, pair_insertion):
|
||||
for key in pair_insertion.keys():
|
||||
key_l = [ x for x in key ]
|
||||
p_t, elements = do_insert(key_l, pair_insertion, 10)
|
||||
tenth[key] = [p_t[1:-1], elements]
|
||||
|
||||
|
||||
def do_final_insert(polymer_template, tenth, final_elements, iterations):
|
||||
for count in range(1,iterations + 1):
|
||||
length_pt = len(polymer_template)
|
||||
for index in range(1, length_pt + 1):
|
||||
if(index == length_pt):
|
||||
break
|
||||
p_t = f'{polymer_template[-index*2]}{polymer_template[-index*2+1]}'
|
||||
for zindex in range(len(tenth[p_t][0])):
|
||||
polymer_template.insert(-index*2+1+zindex, tenth[p_t][0][zindex])
|
||||
final_elements = Counter(final_elements) + Counter(tenth[p_t][1])
|
||||
|
||||
return final_elements
|
||||
|
||||
|
||||
def do_insert(polymer_template, pair_insertion, iterations):
|
||||
elements = dict()
|
||||
for count in range(1,iterations + 1):
|
||||
length_pt = len(polymer_template)
|
||||
for index in range(1, length_pt + 1):
|
||||
if(index == length_pt):
|
||||
break
|
||||
p_t = f'{polymer_template[-index*2]}{polymer_template[-index*2+1]}'
|
||||
polymer_template.insert(-index*2+1, pair_insertion[p_t])
|
||||
try:
|
||||
elements[pair_insertion[p_t]] += 1
|
||||
except KeyError:
|
||||
elements[pair_insertion[p_t]] = 1
|
||||
print(count)
|
||||
|
||||
return polymer_template, elements
|
||||
|
||||
|
||||
def main():
|
||||
with open('day14', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
polymer_template = lines[0].strip()
|
||||
pair_insertion = dict()
|
||||
final_elements = dict()
|
||||
tenth = dict()
|
||||
|
||||
for line in lines[2:]:
|
||||
line = line.strip().split()
|
||||
pair_insertion[line[0]] = line[2]
|
||||
|
||||
for polymer in polymer_template:
|
||||
try:
|
||||
final_elements[polymer] += 1
|
||||
except KeyError:
|
||||
final_elements[polymer] = 1
|
||||
|
||||
polymer_template = [ x for x in polymer_template ]
|
||||
|
||||
polymer_template, elements = do_insert(polymer_template, pair_insertion, 40)
|
||||
|
||||
maxi = max(list(elements.values()))
|
||||
mixi = min(list(elements.values()))
|
||||
|
||||
|
||||
print(maxi-mixi)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from collections import Counter
|
||||
|
||||
def get_final_element_count(pair_count, pair_insertion, final_element_count, iterations):
|
||||
for _ in range(iterations):
|
||||
temp_pair_count = Counter()
|
||||
for key, value in pair_count.items():
|
||||
if value:
|
||||
temp_pair_count[f"{key[0]}{pair_insertion[key]}"] += value
|
||||
temp_pair_count[f"{pair_insertion[key]}{key[1]}"] += value
|
||||
final_element_count[pair_insertion[key]] += value
|
||||
pair_count = temp_pair_count
|
||||
|
||||
|
||||
def build_dicts(polymer_template):
|
||||
final_element_count = Counter()
|
||||
pair_count = Counter()
|
||||
|
||||
for polymer in polymer_template:
|
||||
final_element_count[polymer] += 1
|
||||
|
||||
for index in range(len(polymer_template) - 1):
|
||||
p_t = f'{polymer_template[index]}{polymer_template[index+1]}'
|
||||
pair_count[p_t] += 1
|
||||
|
||||
return pair_count, final_element_count
|
||||
|
||||
|
||||
def get_pair_insertion(lines):
|
||||
pair_insertion = {}
|
||||
for line in lines[2:]:
|
||||
line = line.strip().split()
|
||||
pair_insertion[line[0]] = line[2]
|
||||
return pair_insertion
|
||||
|
||||
|
||||
def print_difference(final_element_count):
|
||||
maxi = max(list(final_element_count.values()))
|
||||
mini = min(list(final_element_count.values()))
|
||||
print(maxi - mini)
|
||||
|
||||
|
||||
def main():
|
||||
with open('day14', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
polymer_template = list(lines[0].strip())
|
||||
pair_insertion = get_pair_insertion(lines)
|
||||
|
||||
# Part1
|
||||
pair_count, final_element_count = build_dicts(polymer_template)
|
||||
get_final_element_count(pair_count, pair_insertion, final_element_count, 10)
|
||||
print_difference(final_element_count)
|
||||
|
||||
# Part2
|
||||
pair_count, final_element_count = build_dicts(polymer_template)
|
||||
get_final_element_count(pair_count, pair_insertion, final_element_count, 40)
|
||||
print_difference(final_element_count)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def main():
|
||||
with open('day2', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
position = 0
|
||||
depth = 0
|
||||
position_2 = 0
|
||||
depth_2 = 0
|
||||
aim = 0
|
||||
for line in lines:
|
||||
command = line.split()
|
||||
|
||||
match command[0]:
|
||||
case 'forward':
|
||||
position += int(command[1])
|
||||
position_2 += int(command[1])
|
||||
depth_2 += aim * int(command[1])
|
||||
case 'up':
|
||||
depth -= int(command[1])
|
||||
aim -= int(command[1])
|
||||
case 'down':
|
||||
depth += int(command[1])
|
||||
aim += int(command[1])
|
||||
|
||||
print(position * depth)
|
||||
print(position_2 * depth_2)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,6 @@
|
|||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def main():
|
||||
with open('day1', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
list_calories = []
|
||||
current_calories = 0
|
||||
max_calories = 0
|
||||
for line in lines:
|
||||
if line == '\n':
|
||||
list_calories.append(current_calories)
|
||||
if current_calories > max_calories:
|
||||
max_calories = current_calories
|
||||
current_calories = 0
|
||||
continue
|
||||
current_calories += int(line)
|
||||
|
||||
list_calories = sorted(list_calories, reverse=True)
|
||||
top_three = sum(list_calories[:3])
|
||||
print(list_calories[0])
|
||||
print(top_three)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def compute_result_one(opp, my_play):
|
||||
match opp:
|
||||
case 'A':
|
||||
match my_play:
|
||||
case 'X':
|
||||
result = 3
|
||||
case 'Y':
|
||||
result = 6
|
||||
case 'Z':
|
||||
result = 0
|
||||
case 'B':
|
||||
match my_play:
|
||||
case 'X':
|
||||
result = 0
|
||||
case 'Y':
|
||||
result = 3
|
||||
case 'Z':
|
||||
result = 6
|
||||
case 'C':
|
||||
match my_play:
|
||||
case 'X':
|
||||
result = 6
|
||||
case 'Y':
|
||||
result = 0
|
||||
case 'Z':
|
||||
result = 3
|
||||
return result
|
||||
|
||||
|
||||
def compute_result_two(opp, my_play):
|
||||
match opp:
|
||||
case 'A':
|
||||
match my_play:
|
||||
case 'X':
|
||||
result = 3
|
||||
case 'Y':
|
||||
result = 4
|
||||
case 'Z':
|
||||
result = 8
|
||||
case 'B':
|
||||
match my_play:
|
||||
case 'X':
|
||||
result = 1
|
||||
case 'Y':
|
||||
result = 5
|
||||
case 'Z':
|
||||
result = 9
|
||||
case 'C':
|
||||
match my_play:
|
||||
case 'X':
|
||||
result = 2
|
||||
case 'Y':
|
||||
result = 6
|
||||
case 'Z':
|
||||
result = 7
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
me = {
|
||||
'X': 1, # Rock
|
||||
'Y': 2, # Paper
|
||||
'Z': 3 # Scissors
|
||||
}
|
||||
|
||||
score = 0
|
||||
with open('day2', 'r') as file:
|
||||
lines = file.readlines()
|
||||
for line in lines:
|
||||
opp, my_play = line.split()
|
||||
score += me[my_play]
|
||||
result = compute_result_one(opp, my_play)
|
||||
score += result
|
||||
print(score)
|
||||
|
||||
score = 0
|
||||
with open('day2', 'r') as file:
|
||||
lines = file.readlines()
|
||||
for line in lines:
|
||||
opp, my_play = line.split()
|
||||
result = compute_result_two(opp, my_play)
|
||||
score += result
|
||||
print(score)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,300 @@
|
|||
NGvdqJmJvpNbGRMGQgRsfgfn
|
||||
WlHTHShlLwSWjFRsncfbcwsgQc
|
||||
BHtSBHWHSCWLZHlhjTHLLdbNNqNpzpDzNvDvtPmmPp
|
||||
JJSShnTpDSJJlllfwBNVbMQWwhQhgQtt
|
||||
cTzrvrHdLwwzttQNWB
|
||||
qrFqTFvqZvrmsplsjlnDflnZ
|
||||
mhhhVHvNNddHMwBqQwlWZZtv
|
||||
fbjzjJllCtWjjrZtjq
|
||||
CbgcgpPRDJfzVHFFnSnsSDlm
|
||||
ZqBPqBQnPLmqZsFqhsvFsLZQMfSSMbbWddWbjbJSrgWgJf
|
||||
NRHnlllcDwwCNClNtttHbNJrSJNfbdWMdfbWgdrJ
|
||||
cHGlzTptHtCpncHnCpHpRGzDmvVhqLmvLPmPvLqPmzsqqmPB
|
||||
rCzVtMMbMvCmmvGlclFQFfLpJFJfJpcLHPJL
|
||||
nDGGwqGqnRTfpHLpRFpLFf
|
||||
ZNdNTDsWgNZsZBndnGrzrlMrjgrmjVGjvC
|
||||
MgFZHFTgqFFDZZDTdVdHrzQvLzCGwpCPrGLqQpzz
|
||||
JsnmbjhmffJbRNJppzPPzwzzrwdv
|
||||
lfblfthBRbBRjnjhBtBlZgdVcFSTVFDtSSWgMcdM
|
||||
hPVhVhWPCMhlDTTWdrPlTcLjfbZbFNjZBbFNBbdBFbsB
|
||||
MHSwMJpHnqJHwtqHGqGGmvqZsZFjBmsBNRBFfLbsFsZfsZ
|
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fPSSHSPfPtDHfbD
|
||||
zNWNZGWNzQnWlJWVJn
|
||||
tMGSBtRtvjFcGpQrQQQQrp
|
||||
FffbJTJfPLNbTnJJmlVcQVfpQmlWVVfH
|
||||
FTdJJdhNvZhMtRSh
|
||||
pSTfMtMLSTPsPsBszP
|
||||
jdlmlFHHhVdmVHFNFRnHzHQJsGZBJbbJDvsDRPBsrGrDrJ
|
||||
VHnFjcdccjlmNVmnzmNVmCMggfqwtLLfSMwWtcWMSg
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env python3
|
||||
from string import ascii_letters
|
||||
|
||||
priority = {letter:index+1 for index,letter in enumerate(ascii_letters)}
|
||||
|
||||
def main():
|
||||
with open('day3', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
priorities = 0
|
||||
for line in lines:
|
||||
length_compartments = int(len(line) / 2)
|
||||
first = line[:length_compartments]
|
||||
second = line[length_compartments:]
|
||||
|
||||
|
||||
for item in first:
|
||||
if item in second:
|
||||
priorities += priority[item]
|
||||
break
|
||||
print(priorities)
|
||||
|
||||
priorities = 0
|
||||
for index, line in enumerate(lines):
|
||||
mod_index = (index + 1) % 3
|
||||
match mod_index:
|
||||
case 1:
|
||||
first = line
|
||||
case 2:
|
||||
second = line
|
||||
case 0:
|
||||
third = line
|
||||
|
||||
for item in first:
|
||||
if (item in second) and (item in third):
|
||||
priorities += priority[item]
|
||||
break
|
||||
print(priorities)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env python3
|
||||
def part_one(lines):
|
||||
pairs = 0
|
||||
for line in lines:
|
||||
first, second = line.split(',')
|
||||
one, two = first.split('-')
|
||||
three, four = second.split('-')
|
||||
one = int(one)
|
||||
two = int(two)
|
||||
three = int(three)
|
||||
four = int(four)
|
||||
|
||||
first_section_ids = []
|
||||
for index in range(one, two+1):
|
||||
index_space = str(index) + ' '
|
||||
first_section_ids.append(index_space)
|
||||
|
||||
first_ids = ''.join(first_section_ids)
|
||||
|
||||
second_section_ids = []
|
||||
for index in range(three, four+1):
|
||||
index_space = str(index) + ' '
|
||||
second_section_ids.append(index_space)
|
||||
|
||||
second_ids = ''.join(second_section_ids)
|
||||
|
||||
if len(first_ids) == 2 and not (one in range(three, four)):
|
||||
continue
|
||||
if len(second_ids) == 2 and not (three in range(one, two)):
|
||||
continue
|
||||
|
||||
if (first_ids in second_ids) or (second_ids in first_ids):
|
||||
pairs += 1
|
||||
|
||||
print(pairs)
|
||||
|
||||
|
||||
def part_two(lines):
|
||||
pairs = 0
|
||||
for line in lines:
|
||||
first, second = line.split(',')
|
||||
one, two = first.split('-')
|
||||
three, four = second.split('-')
|
||||
one = int(one)
|
||||
two = int(two)
|
||||
three = int(three)
|
||||
four = int(four)
|
||||
|
||||
first_section_ids = []
|
||||
for index in range(one, two+1):
|
||||
index_space = str(index) + ' '
|
||||
first_section_ids.append(index_space)
|
||||
|
||||
second_section_ids = []
|
||||
for index in range(three, four+1):
|
||||
index_space = str(index) + ' '
|
||||
second_section_ids.append(index_space)
|
||||
|
||||
for ids in first_section_ids:
|
||||
if ids in second_section_ids:
|
||||
pairs += 1
|
||||
break
|
||||
|
||||
print(pairs)
|
||||
|
||||
|
||||
def main():
|
||||
with open('day4', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
part_one(lines)
|
||||
part_two(lines)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,512 @@
|
|||
[J] [Z] [G]
|
||||
[Z] [T] [S] [P] [R]
|
||||
[R] [Q] [V] [B] [G] [J]
|
||||
[W] [W] [N] [L] [V] [W] [C]
|
||||
[F] [Q] [T] [G] [C] [T] [T] [W]
|
||||
[H] [D] [W] [W] [H] [T] [R] [M] [B]
|
||||
[T] [G] [T] [R] [B] [P] [B] [G] [G]
|
||||
[S] [S] [B] [D] [F] [L] [Z] [N] [L]
|
||||
1 2 3 4 5 6 7 8 9
|
||||
|
||||
move 4 from 2 to 1
|
||||
move 1 from 6 to 9
|
||||
move 6 from 4 to 7
|
||||
move 1 from 2 to 5
|
||||
move 3 from 6 to 3
|
||||
move 4 from 3 to 9
|
||||
move 2 from 1 to 3
|
||||
move 6 from 7 to 5
|
||||
move 5 from 7 to 6
|
||||
move 6 from 8 to 7
|
||||
move 6 from 7 to 6
|
||||
move 1 from 8 to 3
|
||||
move 15 from 6 to 4
|
||||
move 7 from 5 to 6
|
||||
move 1 from 7 to 2
|
||||
move 2 from 5 to 3
|
||||
move 5 from 9 to 8
|
||||
move 5 from 5 to 6
|
||||
move 1 from 7 to 4
|
||||
move 5 from 6 to 5
|
||||
move 3 from 3 to 8
|
||||
move 4 from 5 to 8
|
||||
move 1 from 2 to 8
|
||||
move 7 from 1 to 2
|
||||
move 2 from 6 to 2
|
||||
move 2 from 5 to 8
|
||||
move 1 from 1 to 8
|
||||
move 8 from 2 to 6
|
||||
move 3 from 3 to 4
|
||||
move 4 from 9 to 3
|
||||
move 5 from 3 to 6
|
||||
move 5 from 6 to 8
|
||||
move 3 from 4 to 8
|
||||
move 13 from 6 to 5
|
||||
move 14 from 4 to 8
|
||||
move 1 from 2 to 6
|
||||
move 1 from 4 to 2
|
||||
move 12 from 5 to 4
|
||||
move 30 from 8 to 6
|
||||
move 1 from 8 to 9
|
||||
move 1 from 9 to 4
|
||||
move 15 from 4 to 5
|
||||
move 1 from 2 to 9
|
||||
move 1 from 4 to 2
|
||||
move 1 from 2 to 1
|
||||
move 1 from 9 to 3
|
||||
move 8 from 5 to 7
|
||||
move 2 from 5 to 6
|
||||
move 7 from 8 to 1
|
||||
move 1 from 3 to 4
|
||||
move 1 from 7 to 3
|
||||
move 1 from 4 to 6
|
||||
move 26 from 6 to 7
|
||||
move 1 from 3 to 7
|
||||
move 3 from 7 to 2
|
||||
move 1 from 1 to 9
|
||||
move 16 from 7 to 5
|
||||
move 2 from 7 to 4
|
||||
move 12 from 7 to 6
|
||||
move 1 from 1 to 9
|
||||
move 4 from 6 to 1
|
||||
move 7 from 1 to 5
|
||||
move 2 from 1 to 8
|
||||
move 1 from 7 to 2
|
||||
move 1 from 1 to 4
|
||||
move 2 from 4 to 5
|
||||
move 1 from 9 to 4
|
||||
move 3 from 6 to 9
|
||||
move 8 from 6 to 5
|
||||
move 5 from 5 to 9
|
||||
move 19 from 5 to 8
|
||||
move 1 from 9 to 8
|
||||
move 3 from 8 to 7
|
||||
move 1 from 7 to 3
|
||||
move 8 from 5 to 2
|
||||
move 2 from 4 to 2
|
||||
move 4 from 9 to 8
|
||||
move 1 from 2 to 3
|
||||
move 2 from 3 to 2
|
||||
move 4 from 9 to 5
|
||||
move 8 from 8 to 4
|
||||
move 9 from 8 to 5
|
||||
move 5 from 8 to 4
|
||||
move 5 from 5 to 7
|
||||
move 12 from 2 to 3
|
||||
move 2 from 2 to 8
|
||||
move 1 from 8 to 6
|
||||
move 1 from 8 to 7
|
||||
move 10 from 4 to 3
|
||||
move 1 from 2 to 9
|
||||
move 13 from 5 to 3
|
||||
move 1 from 7 to 5
|
||||
move 27 from 3 to 4
|
||||
move 1 from 8 to 7
|
||||
move 3 from 5 to 2
|
||||
move 6 from 6 to 3
|
||||
move 2 from 4 to 1
|
||||
move 27 from 4 to 2
|
||||
move 2 from 7 to 8
|
||||
move 23 from 2 to 4
|
||||
move 2 from 1 to 4
|
||||
move 2 from 7 to 2
|
||||
move 4 from 2 to 9
|
||||
move 10 from 3 to 4
|
||||
move 1 from 3 to 5
|
||||
move 1 from 5 to 1
|
||||
move 5 from 2 to 5
|
||||
move 30 from 4 to 2
|
||||
move 1 from 8 to 9
|
||||
move 1 from 8 to 1
|
||||
move 27 from 2 to 3
|
||||
move 2 from 4 to 2
|
||||
move 1 from 9 to 4
|
||||
move 2 from 1 to 3
|
||||
move 8 from 3 to 7
|
||||
move 19 from 3 to 1
|
||||
move 1 from 4 to 7
|
||||
move 5 from 9 to 1
|
||||
move 4 from 2 to 9
|
||||
move 4 from 3 to 4
|
||||
move 1 from 3 to 5
|
||||
move 1 from 2 to 7
|
||||
move 1 from 9 to 3
|
||||
move 1 from 9 to 1
|
||||
move 5 from 5 to 4
|
||||
move 5 from 7 to 3
|
||||
move 1 from 5 to 6
|
||||
move 23 from 1 to 6
|
||||
move 1 from 9 to 2
|
||||
move 1 from 2 to 5
|
||||
move 24 from 6 to 9
|
||||
move 6 from 4 to 7
|
||||
move 4 from 4 to 8
|
||||
move 1 from 4 to 9
|
||||
move 4 from 7 to 4
|
||||
move 4 from 3 to 4
|
||||
move 4 from 9 to 8
|
||||
move 6 from 7 to 9
|
||||
move 4 from 7 to 6
|
||||
move 1 from 1 to 4
|
||||
move 2 from 6 to 4
|
||||
move 1 from 6 to 2
|
||||
move 1 from 1 to 8
|
||||
move 1 from 7 to 3
|
||||
move 1 from 6 to 9
|
||||
move 13 from 4 to 2
|
||||
move 3 from 3 to 2
|
||||
move 15 from 9 to 8
|
||||
move 1 from 5 to 9
|
||||
move 5 from 9 to 1
|
||||
move 4 from 1 to 7
|
||||
move 4 from 7 to 3
|
||||
move 8 from 2 to 7
|
||||
move 9 from 8 to 2
|
||||
move 1 from 1 to 2
|
||||
move 7 from 9 to 2
|
||||
move 4 from 3 to 1
|
||||
move 4 from 1 to 4
|
||||
move 2 from 9 to 1
|
||||
move 20 from 2 to 8
|
||||
move 3 from 4 to 8
|
||||
move 1 from 2 to 3
|
||||
move 4 from 2 to 7
|
||||
move 1 from 3 to 4
|
||||
move 1 from 9 to 3
|
||||
move 1 from 4 to 7
|
||||
move 1 from 2 to 5
|
||||
move 1 from 4 to 3
|
||||
move 2 from 1 to 6
|
||||
move 1 from 5 to 6
|
||||
move 1 from 7 to 1
|
||||
move 12 from 7 to 2
|
||||
move 12 from 2 to 6
|
||||
move 9 from 6 to 2
|
||||
move 1 from 6 to 8
|
||||
move 1 from 3 to 9
|
||||
move 8 from 2 to 4
|
||||
move 1 from 9 to 6
|
||||
move 1 from 4 to 6
|
||||
move 4 from 4 to 9
|
||||
move 1 from 4 to 9
|
||||
move 1 from 1 to 5
|
||||
move 2 from 6 to 3
|
||||
move 1 from 5 to 4
|
||||
move 1 from 2 to 8
|
||||
move 10 from 8 to 6
|
||||
move 10 from 8 to 3
|
||||
move 1 from 3 to 4
|
||||
move 8 from 8 to 1
|
||||
move 3 from 9 to 8
|
||||
move 2 from 9 to 1
|
||||
move 11 from 6 to 7
|
||||
move 1 from 1 to 7
|
||||
move 8 from 1 to 4
|
||||
move 3 from 6 to 7
|
||||
move 1 from 1 to 4
|
||||
move 14 from 8 to 6
|
||||
move 1 from 8 to 7
|
||||
move 1 from 6 to 8
|
||||
move 6 from 4 to 1
|
||||
move 1 from 8 to 5
|
||||
move 4 from 1 to 8
|
||||
move 2 from 7 to 1
|
||||
move 1 from 6 to 7
|
||||
move 5 from 4 to 2
|
||||
move 2 from 4 to 3
|
||||
move 4 from 2 to 8
|
||||
move 15 from 7 to 3
|
||||
move 3 from 3 to 6
|
||||
move 1 from 5 to 2
|
||||
move 21 from 3 to 6
|
||||
move 2 from 8 to 7
|
||||
move 1 from 7 to 8
|
||||
move 32 from 6 to 9
|
||||
move 1 from 7 to 8
|
||||
move 5 from 8 to 4
|
||||
move 2 from 8 to 7
|
||||
move 14 from 9 to 8
|
||||
move 14 from 8 to 1
|
||||
move 2 from 6 to 1
|
||||
move 2 from 7 to 4
|
||||
move 1 from 9 to 3
|
||||
move 17 from 9 to 5
|
||||
move 6 from 1 to 8
|
||||
move 4 from 4 to 6
|
||||
move 2 from 2 to 5
|
||||
move 2 from 8 to 2
|
||||
move 1 from 6 to 7
|
||||
move 2 from 2 to 6
|
||||
move 4 from 3 to 2
|
||||
move 7 from 6 to 3
|
||||
move 6 from 5 to 7
|
||||
move 1 from 8 to 9
|
||||
move 1 from 6 to 7
|
||||
move 4 from 8 to 6
|
||||
move 1 from 9 to 3
|
||||
move 4 from 1 to 4
|
||||
move 12 from 5 to 9
|
||||
move 7 from 7 to 8
|
||||
move 3 from 4 to 2
|
||||
move 8 from 9 to 4
|
||||
move 2 from 6 to 2
|
||||
move 1 from 7 to 4
|
||||
move 2 from 6 to 9
|
||||
move 1 from 5 to 3
|
||||
move 1 from 8 to 1
|
||||
move 2 from 8 to 7
|
||||
move 2 from 2 to 9
|
||||
move 7 from 2 to 3
|
||||
move 8 from 4 to 1
|
||||
move 2 from 8 to 4
|
||||
move 4 from 9 to 7
|
||||
move 2 from 9 to 5
|
||||
move 16 from 1 to 3
|
||||
move 3 from 7 to 4
|
||||
move 1 from 7 to 6
|
||||
move 1 from 6 to 2
|
||||
move 2 from 5 to 3
|
||||
move 10 from 4 to 2
|
||||
move 2 from 8 to 7
|
||||
move 19 from 3 to 8
|
||||
move 17 from 3 to 9
|
||||
move 3 from 1 to 7
|
||||
move 17 from 9 to 2
|
||||
move 1 from 7 to 5
|
||||
move 1 from 7 to 5
|
||||
move 2 from 5 to 7
|
||||
move 2 from 9 to 2
|
||||
move 6 from 7 to 6
|
||||
move 3 from 6 to 7
|
||||
move 1 from 8 to 9
|
||||
move 1 from 9 to 3
|
||||
move 4 from 2 to 5
|
||||
move 17 from 2 to 3
|
||||
move 3 from 7 to 5
|
||||
move 1 from 5 to 3
|
||||
move 7 from 2 to 3
|
||||
move 2 from 2 to 4
|
||||
move 1 from 7 to 1
|
||||
move 1 from 1 to 5
|
||||
move 2 from 5 to 3
|
||||
move 1 from 4 to 5
|
||||
move 1 from 4 to 3
|
||||
move 14 from 3 to 5
|
||||
move 17 from 8 to 7
|
||||
move 2 from 6 to 2
|
||||
move 12 from 3 to 5
|
||||
move 15 from 5 to 9
|
||||
move 7 from 7 to 3
|
||||
move 7 from 7 to 6
|
||||
move 1 from 2 to 3
|
||||
move 11 from 9 to 6
|
||||
move 13 from 5 to 7
|
||||
move 10 from 6 to 8
|
||||
move 6 from 8 to 3
|
||||
move 2 from 5 to 8
|
||||
move 1 from 2 to 9
|
||||
move 10 from 7 to 6
|
||||
move 9 from 6 to 8
|
||||
move 1 from 5 to 1
|
||||
move 10 from 6 to 4
|
||||
move 8 from 4 to 5
|
||||
move 1 from 1 to 2
|
||||
move 3 from 9 to 1
|
||||
move 10 from 3 to 7
|
||||
move 1 from 4 to 7
|
||||
move 12 from 7 to 9
|
||||
move 7 from 3 to 5
|
||||
move 13 from 8 to 7
|
||||
move 3 from 9 to 5
|
||||
move 5 from 5 to 6
|
||||
move 3 from 1 to 9
|
||||
move 5 from 9 to 6
|
||||
move 10 from 6 to 4
|
||||
move 15 from 7 to 5
|
||||
move 3 from 9 to 4
|
||||
move 1 from 4 to 3
|
||||
move 3 from 8 to 9
|
||||
move 6 from 9 to 6
|
||||
move 2 from 5 to 1
|
||||
move 1 from 2 to 7
|
||||
move 12 from 5 to 8
|
||||
move 3 from 9 to 5
|
||||
move 11 from 5 to 6
|
||||
move 1 from 1 to 2
|
||||
move 1 from 2 to 8
|
||||
move 3 from 7 to 8
|
||||
move 10 from 8 to 3
|
||||
move 1 from 1 to 7
|
||||
move 10 from 4 to 9
|
||||
move 1 from 7 to 8
|
||||
move 5 from 5 to 3
|
||||
move 15 from 6 to 5
|
||||
move 8 from 3 to 9
|
||||
move 3 from 4 to 5
|
||||
move 1 from 7 to 8
|
||||
move 8 from 8 to 9
|
||||
move 1 from 6 to 5
|
||||
move 5 from 3 to 2
|
||||
move 5 from 2 to 3
|
||||
move 5 from 9 to 8
|
||||
move 1 from 6 to 8
|
||||
move 2 from 5 to 1
|
||||
move 4 from 3 to 2
|
||||
move 16 from 5 to 6
|
||||
move 3 from 5 to 9
|
||||
move 4 from 8 to 5
|
||||
move 8 from 6 to 4
|
||||
move 4 from 2 to 3
|
||||
move 1 from 1 to 4
|
||||
move 6 from 3 to 6
|
||||
move 24 from 9 to 2
|
||||
move 1 from 1 to 9
|
||||
move 1 from 9 to 4
|
||||
move 2 from 4 to 5
|
||||
move 1 from 3 to 2
|
||||
move 10 from 6 to 8
|
||||
move 22 from 2 to 6
|
||||
move 1 from 2 to 7
|
||||
move 1 from 7 to 5
|
||||
move 10 from 8 to 9
|
||||
move 7 from 9 to 3
|
||||
move 6 from 4 to 8
|
||||
move 3 from 9 to 2
|
||||
move 5 from 8 to 3
|
||||
move 1 from 4 to 1
|
||||
move 1 from 8 to 3
|
||||
move 3 from 6 to 2
|
||||
move 5 from 5 to 1
|
||||
move 1 from 5 to 3
|
||||
move 5 from 6 to 3
|
||||
move 1 from 2 to 7
|
||||
move 16 from 3 to 2
|
||||
move 1 from 8 to 1
|
||||
move 1 from 4 to 7
|
||||
move 1 from 5 to 3
|
||||
move 6 from 6 to 4
|
||||
move 14 from 2 to 8
|
||||
move 3 from 3 to 5
|
||||
move 2 from 3 to 6
|
||||
move 3 from 5 to 6
|
||||
move 4 from 6 to 4
|
||||
move 3 from 4 to 8
|
||||
move 7 from 2 to 9
|
||||
move 2 from 2 to 1
|
||||
move 9 from 8 to 4
|
||||
move 7 from 1 to 7
|
||||
move 8 from 7 to 5
|
||||
move 2 from 8 to 4
|
||||
move 3 from 9 to 6
|
||||
move 4 from 4 to 6
|
||||
move 1 from 7 to 3
|
||||
move 4 from 8 to 2
|
||||
move 2 from 9 to 8
|
||||
move 9 from 6 to 7
|
||||
move 1 from 9 to 8
|
||||
move 1 from 1 to 5
|
||||
move 3 from 4 to 5
|
||||
move 1 from 3 to 2
|
||||
move 5 from 8 to 2
|
||||
move 9 from 2 to 7
|
||||
move 1 from 6 to 7
|
||||
move 1 from 6 to 2
|
||||
move 9 from 7 to 4
|
||||
move 2 from 5 to 9
|
||||
move 10 from 4 to 6
|
||||
move 1 from 8 to 6
|
||||
move 5 from 4 to 3
|
||||
move 5 from 4 to 9
|
||||
move 5 from 9 to 5
|
||||
move 1 from 1 to 7
|
||||
move 4 from 7 to 8
|
||||
move 8 from 5 to 3
|
||||
move 3 from 3 to 8
|
||||
move 6 from 7 to 6
|
||||
move 3 from 3 to 1
|
||||
move 5 from 3 to 7
|
||||
move 1 from 9 to 6
|
||||
move 2 from 7 to 6
|
||||
move 1 from 9 to 3
|
||||
move 4 from 6 to 9
|
||||
move 2 from 2 to 6
|
||||
move 1 from 7 to 3
|
||||
move 6 from 5 to 4
|
||||
move 7 from 6 to 9
|
||||
move 6 from 6 to 8
|
||||
move 2 from 1 to 2
|
||||
move 1 from 5 to 1
|
||||
move 5 from 8 to 5
|
||||
move 1 from 3 to 9
|
||||
move 4 from 4 to 5
|
||||
move 10 from 9 to 2
|
||||
move 14 from 6 to 4
|
||||
move 1 from 3 to 8
|
||||
move 1 from 8 to 5
|
||||
move 2 from 7 to 9
|
||||
move 1 from 1 to 2
|
||||
move 14 from 4 to 7
|
||||
move 1 from 1 to 4
|
||||
move 3 from 4 to 1
|
||||
move 3 from 5 to 1
|
||||
move 6 from 5 to 1
|
||||
move 10 from 7 to 3
|
||||
move 6 from 1 to 5
|
||||
move 6 from 1 to 7
|
||||
move 3 from 8 to 3
|
||||
move 1 from 5 to 1
|
||||
move 3 from 9 to 6
|
||||
move 1 from 9 to 3
|
||||
move 6 from 5 to 9
|
||||
move 2 from 6 to 1
|
||||
move 9 from 2 to 1
|
||||
move 6 from 9 to 6
|
||||
move 2 from 8 to 7
|
||||
move 5 from 7 to 3
|
||||
move 7 from 7 to 5
|
||||
move 4 from 2 to 8
|
||||
move 6 from 8 to 3
|
||||
move 1 from 9 to 4
|
||||
move 1 from 7 to 3
|
||||
move 2 from 5 to 3
|
||||
move 7 from 6 to 4
|
||||
move 28 from 3 to 4
|
||||
move 1 from 3 to 8
|
||||
move 1 from 5 to 9
|
||||
move 9 from 4 to 5
|
||||
move 12 from 4 to 5
|
||||
move 2 from 4 to 6
|
||||
move 5 from 4 to 6
|
||||
move 1 from 3 to 8
|
||||
move 10 from 5 to 8
|
||||
move 10 from 5 to 4
|
||||
move 5 from 5 to 9
|
||||
move 3 from 4 to 1
|
||||
move 5 from 6 to 9
|
||||
move 2 from 6 to 7
|
||||
move 2 from 7 to 5
|
||||
move 10 from 9 to 4
|
||||
move 1 from 8 to 5
|
||||
move 5 from 1 to 5
|
||||
move 8 from 8 to 7
|
||||
move 8 from 5 to 3
|
||||
move 8 from 7 to 8
|
||||
move 2 from 8 to 2
|
||||
move 7 from 3 to 2
|
||||
move 21 from 4 to 7
|
||||
move 10 from 1 to 9
|
||||
move 3 from 4 to 5
|
||||
move 1 from 4 to 8
|
||||
move 1 from 8 to 3
|
||||
move 7 from 8 to 5
|
||||
move 2 from 3 to 1
|
||||
move 7 from 7 to 2
|
||||
move 1 from 1 to 4
|
||||
move 1 from 1 to 6
|
||||
move 8 from 9 to 3
|
||||
move 2 from 8 to 4
|
||||
move 3 from 3 to 1
|
||||
move 3 from 4 to 7
|
||||
move 1 from 6 to 7
|
||||
move 5 from 2 to 4
|
||||
move 2 from 1 to 6
|
|
@ -0,0 +1,88 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def parse_stacks(stacks, line):
|
||||
for box in range(9):
|
||||
contents = line[box*4+1]
|
||||
if contents != ' ':
|
||||
match box:
|
||||
case 0:
|
||||
stacks[0].append(contents)
|
||||
case 1:
|
||||
stacks[1].append(contents)
|
||||
case 2:
|
||||
stacks[2].append(contents)
|
||||
case 3:
|
||||
stacks[3].append(contents)
|
||||
case 4:
|
||||
stacks[4].append(contents)
|
||||
case 5:
|
||||
stacks[5].append(contents)
|
||||
case 6:
|
||||
stacks[6].append(contents)
|
||||
case 7:
|
||||
stacks[7].append(contents)
|
||||
case 8:
|
||||
stacks[8].append(contents)
|
||||
|
||||
|
||||
def parse_line(line):
|
||||
line = line.strip().split()
|
||||
count = int(line[1])
|
||||
from_stack = int(line[3]) - 1
|
||||
to_stack = int(line[5]) - 1
|
||||
return count, from_stack, to_stack
|
||||
|
||||
|
||||
def move_single(stacks, line):
|
||||
count, from_stack, to_stack = parse_line(line)
|
||||
|
||||
for _ in range(count):
|
||||
stacks[to_stack].append(stacks[from_stack].pop())
|
||||
|
||||
|
||||
def move_multiple(stacks, line):
|
||||
count, from_stack, to_stack = parse_line(line)
|
||||
count = int(count)
|
||||
|
||||
temp_stack = stacks[from_stack][-count:]
|
||||
for _ in range(count):
|
||||
stacks[from_stack].pop()
|
||||
stacks[to_stack].extend(temp_stack)
|
||||
|
||||
|
||||
def create_and_parse_stacks():
|
||||
stacks = [[] for _ in range(9)]
|
||||
|
||||
with open('day5', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
for line in lines[7::-1]:
|
||||
parse_stacks(stacks, line[:-1])
|
||||
|
||||
return stacks, lines[10:]
|
||||
|
||||
|
||||
def print_stacks(stacks):
|
||||
for stack in stacks:
|
||||
print(stack[-1], end='')
|
||||
print()
|
||||
|
||||
|
||||
def main():
|
||||
stacks, lines = create_and_parse_stacks()
|
||||
|
||||
for line in lines:
|
||||
move_single(stacks, line)
|
||||
|
||||
print_stacks(stacks)
|
||||
|
||||
stacks, lines = create_and_parse_stacks()
|
||||
|
||||
for line in lines:
|
||||
move_multiple(stacks, line)
|
||||
|
||||
print_stacks(stacks)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1 @@
|
|||
rvnvzvhzzjgjgffclllnhhtltptgptgpttjhttsllmbbphbpbzpbpjjcwjwqwccnrrtvrtrfrwffnqffsggwzzhtzhthqhffmrrzsrrnrtrqqbllhrlrjrvvrvvgdgjgfjjtzznffrfvfggswgssccpcwpccstcsstwssgzssswsgwsgsnsshcsscsffcwcmmhmsmrsrddwhhszsfsjfsfccwssvdssmzzwrzzjfzzvzzfsfsvshschhvlhhvmvpvhhstsdtstgtrrtjjcssgfssnsnfsnscnsslvvqbbhthqtqzqmzmjjfmmbdmmzdmdpmpnnfjnnrwnwbwrrwjrrttfzzlwwfmmnhhqlhqqbnqnqznncmmhfmfftsfszssftstggppfddtztltctqcqjcqcmclcnccdgcggvmvvcsstztbzttsccmgcghcczfzszbzmbmjjggsqgghbhjjhhrrjljmllczlzzqssjfjqfjfmfdfgffczfzwwpfwpwbbftbffplphhfcftctlcclhlnlhnhlhnhqnhhjbjmmtpmmlsmllvhhjghhmzzwpzprrjrzzvrvcvqvssgssnccmgmppfhfwhhczhhprhrffpvvqrqvqccdhdvvvssvdvwdwwzggfvfnvvqvwwzwmzzvttgzzwjjfvvpvffqpqhqrrwccjbjppbzbrbrrphrhgrhhzbbhrrblbjjznnlccsffpcfpcfpfddfwddbffczztzsttzsstddrqdqqchqccrlccfcwwghwhnhbhjbhhzrrgprrftrffqlljlslggzdzvvrgvgcgnnngtnggdcgddhjhchqcqfqwfwjffqppblbddgmdgmddrnddjtdjttgzgpzggwvwjvwwhdwwbvvtftcfttpftpfpzfznnchnhrrdtdbtdbdppsjsgsttptsptssnwntwnnsshqqgnnqnddhjjtqqjhhmghmhmsstrrhmmwvvlssprsrbbswsddbnntmtbmtbmmtmrrffvjffdrffnttbffbccgchghjgjwwshwswdswdsdsrdsdjdvjjgbjbssptpddzbdddqdpdspswssjrjwwcbbvsspnspslpplzlqlccvlvfllntlntnqnrqnqpqlqflfrfsfgsfswwptwwgqggrhghzghhrthtzhzsswhhzffpsffhnnrvnrvvhmmlvvqsslddhcddsllpmpggrhrcrbbmnmjmqmlmpmrrqwqhqrqhrrgrqqsrrpjpdjppzhphthddlzdzhddjvdjdcjcncnvnzzvwzvzgzjggcllvpllgdgqqdvvwnvwvwqqvwvvrbbtqqwhdztqfzzcqrshjzwqnpdsshmpjzwqdptbvfqzmfnbtlgbbsjbqgnblhbbpsfdzvcmpzfwczcnbdndsjzccjcqnrdglwfrvwtnjwpvpvvgwtmnpzhbwnbqwznmdvdrsjnlsfrpcnhlbmlgmrcjbbvhqnvbrmlnfttjllstqnqqnhqrzrhfqjbfbwfhhjzwtwzjmszzhjnjbhrlbnnpfvdmlftjnfsfnvddqfhqqlljrthptvmhbqrdmdcmljwgbrqrjwcrtmvjgqtblnslgbjmdsrrpgfsctrhwlwnszpljhrfnsfpcsgczzltgsztclhgcqljrcmbbpdlztncnrnrmgrttplcnldfqddqhznmcczbmwvsztmwmcqnrzmlmqchnhnhrrhhfntjzqcbnttspptqwvphlbtpfcbhdqzbhsbvhmsqbsdntwpcrnzvmbgqsgttbqhhblfjpmvfcrzhfnzwrzbzgsdfqndzzhfdnrvsnvfbptthjnhgljhrvwwrlbnfpvvjdjchcgbhfrqvszhrhqvtzplwsptvdhqwlzhcjpclmmrlccvgvtgsfpnjhqhrbqglznpdhmsqwwsbmhmlsmmvvghsmplqjchrfctltmnqnddzqjfpljwljbdqjcqdqzwsbcclqsmsmlstvljwwtfmpnhqzqfjghjfchjccqrchsvngvrnwfwttsnvrdlfvwfptsjcpslvvpmjclfcpljqjszptsgsmntzrdjbgrzmgvzddqrlsndjzzqbznqnphbnwfhtjjlwjpsvffrdrbsbttpgrvmqrdndqvlgzcpfbttvqdgvrmtvfclcbcwllthmdzjcflwpnrsqzrjdzbvqgzsqvjjpjjpnjtcjqhcfbjdqndlcwzhcbjtgtlvtdwctdnqcbcgsmrcrmwjntdwbjdbzmshbvlspjfdbvmlrbdzlmlggthvphnrqlrcdsqpsgqcmpgmgdzvdqlmcldvztpsbmpwjgjfhswplwrvwpbwbsgsvlhdvmpzwnnbwjwmshwcnqfqjdpchfjjcbdnslqchhnznpqpnnctznbtccclgjhmnngdjlmqnzpsdptqqcrblmrlnnpgvrfrtmbjnmspfrbwpclhgtbsghndrjfbggsplvcjnhjjbqzsfdpfnvchzjgbhdqgddfgddvzdcrjlntnsmscqwmpptqgbnvtsvpjvmhcfpbfrpzqbpfhlbjrmbmvdvvnvfqsndglvhfrqcsbsbbprscrbfthzcwcdrprqrwjzwrpblfllpwzlhmqvltjgpcjzpzwbltgwsrgrrhzcqfpvhcprdhnzcfphqrwcvtpcbppjwzmmwjhbvwbblnbwvcqzvlfzjhgmlnhlhrbsplfctggfbhbgwpncznvtmdtqqmjsvsnrlqswzvflrfsncgpdcndlwrfrqwqnqtjmsphwsgzhdjpnsdgrbrfhbfdrntwvgvbwnvwnrmdbhqgrglbfwprflnrljrwsgwtpgtmfhvvghtzndvwlzjchhmlwcncmpvrslrglzjcnhfdqhcrljhgbzpssvdnmfwzstmvrztgpsscfswltnbwrrtcnvbswmmjbmnnnvqwjzhprfnvlbvzzdvbwlwchrvqnwwpbnttbhfdvjjvzsznhczjcncmcrmwtrlsvbwpsrcwqdvgcfjsbqnwmjmtcgpnmcbfbcqhzrjbtlpvwzhjqqprbdnbgzfwlprlcspwjwnfftldqzbcgqnjtglvbpqffdvjbpslqcdzwdnmncvcwfshdhsmssttqfrsbnjgmhfqzlgrbpdfqtfdwslsgphfzzgbzjssfbgnwztzmczplqwjmhtlflpvqqqmrvlllhngtfgsvbbnvhzqbcgpmnlsmpwqwgqfjpzplzjhrslwzrsrgjgpppjlnhrnggcdzvspsztnschnqftgffbtvrpzndzpqmtsfmwgnrvpmtgpvnmqfmwgcvlznwqnjnjwpgnqfjwtdhhmztlvlcvrlzmlpmjdvdnzwbfsshfsvbbhqsmphjhqtlnvlsmvwlqvfqpnjnzlgmdvwzzrllmcgwtqdwphhbwmlrqhqrfmdvtqswvsllqvwmfbbpllsbjbvgsmrcgqvfgsnszfrdlcjbtfgcbclhmzlmqlnhmslcmgrcvjjlbpsjjcznzqwmztcgdgbmrlgwzjzzjrpndfrdzztzzgmsrcnwrvqrdcczrbhdpfjwvqsmbrcvllvjrrbrsqnzldltdgzscjrssvdhzhnvltpgfdfcvfbtqmphdzhpzgjhjbwsmdlbqqgcrhjrwhgvfgdllmmlnpsbtvdrrzmltfwgrcsfrrsdbdmjtrwhnlgcrgjgmbzvzvqbflvbrsqcssjgsvpjmlhtcggzwbvddmwwtfdrlltjqcpwnthczzlzdszvtmrmhbpcgstvrsnmbdcmjzsvnncmgmlnrzzhfvmblgptwwwbrmtcczjwcqmvdrsvfjgqqvghnhbntqcdrppfmvdzbcjvztrnpdhmdpmnvsnzzldvdfqbdrwqqqqsmswthwpjwdrflszbspqhpfwztjjcbdsrftdsrsfdltnfztcslmbsghgrtcscrfmptqplwpmtqdzthgfjhbqdnsffrpjmgczmrlfvzcjttwtmtqfbtlqrttvjdwhfgcgcclrlswmzhzbfhjrggnhwtnffnqqcvldlttvvgrbcqbmqzvtflfmdblhdbzphrqtbshvp
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def find_signal(line):
|
||||
letters = [line[x] for x in range(4)]
|
||||
for index, letter in enumerate(line[4:]):
|
||||
if len(set(letters)) == 4:
|
||||
return(index + 4)
|
||||
letters[index % 4] = letter
|
||||
|
||||
|
||||
def find_signal_two(line):
|
||||
letters = [line[x] for x in range(14)]
|
||||
for index, letter in enumerate(line[14:]):
|
||||
if len(set(letters)) == 14:
|
||||
return(index + 14)
|
||||
letters[index % 14] = letter
|
||||
|
||||
|
||||
def main():
|
||||
with open('day6', 'r') as file:
|
||||
line = file.readlines()
|
||||
|
||||
line = line[0].strip()
|
||||
|
||||
print(find_signal(line))
|
||||
print(find_signal_two(line))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,125 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
class File:
|
||||
def __init__(self, name, size):
|
||||
self.name = name
|
||||
self.size = size
|
||||
|
||||
|
||||
class Directory:
|
||||
def __init__(self, name, parent):
|
||||
self.parent = parent
|
||||
self.name = name
|
||||
self.directories = []
|
||||
self.files = []
|
||||
|
||||
def addFile(self, file):
|
||||
self.files.append(file)
|
||||
|
||||
def addDirectory(self, directory):
|
||||
self.directories.append(directory)
|
||||
|
||||
def getSize(self):
|
||||
self.size = 0
|
||||
for file in self.files:
|
||||
self.size += int(file.size)
|
||||
for directory in self.directories:
|
||||
self.size += int(directory.getSize())
|
||||
return self.size
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
|
||||
class FileSystem:
|
||||
def __init__(self):
|
||||
self.root = Directory('/', '')
|
||||
self.root.parent = self.root
|
||||
self.current_directory = self.root
|
||||
self.all_directories = []
|
||||
|
||||
def addFile(self, file):
|
||||
self.root.files.append(file)
|
||||
|
||||
def addDirectory(self, directory):
|
||||
self.root.directories.append(directory)
|
||||
|
||||
def getSize(self):
|
||||
return self.root.getSize()
|
||||
|
||||
|
||||
def change_directory(line, fs):
|
||||
match line[2]:
|
||||
case '..':
|
||||
fs.current_directory = fs.current_directory.parent
|
||||
case '/':
|
||||
fs.current_directory = fs.root
|
||||
case _:
|
||||
for directory in fs.current_directory.directories:
|
||||
if directory.name == line[2]:
|
||||
fs.current_directory = directory
|
||||
return
|
||||
new_directory = Directory(line[2], fs.current_directory)
|
||||
fs.all_directories.append(new_directory)
|
||||
fs.current_directory.addDirectory(new_directory)
|
||||
fs.current_directory = new_directory
|
||||
|
||||
|
||||
def process_command(line, fs):
|
||||
match line[1]:
|
||||
case 'cd':
|
||||
change_directory(line, fs)
|
||||
case 'ls':
|
||||
pass
|
||||
|
||||
|
||||
def process_line(line, fs):
|
||||
line = line.split()
|
||||
match line[0]:
|
||||
case '$':
|
||||
process_command(line, fs)
|
||||
case 'dir':
|
||||
for directory in fs.current_directory.directories:
|
||||
if directory.name == line[1]:
|
||||
return
|
||||
new_directory = Directory(line[1], fs.current_directory)
|
||||
fs.all_directories.append(new_directory)
|
||||
fs.current_directory.addDirectory(new_directory)
|
||||
case _:
|
||||
for file in fs.current_directory.files:
|
||||
if file.name == line[1]:
|
||||
file.size == line[0]
|
||||
return
|
||||
new_file = File(line[1], line[0])
|
||||
fs.current_directory.addFile(new_file)
|
||||
|
||||
|
||||
def main():
|
||||
with open('day7', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
fs = FileSystem()
|
||||
fs.current_directory = fs
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
process_line(line, fs)
|
||||
|
||||
root_size = fs.getSize()
|
||||
print(f'{fs.root.name} : {root_size}')
|
||||
max_size = 30_000_000 - (70_000_000 - root_size)
|
||||
smallest = 30_000_000
|
||||
total_size = 0
|
||||
for directory in fs.all_directories:
|
||||
size = directory.getSize()
|
||||
if size <= 100_000:
|
||||
total_size += directory.getSize()
|
||||
if size >= max_size:
|
||||
if size < smallest:
|
||||
smallest = size
|
||||
print(total_size)
|
||||
print(smallest)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,23 @@
|
|||
$ cd /
|
||||
$ ls
|
||||
dir a
|
||||
14848514 b.txt
|
||||
8504156 c.dat
|
||||
dir d
|
||||
$ cd a
|
||||
$ ls
|
||||
dir e
|
||||
29116 f
|
||||
2557 g
|
||||
62596 h.lst
|
||||
$ cd e
|
||||
$ ls
|
||||
584 i
|
||||
$ cd ..
|
||||
$ cd ..
|
||||
$ cd d
|
||||
$ ls
|
||||
4060174 j
|
||||
8033020 d.log
|
||||
5626152 d.ext
|
||||
7214296 k
|
|
@ -0,0 +1,99 @@
|
|||
200120010031113332213034140102430141241124321111512323442304040044220141342121012210022220211111200
|
||||
111021120230012003124233312003010303204555454332453445353125225214221214442214301113012111020220220
|
||||
010000112330232223210123331341111021455213441355415452453433542411022110033014112420103200010200112
|
||||
210220131023203033023421012411405531115123145115445215311422135252541100222231431331003220231121021
|
||||
020112210133112114444340100410411231114131452544155151415233415312511222041221113442132231003203100
|
||||
121210122332301142321211440441113455552434332511455325315545354524142541534411112013143013120333022
|
||||
002022223332143323320030004111431434153352153321414154453442552321332341355132444030442110103203212
|
||||
212130023213100232130230411132244242133251435525323326611211534441513532233340420321144212221332012
|
||||
112201210213131241203033341411115513233426453426433653356253533133113511115222441140433214102332200
|
||||
212012000101044144022321521321444445566546646625625665232323663631331412343532242340023204432003233
|
||||
101233132121222100241254211542133266356326564552445466322626353633223221135151311240430411433022011
|
||||
200132020222314334333551152431232424524623645555522366665322366466545513112135535223102441334310202
|
||||
023113000020114221524122422222662645435544455234636242322656464245462233555511334411233402112203303
|
||||
323212301014434412315252233452332225554646452654545433445553336343544664455435323243510303023142200
|
||||
310022200424121333144123222262332322343322244646667564465544426245466232342143412141451122001041322
|
||||
212301111322001335441132334525635254352425553354565445643472236236266635446421522132452121404230333
|
||||
222212444300345211222512256444456624535343536756355746664436374344346652444335121144422222340114403
|
||||
133103420101433344253425324366444265345745457464444766674564476573243345254266312555221132304022243
|
||||
104024111323421413115464433455553477333456354575666765646757774776752425462423244113225443242031103
|
||||
102001244212344453145353232652647556546465453563544776667356374453675332254663444121345213131024201
|
||||
224444241243433331136646422564367344447534333336573546336576477746463642222264422255444411444213332
|
||||
111102440221143134255523244546456346745346547453543465664363545634575433436342252431313443241200434
|
||||
134231321331555233423635635366465473563535535586445888474374535544636375425246452265522242444124430
|
||||
234112414314111344422243544643454775656784865866884848444877466476364476356322553554245224411411221
|
||||
034400114351525345222546546744637535635657575787587675474664764764736443646462322222525151425423322
|
||||
200214241324215322354446653764777674587466544685754678446567884767437556756324542252661541311422130
|
||||
343144113253113264625454456777333344687566876677476786864558645875776364454562645333232242321313142
|
||||
343024121143435322432236376444777668467756646886688564457885758774655565674476525265433235351133020
|
||||
403402124545255442342535445764457654765745674556784877787445455686478773563733543423236235255444144
|
||||
103322531152132266562676355566367676848756788886766967585484486646776553753344443262466623351341241
|
||||
310355244513624552353465735465555764667556575665597778969594858667646774744555337236256442514154340
|
||||
023311451112523462333545544537465688645559988688956997665697964748587858337347363225646321434554144
|
||||
320135522136342345436443367666564847488558589757575579796688785767645678467555334323622425311134113
|
||||
302355525243323546577736555686874886486985688686888898966978978668487864787645754566534465541511251
|
||||
334125312126266532347576536548547584696886997768569758698995755875465674754333433642553345425533431
|
||||
341111335132225635365534457665748575977867585959997886979957965558787465664637533766462255534332423
|
||||
332515314534343636736373478687676678865555895657977886779567677978977887466835476754353523355412552
|
||||
223554423243256435734467677444784886576856669787898778968956989875566754875777467667635224535114135
|
||||
155522522343322534364735656868875656687568869667769697877887796866975856457447636733764232364431215
|
||||
242345244424435673345476658556448689589759768689899966877768987857579874745884637474453634352133231
|
||||
415255446645436567674735664645455855996887768879976678686967768687868985856885736776326622253351232
|
||||
345511155426334655353457846578475998667966669787979667866969678557875668566464436456435236255355314
|
||||
142554534636264637437346664558867877978687978689679869967766679569789677485678377367342526223134543
|
||||
445152112563265336347774464854776998568899676687677797996796877777879786686845577654534235322155423
|
||||
333311452256452445537757558677965658888896678979799998788899698785896978877575444547572432544335251
|
||||
153342523322435374455644657476596955598987666997999878876686677879688676464687476363732553363413554
|
||||
144335145664565566437454557675966795686769969779977988878679878778787789465465637576634655354532332
|
||||
152415343652336664567566647557776598677998979889877998977867798897785759685544636646555455665423232
|
||||
233452324356364643433768554555595977968766779897887998898666688775789556775758843355374525244243434
|
||||
415514136342636535455644448567857957878867697988999887897878896698589669784466744746433345345355353
|
||||
232342145445335734443368474877857768999979889789879797978786868766697957448687837436437246435352325
|
||||
423142134652644455355368647749855698998886897798977997799867788779868756865564445675347463653623132
|
||||
221215125542657466763755887857659858677696867997877899797779899996787779754784846775376254442211254
|
||||
154531463524644747547747455647685566769977767978799879788898879798999996758665537564563322242224125
|
||||
114543323332546776763457675777969696978788779877889799879998997975759878686666834757774555334611241
|
||||
353441154256436766664748544445957885788777978878979877989798876799786999466647747557553324526153313
|
||||
433233236244364537664567776764977668967888876787887977898978679686668778764647857553662664333221513
|
||||
112335142543334473565677774456986769698869989679787999966877889796668798648474667745633463364123315
|
||||
113555236654542657737447854474695576987788777767987976776779677896568655666568777374452626625515123
|
||||
335535115334436455537766485588496998559679678997888767666867796988758985466776445675326242423551222
|
||||
113534446446435634464566878474597579966586699697988866966997787776788976778774466655756463456235323
|
||||
432234422656545375357656547448457656589888789768979867898878979959955468888683644466555336562315155
|
||||
313344415452422533675445775845665999956589788887986877769867786689888565577764433373633363624515141
|
||||
222432351346446453465663784584875977688789959977876966969658866777886544775874577535665532224311252
|
||||
225114233145352533344653757488874695566977756698769768695668575699668757584555454357642544414312222
|
||||
033415322244643242337557674678486867575857998965787859688788778777887745544746656765646262354135222
|
||||
244444135424622245536477356767676647596876888859989597677576756885858547856577434533266366252341111
|
||||
043422441154553466473376764757644888596669857975585975898957778585855575867574554436566563342243533
|
||||
331142132342425642446677456357664865566895568659588999997598897847485545576757377726563624233332331
|
||||
023252542543632422666654576368776445864568889675685656595757555564576478356355573264462564525315531
|
||||
401013153355343645357335364463874854866687865999886679877556446867474565563474773455256232432344241
|
||||
021145311524153334266573666344586785645787666877957988698886547444446737764473344255436645355133043
|
||||
343022114235145422524664767447348848745548778464684486768568675765556575337775543626443412212441440
|
||||
111402455441135334663624565477563468586767564584754776865658486876757446535673333342623334312243002
|
||||
300312451335434322222245676775746358685854756547745674447587647487533473336654232544332431554454412
|
||||
433111155454541556355524273356653577688858857767884847858548544877576457444762553325524214215402141
|
||||
131233333423335563265232427676636343767667757678865557657665545337553674363435662333422331253432142
|
||||
424110224332255444554444426563344537343587775787775766858448446366677553432226234426335534235001312
|
||||
333412002215124441543424366273747763767633456777658554454464446357566564765333524264253113145112300
|
||||
101110030515255434456252656567734365435643756543777575374763565634563366532624443621453215143234300
|
||||
303322412424455315323623364345353365376676743654344676735433644466637676342646445331232331222232310
|
||||
323112211415542144152522545435246756534467755554567676637543357465766366552324534423444455001240332
|
||||
104010010231221552145233456226456635564775656444567465773637433733444632663325561451234351230241312
|
||||
121411232340543435321316435636242655564355535365574763633547465475523553325562122152444444042300041
|
||||
131012210332331125512334254246234345354543573744464635755354544666345534262435114123351541032131413
|
||||
320204021134412321515435566234224352423426577577364457356445435455454244243342521425351312003010221
|
||||
323114214132034241313542544555435465334424654666346364554655422236635456436354122354410044244241323
|
||||
013302120424301452153353441245652435266525344656664634425626224355262362255351231351513443132401213
|
||||
320030122021334215313244242334523262333453263233364243362363226452453421344311524253311414201210001
|
||||
232000301112410134252124412414346224626463252363536262245565624425334453135542241232142142113023001
|
||||
023101113421202000305251552134255163452646652324334242436543224522235515444445314014323100240020120
|
||||
320223110031202012323335553432231212252653563665545464422324656333443431535442453303001103202231020
|
||||
102033222010100142203435155413125314311166645446465322244546532441244154143433143443342400201012012
|
||||
103310002120123402241302221241151441435355114335344522434421453552354154135223134443030043002000021
|
||||
112323110033212002113322411233332355223342424233213123445224135331545115152043042400020200022133330
|
||||
022111301200101044211214231433231311322554214331413543414521424255241531111410022413003020200231110
|
||||
012022111212202121003233141343155411314255551134343533133453252153433344441013011221420230021203220
|
||||
221101122202110034040022441212441254112211113355531534335143125434435312222200311411322330203331100
|
||||
210122210200133032213341213111433213432513121525124133544144433541201142230241123430213303001122221
|
|
@ -0,0 +1,32 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
def main():
|
||||
with open('day8.sample', 'r') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
matrix = [list(line.strip()) for line in lines]
|
||||
last_column = len(matrix[0]) -1
|
||||
last_row = len(matrix) -1
|
||||
print(last_column, last_row)
|
||||
visible = 0
|
||||
for row_index, row in enumerate(matrix):
|
||||
for column_index, column in enumerate(row):
|
||||
try:
|
||||
if (column > matrix[row_index + 1][column_index] or
|
||||
column > matrix[row_index - 1][column_index] or
|
||||
column > matrix[row_index][column_index + 1] or
|
||||
column > matrix[row_index][column_index - 1]):
|
||||
visible += 1
|
||||
elif (row_index == 0 or column_index == 0 or
|
||||
row_index == last_row or column_index == last_column):
|
||||
visible += 1
|
||||
else:
|
||||
print(f'not visible {column_index}x{row_index}', column)
|
||||
except IndexError:
|
||||
visible += 1
|
||||
print(visible)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -0,0 +1,5 @@
|
|||
30373
|
||||
25512
|
||||
65332
|
||||
33549
|
||||
35390
|
Loading…
Reference in New Issue