from aoc2020.day11 import solution from aoc2020.util import get_input input_data = get_input("tests/testinput.day11") def test_solve_part1(): expected = 37 actual = solution.solve_part1(input_data) assert expected == actual def test_count_adjacent_occupied(): input_data = get_input("tests/testinput.day11.2") expected = 8 actual = solution.count_adjacent_occupied(input_data, 4, 3) assert expected == actual def test_count_adjacent_occupied_2(): input_data = get_input("tests/testinput.day11.3") expected = 0 actual = solution.count_adjacent_occupied(input_data, 3, 3) assert expected == actual # def test_solve_part2(): # expected = 26 # actual = solution.solve_part2(input_data) # assert expected == actual
def test_count_adjacent_occupied_2(): input_data = get_input("tests/testinput.day11.3") expected = 0 actual = solution.count_adjacent_occupied(input_data, 3, 3) assert expected == actual
def slide_down(slope, forest): """ move down the hill and count the number of trees hit """ width = len(forest[0]) height = len(forest) trees_hit = 0 position = (0, 0) while position[1] < height - 1: position = traverse(position, slope, width) if forest[position[1]][position[0]] == "#": trees_hit += 1 return trees_hit def solve_part1(forest): return slide_down((3, 1), forest) def solve_part2(forest): hit = slide_down((1, 1), forest) hit *= slide_down((3, 1), forest) hit *= slide_down((5, 1), forest) hit *= slide_down((7, 1), forest) hit *= slide_down((1, 2), forest) return hit if __name__ == "__main__": # pragma: no cover array = get_input("aoc2020/day03/input") print(solve_part1(array)) print(solve_part2(array))
from aoc2020.day14 import solution from aoc2020.util import get_input input_data = get_input("tests/testinput.day14") input_data_2 = get_input("tests/testinput.day14.2") def test_int2binstr(): value = 64 expected = "000000000000000000000000000001000000" actual = solution.int2binstr(value) assert expected == actual def test_apply_mask_part1(): mask = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX1XXXX0X" value = 11 expected = 73 actual = solution.apply_mask_part1(value, mask) assert expected == actual def test_solve_part1(): expected = 165 actual = solution.solve_part1(input_data) assert expected == actual # def test_solve_part2(): # expected = 208 # actual = solution.solve_part2(input_data_2)
def rotate(self, degrees): self.degree += degrees self.degree %= 360 self.direction = compass[self.degree] def solve_part1(entries): ship = Ship() for instruction in entries: operation = instruction[0] operand = int(instruction[1:]) if operation == "F": ship.forward(operand) elif operation == "R": ship.rotate(operand) elif operation == "L": ship.rotate(-operand) else: ship.translate(operation, operand) return abs(ship.x) + abs(ship.y) def solve_part2(entries): return if __name__ == "__main__": # pragma: no cover entries = get_input("aoc2020/day12/input") print(solve_part1(entries)) print(solve_part2(entries))
if children is None: return for child in children: count, name = child.split(" ", 1) build_part2_tree(Node(name, parent=node, count=int(count)), all_bags) def my_traversal(node): if not node.children: return node.count else: result = 0 for children in node.children: result += my_traversal(children) result *= node.count result += node.count return result def solve_part2(entries): all_bags = collect_bags(entries) shiny_gold_tree = Node("shiny gold", count=1) build_part2_tree(shiny_gold_tree, all_bags) return my_traversal(shiny_gold_tree) - 1 if __name__ == "__main__": # pragma: no cover entries = get_input("aoc2020/day07/input") print(solve_part1(entries)) print(solve_part2(entries))
from aoc2020.util import get_input def solve_part1(entries): return def solve_part2(entries): return if __name__ == "__main__": # pragma: no cover entries = get_input("aoc2020/CHANGEME/input") print(solve_part1(entries)) print(solve_part2(entries))
from aoc2020.day08 import solution from aoc2020.util import get_input input_data = get_input("tests/testinput.day08") def test_solve_part1(): expected = 5 actual = solution.solve_part1(input_data) assert expected == actual def test_solve_part2(): expected = 8 actual = solution.solve_part2(input_data) assert expected == actual
def test_get_input(): expected = ["1", "2", "3", "4"] actual = util.get_input(input_file) assert actual == expected