Пример #1
0
    def test_parse_out_of_order(self):
        contents = """[1518-11-01 00:00] Guard #10 begins shift
[1518-11-01 00:05] falls asleep
[1518-11-01 00:30] falls asleep
[1518-11-01 23:58] Guard #99 begins shift
[1518-11-03 00:05] Guard #10 begins shift
[1518-11-03 00:24] falls asleep
[1518-11-02 00:40] falls asleep
[1518-11-02 00:50] wakes up
[1518-11-03 00:29] wakes up
[1518-11-01 00:25] wakes up
[1518-11-01 00:55] wakes up
[1518-11-05 00:03] Guard #99 begins shift
[1518-11-04 00:02] Guard #99 begins shift
[1518-11-04 00:36] falls asleep
[1518-11-04 00:46] wakes up
[1518-11-05 00:45] falls asleep
[1518-11-05 00:55] wakes up"""
        expected = {
            (10, 11, 1, 5): 20,
            (10, 11, 1, 30): 25,
            (99, 11, 2, 40): 10,
            (10, 11, 3, 24): 5,
            (99, 11, 4, 36): 10,
            (99, 11, 5, 45): 10
        }
        self.assertEqual(expected, puzzle.parse(contents.split('\n')))
Пример #2
0
    def test_parse(self):
        words = """#1 @ 1,3: 4x4
#2 @ 3,1: 4x4
#3 @ 5,5: 2x2""".split('\n')
        data = puzzle.parse(words)
        self.assertEqual(data['#1'], {
            'id': '#1',
            'x': 1,
            'y': 3,
            'width': 4,
            'height': 4
        })
        self.assertEqual(data['#2'], {
            'id': '#2',
            'x': 3,
            'y': 1,
            'width': 4,
            'height': 4
        })
        self.assertEqual(data['#3'], {
            'id': '#3',
            'x': 5,
            'y': 5,
            'width': 2,
            'height': 2
        })
Пример #3
0
 def test_solve(self):
     lines = """abcdef
     bababc
     abbcde
     abcccd
     aabcdd
     abcdee
     ababab"""
     data = puzzle.parse(lines.split())
     answer = puzzle.solve(data)
     self.assertEqual(12, answer)
Пример #4
0
    def test_solve(self):
        lines = """abcde
        abcef
fghij
klmno
pqrst
fguij
axcye
wvxyz"""
        data = puzzle.parse(lines.split())
        answer = puzzle.solve(data)
        self.assertEqual("fgij", answer)
Пример #5
0
 def test_parse(self):
     expected = {
         "metadata": [1, 1, 2],
         "children": [{
             "metadata": [10, 11, 12],
             "children": []
         }, {
             "metadata": [2],
             "children": [{
                 "metadata": [99],
                 "children": []
             }]
         }]
     }
     data = "2 3 0 3 10 11 12 1 1 0 1 99 2 1 1 2"
     self.assertEqual(expected, puzzle.parse(data))
Пример #6
0
    def test_parse(self):
        input = """Step C must be finished before step A can begin.
Step C must be finished before step F can begin.
Step A must be finished before step B can begin.
Step A must be finished before step D can begin.
Step B must be finished before step E can begin.
Step D must be finished before step E can begin.
Step F must be finished before step E can begin."""
        expected = {
            "A": set(["C"]),
            "B": set(["A"]),
            "C": set(),
            "D": set(["A"]),
            "E": set(["B", "D", "F"]),
            "F": set(["C"])
        }
        self.assertEqual(expected, puzzle.parse(input.split("\n")))
Пример #7
0
    def test_parse(self):
        contents = """[1518-11-01 00:00] Guard #10 begins shift
[1518-11-01 00:05] falls asleep
[1518-11-01 00:08] wakes up
[1518-11-01 00:30] falls asleep
[1518-11-01 00:35] wakes up
[1518-11-01 23:58] Guard #99 begins shift
[1518-11-02 00:40] falls asleep
[1518-11-02 00:42] wakes up
[1518-11-03 00:05] Guard #10 begins shift
[1518-11-03 00:34] falls asleep
[1518-11-03 00:35] wakes up"""
        # instead of (guardid, month, day, minute), I only ever use minute and guardid
        # So what if I parse into guard/minute pairs, for each minute asleep?
        expected = [(10, 5), (10, 6), (10, 7), (10, 30), (10, 31), (10, 32),
                    (10, 33), (10, 34), (99, 40), (99, 41), (10, 34)]
        self.assertEqual(expected, puzzle.parse(contents.split('\n')))
Пример #8
0
    def test_find_height(self):
        data = """position=< 9,  1> velocity=< 0,  2>
position=< 7,  0> velocity=<-1,  0>
position=< 3, -2> velocity=<-1,  1>
position=< 6, 10> velocity=<-2, -1>
position=< 2, -4> velocity=< 2,  2>
position=<-6, 10> velocity=< 2, -2>
position=< 1,  8> velocity=< 1, -1>
position=< 1,  7> velocity=< 1,  0>
position=<-3, 11> velocity=< 1, -2>
position=< 7,  6> velocity=<-1, -1>
position=<-2,  3> velocity=< 1,  0>
position=<-4,  3> velocity=< 2,  0>
position=<10, -3> velocity=<-1,  1>
position=< 5, 11> velocity=< 1, -2>
position=< 4,  7> velocity=< 0, -1>
position=< 8, -2> velocity=< 0,  1>
position=<15,  0> velocity=<-2,  0>
position=< 1,  6> velocity=< 1,  0>
position=< 8,  9> velocity=< 0, -1>
position=< 3,  3> velocity=<-1,  1>
position=< 0,  5> velocity=< 0, -1>
position=<-2,  2> velocity=< 2,  0>
position=< 5, -2> velocity=< 1,  2>
position=< 1,  4> velocity=< 2,  1>
position=<-2,  7> velocity=< 2, -2>
position=< 3,  6> velocity=<-1, -1>
position=< 5,  0> velocity=< 1,  0>
position=<-6,  0> velocity=< 2,  0>
position=< 5,  9> velocity=< 1, -2>
position=<14,  7> velocity=<-2,  0>
position=<-3,  6> velocity=< 2, -1>"""
        c = puzzle.parse(data.split("\n"))
        self.assertEqual(15, puzzle.find_height(c, 0))
        self.assertEqual(11, puzzle.find_height(c, 1))
        self.assertEqual(9, puzzle.find_height(c, 2))
        self.assertEqual(7, puzzle.find_height(c, 3))
        self.assertEqual(10, puzzle.find_height(c, 4))
Пример #9
0
 def test_pass(self):
     data = puzzle.parse(open("data.txt").readlines())
     answer = puzzle.solve(data)
     self.assertEqual(0, answer)
 def test_pass(self):
     masses = puzzle.parse(file("puzzleInput.txt").readlines())
     answer = puzzle.solve(masses)
     self.assertEqual(3348909, answer)
Пример #11
0
 def test_basic_parse(self):
   data = puzzle.parse('''12
   14
   15'''.split())
   self.assertEqual([12, 14, 15], data)
Пример #12
0
 def test_pass(self):
   f = open("input.txt", "r")
   data = puzzle.parse(f.readlines())
   answer = puzzle.solve(data)
   self.assertEqual(0, answer)
Пример #13
0
 def test_pass(self):
     data = puzzle.parse(file("input.txt").readlines())
     answer = puzzle.traverse(data)
     self.assertEqual(0, "".join(answer))
Пример #14
0
 def test_pass(self):
     data = puzzle.parse(file("input.txt").readlines())
     answer = puzzle.solve(data)
     self.assertEqual(0, answer)
Пример #15
0
import puzzle

data = puzzle.parse(file("input.txt").readlines())

first_answer = puzzle.solve_first(data)
print("FIRST PART ANSWER IS: ", first_answer)

second_answer = puzzle.solve_second(data)
print("SECOND PART ANSWER IS: ", second_answer)
Пример #16
0
    def test_render(self):
        data = """position=< 9,  1> velocity=< 0,  2>
position=< 7,  0> velocity=<-1,  0>
position=< 3, -2> velocity=<-1,  1>
position=< 6, 10> velocity=<-2, -1>
position=< 2, -4> velocity=< 2,  2>
position=<-6, 10> velocity=< 2, -2>
position=< 1,  8> velocity=< 1, -1>
position=< 1,  7> velocity=< 1,  0>
position=<-3, 11> velocity=< 1, -2>
position=< 7,  6> velocity=<-1, -1>
position=<-2,  3> velocity=< 1,  0>
position=<-4,  3> velocity=< 2,  0>
position=<10, -3> velocity=<-1,  1>
position=< 5, 11> velocity=< 1, -2>
position=< 4,  7> velocity=< 0, -1>
position=< 8, -2> velocity=< 0,  1>
position=<15,  0> velocity=<-2,  0>
position=< 1,  6> velocity=< 1,  0>
position=< 8,  9> velocity=< 0, -1>
position=< 3,  3> velocity=<-1,  1>
position=< 0,  5> velocity=< 0, -1>
position=<-2,  2> velocity=< 2,  0>
position=< 5, -2> velocity=< 1,  2>
position=< 1,  4> velocity=< 2,  1>
position=<-2,  7> velocity=< 2, -2>
position=< 3,  6> velocity=<-1, -1>
position=< 5,  0> velocity=< 1,  0>
position=<-6,  0> velocity=< 2,  0>
position=< 5,  9> velocity=< 1, -2>
position=<14,  7> velocity=<-2,  0>
position=<-3,  6> velocity=< 2, -1>"""
        coords = puzzle.parse(data.split("\n"))
        self.assertEqual((9, 1, 0, 2), coords[0])
        self.assertEqual((7, 0, -1, 0), coords[1])

        expected = """........#.............
................#.....
.........#.#..#.......
......................
#..........#.#.......#
...............#......
....#.................
..#.#....#............
.......#..............
......#...............
...#...#.#...#........
....#..#..#.........#.
.......#..............
...........#..#.......
#...........#.........
...#.......#..........
"""
        self.assertMultiLineEqual(expected, puzzle.render(coords, 0))

        expected = """#...#..###
#...#...#.
#...#...#.
#####...#.
#...#...#.
#...#...#.
#...#...#.
#...#..###
"""
        self.assertMultiLineEqual(expected, puzzle.render(coords, 3))
Пример #17
0
 def test_parse(self):
     self.assertEqual([(9, 1, 0, 2)],
                      puzzle.parse(["position=< 9,  1> velocity=< 0,  2>"]))
Пример #18
0
 def test_pass(self):
     data = puzzle.parse(file("input.txt").readlines())
     answer, t = puzzle.traverse(data, 5, 60)
     self.assertEqual(0, t)
 def test_basic_parse(self):
     masses = puzzle.parse('''12
     14
     1969
     100756'''.split())
     self.assertEqual([12, 14, 1969, 100756], masses)
Пример #20
0
 def test_part_two(self):
     file = open("input.txt", "r")
     data = puzzle.parse(file.readlines())
     answer = puzzle.solvePartTwo(data)
     self.assertEqual(5230169, answer)
     file.close()
Пример #21
0
 def test_part_one(self):
     file = open("input.txt", "r")
     data = puzzle.parse(file.readlines())
     answer = puzzle.solvePartOne(data)
     self.assertEqual(3488702, answer)
     file.close()
Пример #22
0
    def test_part1(self):
        with open("input.txt") as inTxt:
            data = puzzle.parse(inTxt.readlines())

        answer = puzzle.solve1(data)
        self.assertEqual(0, answer)
Пример #23
0
 def test_part_one(self):
     f = open("test_input.txt", "r")
     data = puzzle.parse(f.read())
     answer = puzzle.solvePartOne(data)
     self.assertEqual(30, answer)
     f.close()
Пример #24
0
 def test_basic_parse(self):
     data = puzzle.parse('''+1
     +13
     +2'''.split())
     self.assertEqual([1, 13, 2], data)
Пример #25
0
 def test_pass(self):
     data = puzzle.parse("data.txt")
     answer = puzzle.solve(data)
     self.assertEqual(0, answer)