Пример #1
0
def test_jotls_reduce_sample():
    from loader import read_input
    devices = list(read_input('sample'))
    stats = jolts.jolts_reduce(devices)
    assert len(stats) == 2
    assert stats[1] == 22
    assert stats[3] == 10
Пример #2
0
def main():
    all_numbers = list(read_input(FILENAME))
    dec = Decoder(size=SIZE, preamble=all_numbers[0:SIZE])
    invalid_number = None
    for next_value in all_numbers[SIZE:]:
        if dec.is_valid(next_value):
            dec.append(next_value)
        else:
            invalid_number = next_value
            break
    for initial, value in enumerate(all_numbers):
        # print(f"[{initial}: {value}]", end="")
        if value == invalid_number:
            # print('Skipped trivial solution')
            continue
        acc = value
        final = initial + 1
        while final < len(all_numbers) and acc < invalid_number:
            acc += all_numbers[final]
            final += 1
        if acc == invalid_number:
            break
    sequence = all_numbers[initial:final]
    expr = '+'.join(map(str, sequence))
    print(f'Found in positions [{initial}-{final}] {expr} = {invalid_number}')
    print(f"Min value is {min(sequence)}")
    print(f"Max value is {max(sequence)}")
    print(f"Solution 2 is {min(sequence)+max(sequence)}")
Пример #3
0
def main():
    all_bags = list(read_input("input"))
    shiny_gold = Bag.registry[('shiny', 'gold')]
    acc = 0
    for bag in all_bags:
        if shiny_gold in bag.expand():
            acc += 1
    print(f"Solution 1: {acc}")
Пример #4
0
def test_read_input():
    results = list(loader.read_input('sample'))
    assert len(results) == 5
    assert results[0] == ['abc']
    assert results[1] == ['a', 'b', 'c']
    assert results[2] == ['ab', 'ac']
    assert results[3] == ['a', 'a', 'a', 'a']
    assert results[4] == ['b']
Пример #5
0
def main():
    stream = read_input(FILENAME)
    dec = Decoder(size=SIZE)
    dec.load_preamble(stream)
    for next_value in stream:
        if dec.is_valid(next_value):
            dec.append(next_value)
        else:
            print(f'Solution 1 is {next_value}')
            break
Пример #6
0
def main():
    karte = read_input('input')
    round_num = 0
    while True:
        karte, changes = evolve(karte)
        round_num += 1
        if changes == 0:
            break
    print(f"Found stable position in round_num {round_num}")
    sol = sum([1 if c.is_occupied() else 0 for c in karte])
    print(f"Solution 1 is {sol}")
Пример #7
0
def main():
    proc = Proc()
    proc.load_memory(read_input('input'))
    for index, op in enumerate(proc.memory):
        if op.code == 'acc':
            continue
        new_op = swap_op(op)
        proc.memory[index] = new_op
        proc.reset()
        success = proc.run()
        if success:
            print(
                f"Solution is to change instruction on index {index}",
                f"from {op} to {new_op}",
            )
            print(f"Solution 2: {proc.ACC}")
            break
        else:  # Restore memory
            proc.memory[index] = op
Пример #8
0
def main():
    devices = sorted(list(read_input('input')))
    current = 0
    count = 0
    factors = []
    devices.append(devices[-1]+3)
    for device in devices:
        print(f"{current} -> {device}", end=" ")
        delta = device - current
        if delta == 1:
            count += 1
            print(f"[{delta}]")
        else:
            print(f"\u001b[1m\u001b[32m[{delta}]\u001b[0m count is {count}", end="|")
            print(f"count is {count} -> alternatives {alternative_paths(count)}")
            if count >= 2:
                factors.append(alternative_paths(count))
            count = 0
        current = device
    print(f"factors is {factors}")
    sol = functools.reduce(lambda a, b: a*b, factors)
    print(f"Solution is {sol}")
Пример #9
0
def test_read_input():
    assert list(loader.read_input("sample")) == [
        35,
        20,
        15,
        25,
        47,
        40,
        62,
        55,
        65,
        95,
        102,
        117,
        150,
        182,
        127,
        219,
        299,
        277,
        309,
        576,
    ]
Пример #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from loader import read_input
from answers import AnyAnswer

acc = 0
for responses in read_input('input'):
    acc += len(AnyAnswer(responses))

print(f"Solution 1: {acc}")
Пример #11
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import loader

karte = {}
for seat in loader.read_input("input"):
    karte[seat.seat_id] = seat

min_seat_id = min(karte.keys())
max_seat_id = max(karte.keys())
for i in range(min_seat_id+1, max_seat_id):
    if (i-1) in karte and i not in karte and (i+1) in karte:
        sol = i
        break

print(f"Solution 2 is {sol}")
Пример #12
0
def main():
    list(read_input("input"))
    shiny_gold = Bag.registry[('shiny', 'gold')]
    print(f"Solution 2: {shiny_gold.count()}")
Пример #13
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import loader

seats = list(loader.read_input("input"))
print("Solution 1 is", max([s.seat_id for s in seats]))
Пример #14
0
def main():
    result = 0
    for passport in read_input("input"):
        if is_full_passport(passport) and is_valid_passport(passport):
            result += 1
    print(f"Solution 2: {result}")
Пример #15
0
def main():
    devices = list(read_input('input'))
    stats = jolts_reduce(devices)
    assert len(stats) == 2
    sol = stats[1] * stats[3]
    print(f"Solution 1 is {sol}")
Пример #16
0
def main():
    result = 0
    for passport in read_input('input'):
        if is_full_passport(passport):
            result += 1
    print(f"Solution 1: {result}")
Пример #17
0
def test_loader():
    for bag in loader.read_input("sample"):
        print(bag)
Пример #18
0
def main():
    proc = Proc()
    proc.load_memory(read_input('input'))
    proc.run()
    print(f"Solution 1: {proc.ACC}")