added next to days

This commit is contained in:
Peter Hudec
2018-12-15 15:00:57 +01:00
parent 2785fe4c1d
commit 6c2ec8b826
10 changed files with 206 additions and 0 deletions

26
08/solve01.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env python
def read_input():
with open('input.txt', 'r') as f:
data = f.read().splitlines()
return [ int(x) for x in data[0].split(" ")]
def get_node_meta(data, pos):
num_ch = data[pos]
num_m = data[pos+1]
len_ch = 0 # total length of children
meta = []
for ch in range(num_ch):
(ch_len, ch_meta) = get_node_meta(data, pos+2+len_ch)
len_ch += ch_len
meta = meta + ch_meta
meta = meta + data[pos+2+len_ch:pos+2+len_ch+num_m]
return (len_ch+2+num_m, meta)
tree = read_input()
(_, meta) = get_node_meta(tree, 0)
print(sum(meta))