<jupyter_start><jupyter_text>**First read in the data**<jupyter_code>input_file = os.path.join("inputs", "day_5.txt")
with open(input_file) as f:
        data_in = f.readlines()
coords_start = []
coords_end = []

for d in data_in:
    input_split = re.split(r'(\s->\s)',d.strip("\n"))
    coords_start.append(input_split[0].split(","))
    coords_end.append(input_split[2].split(","))

coords_start = np.asarray(coords_start, dtype=int)
coords_end = np.asarray(coords_end, dtype=int)<jupyter_output><empty_output><jupyter_text>**Now we have our input data, we can work on solving part 1**Keep in mind it looks likely we will also needed coords where either a x or y coord do not necessarily match.<jupyter_code>list(zip(coords_start, coords_end))[1][0]
vent_lines_x = np.array([])
vent_lines_y = np.array([])

for start, end in zip(coords_start, coords_end):
    # only operate on pairs which share a coord
    if start[0] == end[0]:
        # now we know x_coords match
        new_y = np.array(
            range(min(start[1], end[1]), max(start[1], end[1]) + 1)
        )
        vent_lines_y = np.append(vent_lines_y, new_y)
        vent_lines_x = np.append(vent_lines_x, start[0]*np.ones(len(new_y)))
    elif start[1] == end[1]:
        # now we know y_coords match
        new_x = np.array(
            range(min(start[0], end[0]), max(start[0], end[0]) + 1)
        )
        vent_lines_x = np.append(vent_lines_x, new_x)
        vent_lines_y = np.append(vent_lines_y, start[1]*np.ones(len(new_x)))
    elif abs(end[1] - start[1]) == abs(end[0] - start[0]):
        # now we have a 45 deg diagonal line
        delta = np.array(range(abs(end[1] - start[1])+1))
        direction = (end - start)/abs(end[1] - start[1])
        
        new_x = start[0] + delta*direction[0]
        new_y = start[1] + delta*direction[1]
        vent_lines_x = np.append(vent_lines_x, new_x)
        vent_lines_y = np.append(vent_lines_y, new_y)
    else:
        # not interested  
        pass
all_coords = list(zip(vent_lines_x, vent_lines_y))
coord_dict = dict(Counter(all_coords))
total = 0

for _, value in coord_dict.items():
    if value > 1:
        total += 1

print(total)<jupyter_output>22083
{'fraction_non_alphanumeric': 0.1459188326493388, 'fraction_numerical': 0.02051983584131327, 'mean_word_length': 3.3445544554455444, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '367510', 'license': 'MIT', 'n_tokens_mistral': 835, 'n_tokens_neox': 821, 'n_words': 176, 'path': 'day_5.ipynb', 'repo_name': 'willjrh/Advent-of-code-21', 'size': '2193'}