Exemple #1
0
# Day 4: Passport Processing

from projects.helpers import io

rows = []


def add_to_rows(line):
    try:
        rows_item = line
        rows.append(rows_item)
    except ValueError:
        return


io.read_file_by_newline("day4.txt", add_to_rows)


#Function to create array of people from rows
def parse_people(rows):
    persons = []
    index = 0
    persons.append('')
    for row in rows:
        #print(row)
        if len(row) > 1:
            #print(index)
            row = row.rstrip()
            persons[index] = persons[index] + ' ' + row
            persons[index] = persons[index].strip()
        else:
Exemple #2
0
def find_col(map):
    map = map.strip('FB')
    range = [0, 7]
    for x in map:
        if x == 'L':
            range[1] = math.floor(statistics.median(range))
        else:
            range[0] = math.ceil(statistics.median(range))

    if map[-1] == "R":
        return range[0]
    else:
        return range[1]

io.read_file_by_newline("day5.txt", add_to_arr)
highest_ID = -1
row = 0
col = 0
passes_sorted = []
for x in passes:
    row = find_row(x)
    col = find_col(x)
    current_ID = row*8+col
    passes_sorted.append(current_ID)
    if current_ID > highest_ID:
        highest_ID = current_ID

print('Highest ID: ', highest_ID)
passes_sorted = sorted(passes_sorted)
for i in range(0, len(passes_sorted)-1):
Exemple #3
0
# Day 1: Report Repair
from projects.helpers import io

A = []

def add_to_A(line):
    try:
        A_item = int(line)
        A.append(A_item)
    except ValueError:
        return


io.read_file_by_newline("day1.txt", add_to_A)

list_num = len(A)
num = 2020
x = 0
while x < list_num - 1:
    y = x + 1
    while y < list_num:
        if A[x] + A[y] == num:
            print(A[x], A[y], num, A[x] * A[y])
            break
        else:
            y += 1
    x += 1

x = 0
while x < list_num - 2:
    y = x + 1