<jupyter_start><jupyter_text>Puzzle 1: Calculate number of orbits in map  direct and indirect orbits<jupyter_code>import numpy as np<jupyter_output><empty_output><jupyter_text>Load input<jupyter_code>with open('./input6.txt', 'r') as file:

    data = file.readlines()<jupyter_output><empty_output><jupyter_text>Some data preprocessing<jupyter_code>data = [x.strip() for x in data]
data = [x.split(')') for x in data]
orbit_dict = dict()
for orbit in data:
    if orbit[0] in orbit_dict:
        orbit_dict['{0}'.format(orbit[0])].append(orbit[1])
    else:
        orbit_dict['{0}'.format(orbit[0])] = []
        orbit_dict['{0}'.format(orbit[0])].append(orbit[1])<jupyter_output><empty_output><jupyter_text>Calculation<jupyter_code>orbit = 'COM'
counter = 1
overall = 0
run = True

while run is True:
    orbit = 'COM'
    counter = 1
    while True:
        next_orbit = orbit_dict['{0}'.format(orbit)][0]
        if next_orbit in orbit_dict.keys():         
            orbit = next_orbit
            counter += 1
        else: 
            del orbit_dict['{0}'.format(orbit)][0]
            if len(orbit_dict['{0}'.format(orbit)]) == 0:
                del orbit_dict['{0}'.format(orbit)]
            overall += counter
            break
    if len(orbit_dict) == 0:
        run = False
print('The overall number of orbits in the map is {0}.'.format(overall))<jupyter_output>The overall number of orbits in the map is 122782.<jupyter_text>Puzzle 2: Transfer towards Santa  YOU to SAN  Load input<jupyter_code>with open('./input6.txt', 'r') as file:

    data = file.readlines()
data = [x.strip() for x in data]
data = [x.split(')') for x in data]
orbit_dict = dict()
for orbit in data:
    if orbit[0] in orbit_dict:
        orbit_dict['{0}'.format(orbit[0])].append(orbit[1])
    else:
        orbit_dict['{0}'.format(orbit[0])] = []
        orbit_dict['{0}'.format(orbit[0])].append(orbit[1])<jupyter_output><empty_output><jupyter_text>Way from YOU to COM<jupyter_code>run = True
way_you = []
orbit = 'YOU'

while run is True:
    counter = 0
    for key, values in orbit_dict.items():
        if orbit in values:
            way_you.append(orbit)
            orbit = key
            break
    if orbit == 'COM':
        run = False<jupyter_output><empty_output><jupyter_text>Way from SAN to COM<jupyter_code>run = True
way_san = []
orbit = 'SAN'

while run is True:
    counter = 0
    for key, values in orbit_dict.items():
        if orbit in values:
            way_san.append(orbit)
            orbit = key
            break
    if orbit == 'COM':
        run = False
for orbit in way_you:
    if orbit in way_san:
        break
print('Both ways intersect in {0}.'.format(orbit))<jupyter_output>Both ways intersect in 72D.<jupyter_text>Now calculate way from YOU to SAN<jupyter_code>way = way_you[1:way_you.index('72D')] + way_san[1:way_san.index('72D')]
print('You need {0} orbital transfers to reach Santa.'.format(len(way)))<jupyter_output>You need 271 orbital transfers to reach Santa.
{'fraction_non_alphanumeric': 0.13628790403198934, 'fraction_numerical': 0.01866044651782739, 'mean_word_length': 3.2401129943502824, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '602563', 'license': 'MIT', 'n_tokens_mistral': 1107, 'n_tokens_neox': 1032, 'n_words': 257, 'path': 'day6/Script6.ipynb', 'repo_name': 'FabianKreutmayr/advent_of_code_19', 'size': '3001'}