Example #1
0
from aocd.get import get_day_and_year
from aocd.models import Puzzle
from collections import defaultdict, Counter

day, year = get_day_and_year()
p = Puzzle(year, day)
print("Day", day, ":", p.title)
data = p.input_data
print(data)

data = [line for line in data.splitlines()]
print(data)


def part1():
    count = 0
    for i in range(len(data)):
        if int(data[i]) > int(data[i - 1]):
            count = count + 1

    print(count)


def part2():
    count = 0
    for i in range(len(data) - 2):
        if int(data[i]) + int(data[i + 1]) + int(data[i + 2]) > int(data[i - 1]) + int(data[i]) + int(data[i + 1]):
            count += 1

    print(count)
Example #2
0
 def __init__(self):
     day, year = get_day_and_year()
     super().__init__(year, day)
def test_get_day_and_year_fail_no_filename_on_stack():
    with pytest.raises(AocdError("Failed introspection of filename")):
        get_day_and_year()
def test_day_is_invalid(mocker):
    fake_stack = [("~/2016/q27.py", )]
    mocker.patch("aocd.get.traceback.extract_stack", return_value=fake_stack)
    with pytest.raises(AocdError("Failed introspection of day")):
        get_day_and_year()
def test_year_is_ambiguous(mocker):
    fake_stack = [("~/2016/2017_q01.py", )]
    mocker.patch("aocd.get.traceback.extract_stack", return_value=fake_stack)
    with pytest.raises(AocdError("Failed introspection of year")):
        get_day_and_year()
def test_get_day_and_year_from_stack(mocker):
    fake_stack = [("xmas_problem_2016_25b_dawg.py", )]
    mocker.patch("aocd.get.traceback.extract_stack", return_value=fake_stack)
    day, year = get_day_and_year()
    assert day == 25
    assert year == 2016