[Python/2018] Move solutions into .py files
This commit is contained in:
parent
edb04277c6
commit
40e767096e
60 changed files with 1518 additions and 3541 deletions
41
Python/2018/08.py
Normal file
41
Python/2018/08.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2018, 8)
|
||||
|
||||
(*nums,) = map(int, input.split())
|
||||
|
||||
|
||||
def get_metadata_sum():
|
||||
child_count = nums.pop(0)
|
||||
meta_count = nums.pop(0)
|
||||
out = 0
|
||||
for _ in range(child_count):
|
||||
out += get_metadata_sum()
|
||||
for _ in range(meta_count):
|
||||
out += nums.pop(0)
|
||||
return out
|
||||
|
||||
|
||||
print(get_metadata_sum())
|
||||
|
||||
|
||||
(*nums,) = map(int, input.split())
|
||||
|
||||
|
||||
def get_value():
|
||||
child_count = nums.pop(0)
|
||||
meta_count = nums.pop(0)
|
||||
out = 0
|
||||
|
||||
childs = [get_value() for _ in range(child_count)]
|
||||
|
||||
for _ in range(meta_count):
|
||||
num = nums.pop(0)
|
||||
if not child_count:
|
||||
out += num
|
||||
elif 1 <= num <= child_count:
|
||||
out += childs[num - 1]
|
||||
return out
|
||||
|
||||
|
||||
print(get_value())
|
Loading…
Add table
Add a link
Reference in a new issue