add 2019
This commit is contained in:
parent
856852f4ce
commit
fc8320bdd0
6
2019/00/00.py
Normal file
6
2019/00/00.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
with open("input.txt","r") as f:
|
||||
input = f.read().split('\n')
|
||||
|
||||
part1 = 0
|
||||
part2 = 0
|
||||
print(part1, part2)
|
0
2019/00/input.txt
Normal file
0
2019/00/input.txt
Normal file
15
2019/01/01.py
Normal file
15
2019/01/01.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
with open("input.txt","r") as f:
|
||||
masses = [int(x) for x in f.read().split('\n')]
|
||||
|
||||
def fuel_required(mass):
|
||||
return mass // 3 - 2
|
||||
|
||||
def fuel_required_recursive(mass):
|
||||
fuel = mass // 3 - 2
|
||||
if fuel <= 0:
|
||||
return 0
|
||||
return fuel + fuel_required_recursive(fuel)
|
||||
|
||||
part1 = sum([fuel_required(mass) for mass in masses])
|
||||
part2 = sum([fuel_required_recursive(mass) for mass in masses])
|
||||
print(part1, part2)
|
100
2019/01/input.txt
Normal file
100
2019/01/input.txt
Normal file
|
@ -0,0 +1,100 @@
|
|||
147077
|
||||
148686
|
||||
71851
|
||||
98056
|
||||
65024
|
||||
87254
|
||||
146003
|
||||
128542
|
||||
136657
|
||||
91885
|
||||
91904
|
||||
78806
|
||||
58210
|
||||
67520
|
||||
118393
|
||||
68344
|
||||
69593
|
||||
135370
|
||||
111892
|
||||
84153
|
||||
105683
|
||||
76166
|
||||
112780
|
||||
145179
|
||||
83811
|
||||
61481
|
||||
118277
|
||||
59732
|
||||
72222
|
||||
64606
|
||||
55645
|
||||
82168
|
||||
97590
|
||||
122479
|
||||
120365
|
||||
103057
|
||||
76225
|
||||
148099
|
||||
100610
|
||||
75592
|
||||
148678
|
||||
132756
|
||||
55335
|
||||
77094
|
||||
73992
|
||||
95097
|
||||
92382
|
||||
78885
|
||||
93657
|
||||
121709
|
||||
114261
|
||||
90565
|
||||
110043
|
||||
145497
|
||||
92066
|
||||
109833
|
||||
76107
|
||||
143941
|
||||
67084
|
||||
139407
|
||||
56730
|
||||
131457
|
||||
110026
|
||||
85632
|
||||
74239
|
||||
116964
|
||||
129806
|
||||
75030
|
||||
76317
|
||||
99523
|
||||
78069
|
||||
75685
|
||||
81279
|
||||
58287
|
||||
148135
|
||||
89313
|
||||
139141
|
||||
136066
|
||||
94046
|
||||
50430
|
||||
55242
|
||||
123494
|
||||
68410
|
||||
83716
|
||||
122608
|
||||
79343
|
||||
88826
|
||||
95968
|
||||
98603
|
||||
104895
|
||||
128814
|
||||
120473
|
||||
97504
|
||||
60990
|
||||
98132
|
||||
58895
|
||||
92987
|
||||
136301
|
||||
131747
|
||||
137498
|
31
2019/02/02.py
Normal file
31
2019/02/02.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
def process(program):
|
||||
i = 0
|
||||
while True:
|
||||
opcode = program[i]
|
||||
if opcode == 99:
|
||||
break
|
||||
elif opcode == 1:
|
||||
program[program[i+3]] = program[program[i+1]] + program[program[i+2]]
|
||||
elif opcode == 2:
|
||||
program[program[i+3]] = program[program[i+1]] * program[program[i+2]]
|
||||
else:
|
||||
break
|
||||
i += 4
|
||||
return program[0]
|
||||
|
||||
def alarm(noun, verb):
|
||||
with open("input.txt","r") as f:
|
||||
program = [int(x) for x in f.read().split(',')]
|
||||
program[1] = noun
|
||||
program[2] = verb
|
||||
return process(program)
|
||||
|
||||
def part2():
|
||||
for noun in range(100):
|
||||
for verb in range(1,100):
|
||||
if alarm(noun, verb) == 19690720:
|
||||
return 100 * noun + verb
|
||||
|
||||
part1 = alarm(12,2)
|
||||
part2 = part2()
|
||||
print(part1, part2)
|
1
2019/02/input.txt
Normal file
1
2019/02/input.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,10,1,19,1,6,19,23,1,23,13,27,2,6,27,31,1,5,31,35,2,10,35,39,1,6,39,43,1,13,43,47,2,47,6,51,1,51,5,55,1,55,6,59,2,59,10,63,1,63,6,67,2,67,10,71,1,71,9,75,2,75,10,79,1,79,5,83,2,10,83,87,1,87,6,91,2,9,91,95,1,95,5,99,1,5,99,103,1,103,10,107,1,9,107,111,1,6,111,115,1,115,5,119,1,10,119,123,2,6,123,127,2,127,6,131,1,131,2,135,1,10,135,0,99,2,0,14,0
|
1
2019/02/input_sample.txt
Normal file
1
2019/02/input_sample.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1,9,10,3,2,3,11,0,99,30,40,50
|
1
2019/02/input_sample2.txt
Normal file
1
2019/02/input_sample2.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1,0,0,0,99
|
27
2019/04/04.py
Normal file
27
2019/04/04.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
passwords = [str(p) for p in range(172851,675869+1)]
|
||||
|
||||
def monotonic(password):
|
||||
digits = list(password)
|
||||
if digits == sorted(digits):
|
||||
return True
|
||||
return False
|
||||
|
||||
def at_least_two_adjacent(password):
|
||||
digits = list(password)
|
||||
for i, digit in enumerate(digits):
|
||||
if i+1 == len(digits):
|
||||
return False
|
||||
if digits[i+1] == digit:
|
||||
return True
|
||||
|
||||
def exactly_two_adjacent(password):
|
||||
if not at_least_two_adjacent(password):
|
||||
return False
|
||||
digits = list(password)
|
||||
for digit in digits:
|
||||
if password.count(digit) == 2:
|
||||
return True
|
||||
|
||||
part1 = [p for p in passwords if monotonic(p) and at_least_two_adjacent(p)]
|
||||
part2 = [p for p in passwords if monotonic(p) and exactly_two_adjacent(p)]
|
||||
print(len(part1), len(part2))
|
1
2019/04/input.txt
Normal file
1
2019/04/input.txt
Normal file
|
@ -0,0 +1 @@
|
|||
172851-675869
|
33
2019/06/06.py
Normal file
33
2019/06/06.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
with open("input.txt","r") as f:
|
||||
lines = f.read().split('\n')
|
||||
orbits = {}
|
||||
for line in lines:
|
||||
parent, child = line.split(')')
|
||||
orbits[child] = parent
|
||||
|
||||
def depth(node, graph):
|
||||
depth = 1
|
||||
parent = graph[node]
|
||||
while parent != "COM":
|
||||
depth += 1
|
||||
parent = graph[parent]
|
||||
return depth
|
||||
|
||||
def parents(node, graph):
|
||||
path = []
|
||||
parent = graph[node]
|
||||
while parent != "COM":
|
||||
path.append(parent)
|
||||
parent = graph[parent]
|
||||
return path
|
||||
|
||||
def orbital_transfers(start, end, graph):
|
||||
path1 = parents(start, graph)
|
||||
path2 = parents(end, graph)
|
||||
set1 = set(path1)
|
||||
set2 = set(path2)
|
||||
return len((set1 - set2) | (set2 - set1)) # union of differences
|
||||
|
||||
part1 = sum([depth(x, orbits) for x in orbits.keys()])
|
||||
part2 = orbital_transfers("YOU", "SAN", orbits)
|
||||
print(part1, part2)
|
1799
2019/06/input.txt
Normal file
1799
2019/06/input.txt
Normal file
File diff suppressed because it is too large
Load diff
11
2019/06/input_sample.txt
Normal file
11
2019/06/input_sample.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
COM)B
|
||||
B)C
|
||||
C)D
|
||||
D)E
|
||||
E)F
|
||||
B)G
|
||||
G)H
|
||||
D)I
|
||||
E)J
|
||||
J)K
|
||||
K)L
|
13
2019/06/input_sample2.txt
Normal file
13
2019/06/input_sample2.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
COM)B
|
||||
B)C
|
||||
C)D
|
||||
D)E
|
||||
E)F
|
||||
B)G
|
||||
G)H
|
||||
D)I
|
||||
E)J
|
||||
J)K
|
||||
K)L
|
||||
K)YOU
|
||||
I)SAN
|
32
2019/08/08.py
Normal file
32
2019/08/08.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
from textwrap import wrap
|
||||
with open("input.txt","r") as f:
|
||||
width = 25
|
||||
height = 6
|
||||
layersize = width * height
|
||||
data = f.read()
|
||||
|
||||
layers = wrap(data, layersize)
|
||||
zeros = [layer.count("0") for layer in layers]
|
||||
i = zeros.index(min(zeros))
|
||||
part1 = layers[i].count("1") * layers[i].count("2")
|
||||
print(part1)
|
||||
|
||||
top = []
|
||||
for i, pixel in enumerate(layers[0]):
|
||||
n = 0
|
||||
while pixel == "2":
|
||||
pixel = layers[n][i]
|
||||
n += 1
|
||||
top.append(pixel)
|
||||
|
||||
def print_image(layer, width, height):
|
||||
output = ''
|
||||
for x in layer:
|
||||
output += x
|
||||
output = output.replace("0","⠀")
|
||||
output = output.replace("1","█")
|
||||
output = wrap(output, width)
|
||||
for line in output:
|
||||
print(line)
|
||||
|
||||
print_image(top, width, height)
|
1
2019/08/input.txt
Normal file
1
2019/08/input.txt
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue