Esempio n. 1
0
def run2(filename):
    input_list = AOCH.ril2(filename, '')
    p1 = list(map(int, input_list[0][1:]))
    p2 = list(map(int, input_list[1][1:]))
    bol, winner_list = game(p1, p2)
    score = 0
    for i in range(len(winner_list)):
        score += winner_list[i] * (len(winner_list) - i)
    return score
Esempio n. 2
0
def initialize(filename):
    input13 = AOCH.ril(filename)
    input13[0] = int(input13[0])
    input13[1] = input13[1].split(',')
    temp = []
    for j in input13[1]:
        if j != 'x':
            temp.append(int(j))
    return [input13[0], temp]
Esempio n. 3
0
def initialize(filename):
    input_list = AOCH.ril(filename)
    temp = []
    for i in range(len(input_list)):
        input_list[i] = input_list[i].split(' (')
        input_list[i][0] = input_list[i][0].split(' ')
        input_list[i][1] = input_list[i][1][9:-1].split(', ')
        for item in input_list[i][1]:
            if item not in temp:
                temp.append(item)
    return input_list, temp
Esempio n. 4
0
def run(filename):
    input_list = AOCH.ril(filename)
    res_set_black = {}
    for item in input_list:
        pos = str(position(item))
        if pos in res_set_black.keys():
            res_set_black.pop(pos)
        else:
            res_set_black[pos] = 'Black'

    return res_set_black
Esempio n. 5
0
def splitting(filename):
    input16 = AOCH.ril2(filename, '')
    for i in range(len(input16[0])):
        input16[0][i] = input16[0][i].split(': ')
        input16[0][i][1] = input16[0][i][1].split(' or ')
        for j in range(len(input16[0][i][1])):
            input16[0][i][1][j] = list(map(int,
                                           input16[0][i][1][j].split('-')))
    input16[1][1] = list(map(int, input16[1][1].split(',')))

    for i in range(1, len(input16[2])):
        input16[2][i] = list(map(int, input16[2][i].split(',')))
    return input16
Esempio n. 6
0
def initialize(filename, cycles):
    first_state = AOCH.ril(filename)
    for i in range(len(first_state)):
        temp1 = []
        for j in range(len(first_state[i])):
            temp1.append(first_state[i][j])
        first_state[i] = temp1
    for _ in range(cycles):
        first_state = append_row_and_col(first_state)
    res = [first_state]
    for _ in range(cycles):
        res = append_dimension(res)

    return res
Esempio n. 7
0
def run(filename, init_sub):
    pub = list(map(int, AOCH.ril(filename)))
    init = 1
    i = 0
    while init != pub[0]:
        init *= init_sub
        init = init % 20201227
        i += 1
    init = 1
    for _ in range(i):
        init *= pub[1]
        init = init % 20201227
    print(init)
    return init
Esempio n. 8
0
def run2(filename):
    input_list = AOCH.ril(filename)[1].split(',')
    print(input_list)
    between = []
    ids = []
    for i in range(len(input_list)):
        if input_list[i] != 'x':
            between.append(i)
            ids.append(int(input_list[i]))
    step = ids[0]
    n = 0
    for i in range(1, len(between)):
        print('n = ' + str(n) + ' og step = ' + str(step))
        n = find_n(step, n, ids[i], between[i])
        step = lcm(step, ids[i])
    return n
Esempio n. 9
0
def split_in_list(filename):
    temp = AOCH.ril(filename)
    temp2 = []
    temp3 = []
    mask = ''
    for i in range(len(temp)):
        if temp[i].split(' = ')[0] == 'mask':
            if len(mask) > 0:
                temp3.append([mask, temp2])
            mask = temp[i].split(' = ')[1]
            temp2 = []
        else:
            if temp[i][:3] == 'mem':
                temp2.append([
                    int(temp[i].split(' = ')[0][4:-1]),
                    int(temp[i].split(' = ')[1])
                ])
    temp3.append([mask, temp2])
    return temp3
Esempio n. 10
0
def initialize(filename):
    input19 = AOCH.ril2(filename, '')
    temp_set = {}
    for i in range(len(input19[0])):
        input19[0][i] = input19[0][i].split(': ')
        temp_list = input19[0][i][1].split(' | ')
        if len(temp_list) == 1:
            if len(temp_list[0].split(' ')) > 1:
                temp_set[input19[0][i][0]] = [temp_list[0].split(' ')]
            else:
                if temp_list[0][0] == '"':
                    temp_set[input19[0][i][0]] = temp_list[0].split('"')[1]
                else:
                    print('Here', temp_list)
                    temp_set[input19[0][i][0]] = [temp_list]
        else:
            for j in range(len(temp_list)):
                temp_list[j] = temp_list[j].split(' ')
            temp_set[input19[0][i][0]] = temp_list
    return [temp_set, input19[1]]
Esempio n. 11
0
def run(filename):
    input_list = AOCH.ril2(filename, '')
    p1 = list(map(int, input_list[0][1:]))
    p2 = list(map(int, input_list[1][1:]))
    while len(p1) > 0 and len(p2) > 0:
        if p1[0] > p2[0]:
            p1.append(p1[0])
            p1.append(p2[0])
        else:
            p2.append(p2[0])
            p2.append(p1[0])
        p1 = p1[1:]
        p2 = p2[1:]
        if len(p1) == 0:
            count = 0
            for i in range(len(p2)):
                count += p2[i] * (len(p2) - i)
            return count
        elif len(p2) == 0:
            count = 0
            for i in range(len(p1)):
                count += p1[i] * (len(p1) - i)
            return count
Esempio n. 12
0
import AOCH

input8 = AOCH.ril('input8.txt')


temp = []
for i in range(len(input8)):
    temp.append(input8[i].split(' '))
    temp[i][1] = int(temp[i][1])
input8 = temp


def run(item_list):
    acc = 0
    visited = []
    k = 0
    while k < len(item_list):
        if k in visited:
            return [acc, 0]
        elif item_list[k][0] == 'acc':
            visited.append(k)
            acc += item_list[k][1]
            k += 1
        elif item_list[k][0] == 'jmp':
            visited.append(k)
            k += item_list[k][1]
        elif item_list[k][0] == 'nop':
            visited.append(k)
            k += 1
    return [acc, 1]
Esempio n. 13
0
import AOCH
from AOCHelper import day2

input2 = AOCH.password_input("input2")
input2 = day2('input2')

count_t = 0
count_t2 = 0
for item in input2:
    count_l = 0
    letter = item[1][0]
    if (letter == item[2][item[0][0] - 1] and letter != item[2][item[0][1] - 1]) or \
            (letter != item[2][item[0][0] - 1] and letter == item[2][item[0][1] - 1]):
        count_t2 += 1
    for j in item[2]:
        if letter == j:
            count_l += 1
    if item[0][1] >= count_l >= item[0][0]:
        count_t += 1

print(count_t, count_t2)
Esempio n. 14
0
import AOCH

input6 = AOCH.ril('input6.txt')


def run(input_list):
    count = 0
    temp = []

    for i in input_list:
        if i == '':
            count += len(temp)
            temp = []
        else:
            for j in i:
                if j not in temp:
                    temp.append(j)
    count += len(temp)
    return count


print('Part 1: ' + str(run(input6)))


def run2(input_list):
    count = 0
    for i in input_list:
        temp = []
        for j in range(len(i)):
            for k in i[j]:
                in_all = True
Esempio n. 15
0
import AOCH
from math import cos, sin, radians

input12 = AOCH.ril('input12.txt')


def run(input_list):
    start = [0, 0]
    rad = 0
    for item in input_list:
        if item[0] == 'N':
            start[1] += int(item[1:])
        elif item[0] == 'S':
            start[1] -= int(item[1:])
        elif item[0] == 'E':
            start[0] += int(item[1:])
        elif item[0] == 'W':
            start[0] -= int(item[1:])
        elif item[0] == 'F':
            start[0] += round(cos(rad) * int(item[1:]))
            start[1] += round(sin(rad) * int(item[1:]))
        elif item[0] == 'R':
            rad -= radians(int(item[1:]))
        elif item[0] == 'L':
            rad += radians(int(item[1:]))
    return start


end_pos = run(input12)
print(abs(end_pos[0]) + abs(end_pos[1]))
Esempio n. 16
0
import AOCH
from AOCHelper import day1

input_list = AOCH.ril("input01")
input_list = AOCH.stt(input_list)

for i in range(0, len(input_list)):
    for j in range(i+1, len(input_list)):
        for k in range(j+1, len(input_list)):
            if input_list[i] + input_list[j] + input_list[k] == 2020:
                print([input_list[i], input_list[j], input_list[k], input_list[i] + input_list[j] + input_list[k],
                       input_list[i] * input_list[j] * input_list[k]])
Esempio n. 17
0
import AOCH

input7 = AOCH.ril('input7.txt')
input7 = AOCH.split_by(input7, ' ')


def make_set(input_list):
    temp2 = {}
    for i in input_list:
        temp3 = []
        for j in range(3, len(i)):
            if i[j][:3] == 'bag' or i[j] == 'bags':
                temp3.append([i[j - 3], i[j - 2] + ' ' + i[j - 1]])
        temp2[i[0] + ' ' + i[1]] = temp3
    return temp2


