Last active
December 6, 2019 09:34
-
-
Save erikaderstedt/c684af393a053efae11dac8700937a5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf8 -*- | |
from re import compile | |
x = compile(r"(\S+)\)(\S+)") | |
orbits = [x.match(r).groups() for r in open('6.in','r').read().split('\n') if x.match(r) is not None] | |
def orbit_checker(all_orbits, center, depth): | |
s = [orbit_checker(all_orbits, j[1], depth+1) for j in [x for x in orbits if x[0] == center]] | |
return sum(s) + len(s)*depth | |
def upwards(all_orbits, from_node): | |
return next(([x[0]] + upwards(all_orbits, x[0]) for x in orbits if x[1] == from_node), []) | |
srco = upwards(orbits, "YOU") | |
dsto = upwards(orbits, "SAN") | |
print("Pt 1:", orbit_checker(orbits, 'COM',1)) | |
print("Pt 2:", min([i + dsto.index(o) for i,o in enumerate(srco) if o in dsto])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment