Ejemplo n.º 1
0
def get_directions():
    raw_directions = ut.read_file('input.txt').split(', ')
    final_directions = []
    for direction in raw_directions:
        dir = direction[0]
        steps = int(direction[1:])
        final_directions.append((dir, steps))
    return final_directions
Ejemplo n.º 2
0
def get_password_data():
    raw_password_data = [line.split(': ') for line in ut.read_file('input.txt').splitlines()]
    password_data = []
    for password in raw_password_data:
        new_password = password[1]
        policy_char = password[0].split()[1]
        policy_range = [int(val) for val in password[0].split()[0].split('-')]
        password_data.append(PasswordPolicy(new_password, policy_char, policy_range))
    return password_data
Ejemplo n.º 3
0
def get_room_data():
    raw_data = ut.read_file('input.txt').split()
    room_data = []
    for raw_room in raw_data:
        room = raw_room.split('-')
        sector_id = int(room[len(room) - 1].split('[')[0])
        checksum = room[len(room) - 1].split('[')[1].replace(']', '')
        room_name = room[0:len(room) - 1]
        final_room = [room_name, sector_id, checksum]
        room_data.append(final_room)

    return room_data
Ejemplo n.º 4
0
def get_corrupted_message():
    message_in_rows = ut.read_file('input.txt').split()
    message_in_columns = [[], [], [], [], [], [], [], []]

    rows = len(message_in_rows)
    cols = len(message_in_rows[0])

    for row in range(0, rows):
        for col in range(0, cols):
            message_in_columns[col].append(message_in_rows[row][col])

    return message_in_columns
Ejemplo n.º 5
0
    def load(self):

        if not os.path.exists(self.file_path):
            self.err = "File Not Exists"
            return

        self.raw, self.err = ut.read_file(self.file_path)
        if self.err != None:
            return

        self.html = mistune.markdown(self.raw, escape=False, parse_html=True)

        """
Ejemplo n.º 6
0
def get_ip_addresses():
    raw_data = ut.read_file('input.txt').split()

    ip_addresses = []
    for address in raw_data:

        new_address = []

        hyper_net_sequences = re.findall("\[([^[\]]*)\]", address)
        non_hyper_net_sequences = re.sub("[\(\[].*?[\)\]]", " ",
                                         address).split()
        new_address.append(non_hyper_net_sequences)
        new_address.append(hyper_net_sequences)
        ip_addresses.append(new_address)

    return ip_addresses
Ejemplo n.º 7
0
def get_triangles():
    raw_triangles = ut.read_file('input.txt').split()
    column_1 = []
    column_2 = []
    column_3 = []

    index = 0
    while index < len(raw_triangles):
        row = raw_triangles[index:(index + 3)]

        column_1.append(row[0])
        column_2.append(row[1])
        column_3.append(row[2])

        index += 3

    return column_1, column_2, column_3
Ejemplo n.º 8
0
        for index in range(row_index - 1, row_index + 2)
    ]
    return triplet


def get_triplets(row):
    return [get_triplet(row, row_index) for row_index in range(0, len(row))]


def get_next_row(current_row):
    triplets = get_triplets(current_row)
    return ''.join([get_tile_type(triplet) for triplet in triplets])


def generate_map(current_row, rows):
    trap_map = [current_row]
    while len(trap_map) < rows:
        current_row = get_next_row(current_row)
        trap_map.append(current_row)
    return trap_map


def count_safe_tile(trap_map: list[list]):

    return sum([row.count('.') for row in trap_map])


first_row = ut.read_file('input.txt')
tr_map = generate_map(first_row, 400000)
print('Safe tiles: ' + str(count_safe_tile(tr_map)))
Ejemplo n.º 9
0
import ut
import math
import copy

sea_monster = [
    list(line) for line in ut.read_file('sea_monster.txt').splitlines()
]


class Piece:
    def __init__(self, piece_id, image):
        self.image = image
        self.piece_id = piece_id

    def up_edge(self):
        return self.image[0]

    def down_edge(self):
        return self.image[-1]

    def left_edge(self):
        return [row[0] for row in self.image]

    def right_edge(self):
        return [row[-1] for row in self.image]

    def flip(self):
        for row in self.image:
            row.reverse()

    def rotate(self):
Ejemplo n.º 10
0
def get_compressed_message():
    return ut.read_file('input.txt')
Ejemplo n.º 11
0
def get_instructions():
    return ut.read_file('input.txt').splitlines()