input7 = make_set(input7)

test_for1 = 'shiny gold'


def run(my_set, test_for):
    good_bags = [test_for]
    for item in good_bags:
        for key_val in my_set:
            test_list = [bag[1] for bag in my_set[key_val]]
            if item in test_list and key_val not in good_bags:
                good_bags.append(key_val)
    return len(good_bags) - 1
Esempio n. 18
0
import AOCH

input9 = AOCH.ril('input9.txt')

input9 = list(map(int, input9))


def val_list(item_list):
    temp = []
    for i in range(len(item_list)):
        for j in range(len(item_list)):
            temp.append(item_list[i] + item_list[j])
    return temp


def run(item_list, val_int):
    for i in range(val_int, len(item_list)):
        if item_list[i] not in val_list(item_list[i - val_int:i]):
            return item_list[i]
    return 0


def run2(item_list, val_int):
    number = run(item_list, val_int)
    for i in range(len(item_list)):
        for j in range(i):
            if sum(item_list[i - j:i]) == number:
                return min(item_list[i - j:i]) + max(item_list[i - j:i])

    return 0
Esempio n. 19
0
import AOCH
from operator import itemgetter

input4 = AOCH.passport('input4.txt')


def run(input_list):
    list_att = ['byr', 'iyr', 'eyr', 'hgt', 'hcl', 'ecl', 'pid']
    count_t = 0
    input_list = sorted(input_list, key=itemgetter(1))
    temp5 = []

    for i in input_list:
        if len(i) < len(list_att) - 1:
            continue

        count_att = 0

        for j in range(len(i)):
            if i[j][0] in list_att:
                count_att += 1
            if count_att == len(list_att):
                count_t += 1
                temp5.append(i)
    return [count_t, temp5]


print('Part 1: ' + str(run(input4)[0]))


def run2(input_list):
Esempio n. 20
0
def initialize(filename):
    input_list = AOCH.ril2(filename, '')
    input_set = {}
    for item in input_list:
        input_set[item[0].split(' ')[1][:-1]] = item[1:]
    return input_set
Esempio n. 21
0
import AOCH

res = sum([int(int(item) / 3) - 2 for item in AOCH.ril('input1.txt')])
print(res)

sum_res = 0
for i in [int(item) for item in AOCH.ril('input1.txt')]:
    current = i
    while current > 5:
        current = int(current / 3) - 2
        sum_res += current
print(sum_res)
Esempio n. 22
0
import AOCH
input3 = AOCH.ril("input3.txt")


def run(list_name: list, position: list, x: int, y: int):
    pos = position
    count1 = 0
    l = len(list_name[pos[0]])
    in_scope = True
    while in_scope:
        pos[1] = pos[1] % l
        if list_name[pos[0]][pos[1]] == '#':
            count1 += 1
        pos[0] += x
        pos[1] += y
        if pos[0] >= len(list_name):
            in_scope = False
    return count1


directions = [[1, 1], [1, 3], [1, 5], [1, 7], [2, 1]]
res = 1
for i in directions:
    temp = run(input3, [0, 0], i[0], i[1])
    res *= temp

print('Result part 2 ' + str(res))
Esempio n. 23
0
import AOCH

input5 = AOCH.ril("input5.txt")


def run(input_list):

    maxi = 0
    ID = []
    for i in input_list:
        row = ''
        col = ''

        for j in i:
            if j == 'F':
                row += '0'
            elif j == 'B':
                row += '1'
            elif j == 'R':
                col += '1'
            elif j == 'L':
                col += '0'

        if int(row, 2) * 8 + int(col, 2) > maxi:
            maxi = int(row, 2) * 8 + int(col, 2)

        ID.append(int(row, 2) * 8 + int(col, 2))

    ID = sorted(ID)
    res = -1
    for i in range(min(ID), max(ID)):
Esempio n. 24
0
import AOCH

input10 = AOCH.ril('input10.txt')

input10 = list(map(int, input10))
input10.append(0)
input10.append(max(input10) + 3)
input10 = sorted(input10)


def diff_in_list(input_list):
    temp = []
    for i in range(1, len(input_list)):
        temp.append(input_list[i] - input_list[i - 1])
    return temp


def run(input_list):
    temp = diff_in_list(input_list)

    return [temp.count(1), temp.count(3), temp.count(1) * temp.count(3)]


print(run(input10)[2])


def rec_pas(value):
    if value == 0 or value == 1:
        return 1
    elif value == 2:
        return 2