Esempio n. 1
0
def get_input():
    lines = read_input_as_list("inputs/12.txt")
    pos = {}
    points = [get_tuple(line) for line in lines]
    for p1 in points:
        pos[p1] = p1
    return pos
Esempio n. 2
0
def construct_graph():
    global g
    lines = read_input_as_list("inputs/14.txt")
    for line in lines:
        lh_elements = [
            extract_element(ele_tuple)
            for ele_tuple in line.split("=>")[0].split(",")
        ]
        rh_element = [
            extract_element(ele_tuple)
            for ele_tuple in line.split("=>")[1].split(",")
        ][0]

        if rh_element not in g.nodes:
            g.add_node(rh_element, name=rh_element)
        for lh_element in lh_elements:
            if lh_element not in g.nodes:
                g.add_node(lh_element, name=lh_element)
            g.add_edge(rh_element[0],
                       lh_element[0],
                       l_val=lh_element[1],
                       r_val=rh_element[1])
Esempio n. 3
0
from Utils import read_input_as_list
import sys

lines = read_input_as_list("inputs/8.txt")
input = [int(i) for i in list(str(lines[0]))]
width = 25
height = 6

k = i = z_c = o_c = t_c = ans = 0
min_z_c = sys.maxsize
image = [2] * (width * height)
for j, num in enumerate(input):
    z_c += 1 if num == 0 else 0
    o_c += 1 if num == 1 else 0
    t_c += 1 if num == 2 else 0

    if j % (width * height) == 0 and j != 0:
        if min_z_c > z_c:
            ans = o_c * t_c
            min_z_c = z_c
        z_c = 1 if num == 0 else 0
        o_c = 1 if num == 1 else 0
        t_c = 1 if num == 2 else 0
        k = 0
    image[k] = num if image[k] == 2 else image[k]
    k += 1

if min_z_c > z_c:
    ans = o_c * t_c

print("Part 1")