Honestly, Advent of Code is so much fun. This stuff makes me fall back in love with programming.
defget_data(_file):orbits={}objects=set()forlinein_file:to_orbit,orbiter=line.rstrip().split(")")orbits[orbiter]=to_orbitobjects.add(to_orbit)objects.add(orbiter)returnorbits,objectsdefget_orbit(current_obj,orbits):ifcurrent_objnotinorbits:return[]return[orbits[current_obj]]+get_orbit(orbits[current_obj],orbits)defget_total_orbits(orbits):returnsum(len(get_orbit(obj,orbits))forobjinobjects)defget_path_between(start,end,orbits):start_path,end_path=get_orbit(start,orbits),get_orbit(end,orbits)# Get the first point that is in both paths
overlapping_point=[iforiinstart_pathifiinend_path][0]returnstart_path.index(overlapping_point)+end_path.index(overlapping_point)withopen("input.txt")as_file:orbits,objects=get_data(_file)print(f"Part 1: {get_total_orbits(orbits)}")print(f'Part 2: {get_path_between("YOU", "SAN", orbits)}')
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Honestly, Advent of Code is so much fun. This stuff makes me fall back in love with programming.