part1 (2242B)
1--- Day 6: Universal Orbit Map --- 2 3You've landed at the Universal Orbit Map facility on Mercury. Because navigation in space often 4involves transferring between orbits, the orbit maps here are useful for finding efficient routes 5between, for example, you and Santa. You download a map of the local orbits (your puzzle input). 6 7Except for the universal Center of Mass (COM), every object in space is in orbit around exactly one 8other object. An orbit looks roughly like this: 9 10 \ 11 \ 12 | 13 | 14AAA--> o o <--BBB 15 | 16 | 17 / 18 / 19 20In this diagram, the object BBB is in orbit around AAA. The path that BBB takes around AAA (drawn 21with lines) is only partly shown. In the map data, this orbital relationship is written AAA)BBB, 22which means "BBB is in orbit around AAA". 23 24Before you use your map data to plot a course, you need to make sure it wasn't corrupted during the 25download. To verify maps, the Universal Orbit Map facility uses [1m[97morbit count checksums[0m - the total 26number of [1m[97mdirect orbits[0m (like the one shown above) and [1m[97mindirect orbits[0m. 27 28Whenever A orbits B and B orbits C, then A [1m[97mindirectly orbits[0m C. This chain can be any number of 29objects long: if A orbits B, B orbits C, and C orbits D, then A indirectly orbits D. 30For example, suppose you have the following map: 31 32COM)B 33B)C 34C)D 35D)E 36E)F 37B)G 38G)H 39D)I 40E)J 41J)K 42K)L 43 44Visually, the above map of orbits looks like this: 45 46 G - H J - K - L 47 / / 48COM - B - C - D - E - F 49 \ 50 I 51 52In this visual representation, when two objects are connected by a line, the one on the right 53directly orbits the one on the left. 54 55Here, we can count the total number of orbits as follows: 56 57 58 - D directly orbits C and indirectly orbits B and COM, a total of 3 orbits. 59 60 - L directly orbits K and indirectly orbits J, E, D, C, B, and COM, a total of 7 orbits. 61 62 - COM orbits nothing. 63 64 65The total number of direct and indirect orbits in this example is [1m[97m42[0m. 66 67[1m[97mWhat is the total number of direct and indirect orbits[0m in your map data? 68 69 70