Exemple #1
0
# print(scan_letters('FBFBBFF', (0,127)))
# print(scan_letters('RLR', (0,7)))


def get_seat_ID(inp):
    row_str = re.findall(r'([FB]+)', inp)
    col_str = re.findall(r'([RL]+)', inp)
    if (row_str and col_str):
        row_id = scan_letters(row_str[0], (0, 127))
        col_id = scan_letters(col_str[0], (0, 7))
        seat_id = row_id * 8 + col_id
        # print("{}: row {}, column {}, seat ID {}.".format(inp, row_id, col_id, seat_id))
        return seat_id


part1_inp = readInput('Input/day5input.txt')
max_id = 0
codes = []
for code in part1_inp:
    _id = get_seat_ID(code)
    # print(_id)
    if (max_id < _id): max_id = _id
    codes.append(_id)
print("Max id for part 1 is: {}".format(max_id))

codes.sort()
for i in range(36, 945):
    if (not (i in codes)): print("missing seat is : {}".format(i))

# get_seat_ID ('FBFBBFFRLR')
Exemple #2
0
        return False


def pwd_policy_NEW_check(t):
    if (t):
        _from, _to, _char, sequence = t[0]
        _from = int(_from) - 1  # To match array index starting at 0
        _to = int(_to) - 1  # To macth array index starting at 0
        print(_from, _to, _char, sequence, len(sequence))
        if not (sequence[_from] == _char and sequence[_to] == _char):
            if (sequence[int(_from)] == _char or sequence[_to] == _char):
                return True
            #  print ("Password ok")


from InputReader import readInput
import re

input_file = readInput("Input/day2input.txt")
valid_passwords_old = []
valid_passwords_new = []
for pwd in input_file:
    test = re.findall(r'(\d+)-(\d+) (\w): (.*)', pwd)
    if pwd_policy_OLD_check(test):
        valid_passwords_old.append(pwd)
    if pwd_policy_NEW_check(test):
        valid_passwords_new.append(pwd)

print("valid OLD password count is:{}".format(len(valid_passwords_old)))
print("valid NEW password count is:{}".format(len(valid_passwords_new)))
Exemple #3
0
from InputReader import readInput

inp = readInput('Input/day6input.txt')

# print(inp)

answers = []
group = set()

for line in inp:
    if (not (line == '')):
        for l in line:
            group.add(l)
    else:
        answers.append(group)
        group = set()
answers.append(group)

# print(answers)
s = 0
for a in answers:
    s = s + len(a)

# print("total answers: {}".format(s))

survey = []
group = []
person = set()
i = 0
for line in inp:
    if (not (line == '')):
Exemple #4
0
# print("----------------------------")
# print("QUEUE")
# queue = Queue(8)
# queue.enqueue(DummyObject(8))
# queue.enqueue(DummyObject(6))
# queue.enqueue(DummyObject(22))
# queue.enqueue(DummyObject(3))
# queue.enqueue(DummyObject(4))
# queue.enqueue(DummyObject(14))
# queue.enqueue(DummyObject(9))
# queue.dequeue()
# queue.traverse()
# # queue.toDot("output.dot")
# # os.system("dot -Tps output.dot -o dotOutput.ps")
# print("----------------------------")
# print("STACK")
# st = Stack()
# st.push(DummyObject(8))
# st.push(DummyObject(13))
# st.push(DummyObject(50))
# st.push(DummyObject(89))
# st.push(DummyObject(0))
# st.push(DummyObject(23))
# st.push(DummyObject(2))
# # st.traverse()
# # st.toDot("output.dot")
# # os.system("dot -Tps output.dot -o dotOutput.ps")

readInput("input.txt")

Exemple #5
0
from InputReader import readInput

inp = [int(x) for x in readInput('Input/day9input.txt')]


def number_appears(arr, nr):
    for s in arr:
        test = nr - s
        if not (test == s) and (test in arr):
            return (test, s)
    return False


j = 0
cont_num = 0
for i in range(25, len(inp)):
    seq = inp[j:i]
    num = inp[i]
    if number_appears(inp[j:i], num):
        a, b = number_appears(inp[j:i], num)
        # print("{} is a sum of nr {} and {}  in sequence {}".format(num,a,b,seq))
        j += 1
    else:
        # print("{} is not matching sum of any previous numbers {}".format(num,seq))
        cont_num = num
        break

