Esempio n. 1
0
#!/usr/bin/env python
from functools import lru_cache
import itertools
import sys
sys.path.insert(1, sys.path[0] + '/..')  # Add parent of my directory to path
import AOC  ## pylint: disable=import-error
lines = AOC.loadInput(None,'day11.data')


class Seating():
    def __init__(self,world):
        self.world = world
        self.occ = 0
        self.maxx = len(self.world)-1
        self.maxy = len(self.world[0])-1
        self.checkmatrix = list(filter(self.not00, itertools.product((1,0,-1),repeat=2)))

    def not00(self, x):
        return x != (0,0)

    def seecheck(self,x,y,dx,dy):
        ddx = dx
        ddy = dy
        while True:
            if 0 <= x+dx <= self.maxx:
                if 0 <= y+dy <= self.maxy:
                    if self.world[x+dx][y+dy] == ".":
                        dx += ddx
                        dy += ddy
                        next
                    elif self.world[x+dx][y+dy] == "#":
Esempio n. 2
0
from typing import List
import sys
sys.path.insert(1, sys.path[0] + '/..')  # Add parent of my directory to path
import AOC  ## pylint: disable=import-error
lines: List = AOC.loadInput(None,'input', notInt=True)

TEST = ["00100", "11110", "10110", "10111",
        "10101", "01111", "00111", "11100",
        "10000","11001","00010", "01010" ]

def part1(input: List) -> int:
    bits = [int(a) for a in "0" * len(str(input[0]))] 
    sbits = [int(a) for a in "0" * len(str(input[0]))] 
    ubits = [int(a) for a in "0" * len(str(input[0]))] 
    for line in input:
        for n,bit in enumerate(str(line)):
            bits[n] += int(bit)
    half = len(input)/2
    for n,a in enumerate(bits):
        if a > half:
            sbits[n] = 1
            ubits[n] = 0
        else:
            sbits[n] = 0
            ubits[n] = 1
    gamma = int("".join([str(a) for a in sbits]),2)
    epsilon = int("".join([str(a) for a in ubits]),2)    
    print(sbits, gamma)
    print(ubits, epsilon)
    return gamma*epsilon
Esempio n. 3
0
#!/usr/bin/env python
import sys
sys.path.insert(1, sys.path[0] + '/..')  # Add parent of my directory to path
from itertools import combinations
import AOC  ## pylint: disable=import-error
lines = AOC.loadInput(10)

jolt = 0
joltdiff = dict()
for line in sorted(lines):
    if line - jolt in joltdiff.keys():
        joltdiff[line - jolt] += 1
    else:
        joltdiff[line - jolt] = 1
    jolt = line
joltdiff[3] += 1  # Add the last +3 for the device
# print(joltdiff)
print(joltdiff[3] * joltdiff[1])
AOC.printTimeTaken()
Esempio n. 4
0
#!/usr/bin/env python
import sys
sys.path.insert(1, sys.path[0] + '/..')  # Add parent of my directory to path
from itertools import combinations
import AOC  ## pylint: disable=import-error
lines = AOC.loadInput(9)

preamble = 25


def xmas_check(num, buffer):
    for a, b in combinations(buffer, 2):
        if a + b == num:
            return True
    return False


def xmas_hack(num, buffer):
    for start in range(len(buffer)):
        offset = 2
        while sum(buffer[start:start + offset]) < num:
            offset += 1
        if sum(buffer[start:start + offset]) == num:
            # print(buffer[start:start+offset])
            # print(f"fount at {start} - {start+offset}")
            _min = min(buffer[start:start + offset])
            _max = max(buffer[start:start + offset])
            print(f"{_min} + {_max} = {_min+_max}")
            return

Esempio n. 5
0
from typing import List
import sys
sys.path.insert(1, sys.path[0] + '/..')  # Add parent of my directory to path
import AOC  ## pylint: disable=import-error
lines: List = AOC.loadInput(None, 'input')

TEST = ["forward 5", "down 5", "forward 8", "up 3", "down 8", "forward 2"]


def part1(input: List) -> int:
    horizontal = 0
    depth = 0
    for data in input:
        cmd, length = data.split()
        length = int(length)
        if cmd == "forward":
            horizontal += length
        elif cmd == "down":
            depth += length
        elif cmd == "up":
            depth -= length
    return horizontal * depth


def part2(input: List) -> int:
    horizontal = 0
    depth = 0
    aim = 0
    for data in input:
        cmd, length = data.split()
        length = int(length)