# print(num)
# print(inp.index(num))
# print(sum(inp[0:2]))
Exemple #6
0
#!/usr/local/bin/env python3
"""input_location = 'Input/day1input.txt'
with open(input_location, "r") as f:
    read_data = f.read().splitlines()
    numbers = []
    for n in read_data:
        numbers.append(int(n))
        numbers.sort()
        print(numbers)"""
from InputReader import readInput

numbers = list(map(int, readInput("Input/day1input1.txt")))


def part1():
    outp = int()
    for s in numbers:
        t = 2020 - s
        if (t in numbers):
            print("Found number {} and {}. Their product is: {}".format(
                s, t, s * t))
            print("took {} iterations".format(numbers.index(s) + 1))
            return


part1()


def part2():
    for i in range(0, len(numbers)):
        for j in range(i + 1, len(numbers)):
Exemple #7
0
from InputReader import readInput
inp = readInput('Input/day11input.txt')


# print (inp)
def log(a):
    print("_" * 10)
    for x in (a):
        print(x)
    print("_" * 10)


_r = len(inp)
_c = len(inp[0])


def empty_seat(arr, i, j, limit):
    occupied_count = 0
    # print("is seat {}:{} empty?".format(i,j))
    for ii in range(i - 1, i + 2):
        for jj in range(j - 1, j + 2):
            if (not i == ii or not j == jj):
                if ii in range(0, _r) and jj in range(0, _c):
                    # print('checking{}:{}- value {}'.format(ii,jj,arr[ii][jj]))
                    if arr[ii][jj] == '#':
                        occupied_count += 1
    # print('seat {} {} is occupied by {} adjasent seats'.format(i,j,occupied_count))
    if occupied_count >= limit:
        return False
    else:
        return True
Exemple #8
0
from InputReader import readInput

slope = readInput("Input/day3input.txt")
#print(slope_pattern[0])

height = len(slope)

# helpers

# .............#...#....#.....##.

# evaluate if we reached bottom yet
def count_trees_downSlope(s, l):
    step = s
    trees = 0
    # height = 30
    for h in range(0+l,height,l):
        # move down the slope   
            # print ("level {} step {} value {}".format(h, step +1,slope[h][step]))
            # print(step)
            if slope[h][step] == "#":
                trees +=1
            if (step +  s  < len(slope[h])):
                step +=s
                # print("moved to {} step {}".format(h,step))
            else:
                step = (step + s) - len(slope[h])
                # print("Stepped over, moving to {} step {}".format(h+1,step))
            
    # print("Number of trees on the path is: {}".format(trees))
    return trees
from InputReader import readInput
import re


input = readInput("Input/day4input.txt")
passports_data = []
passport = {}
i = 0
# print(input)
for entry in input:
    
    if not (entry == ""):
        line = re.findall(r'(\w+):([\w#]+)', entry)
        for pair in line:
            k,v = pair
            passport[k]=v
    elif entry =="":
        passports_data.append(passport) #add object to list
        passport = {} #reset object
passports_data.append(passport) #putting last passport to the data list


mand = ["byr","iyr","eyr","hgt","hcl","ecl","pid"]
opt = ["cid"]

def validate_passport(p, mand, opt):
    # print("checking passport {} ......".format(p))
    if len(p.keys()) < len(mand):      
        # print("failed mand field count check. Nr of keys: {} Mand: {} ".format(len(p.keys()), len(mand)))
        return False
    for m in mand:
Exemple #10
0
from InputReader import readInput
inp = readInput('Input/s.txt')

print(inp)


def empty_direction(arr, i, j):
    print(i, j)
    _r = len(arr)
    _c = len(arr[0])
    if (i in range(0, _r) and j in range(0, _c)):
        if arr[i][j] == '#': return 1
        else:
            return empty_direction(arr, i, j - 1) + empty_direction(
                arr, i, j + 1)
    else:
        return 0
    return 0


print(empty_direction(inp, 1, 1))