Esempio n. 1
0
    def test_part_one(self):
        "Test part one example of Detective object"

        # 1. Create Detective object from text
        myobj = detective.Detective(text=aoc_16.from_text(PART_ONE_TEXT))

        # 2. Check the part one result
        self.assertEqual(myobj.part_one(verbose=False), PART_ONE_RESULT)
Esempio n. 2
0
    def test_part_two(self):
        "Test part two example of Detective object"

        # 1. Create Detective object from text
        myobj = detective.Detective(part2=True,
                                    text=aoc_16.from_text(PART_TWO_TEXT))

        # 2. Check the part two result
        self.assertEqual(myobj.part_two(verbose=False), PART_TWO_RESULT)
Esempio n. 3
0
    def test_text_init(self):
        "Test the Detective object creation from text"

        # 1. Create Detective object from text
        myobj = detective.Detective(text=aoc_16.from_text(EXAMPLE_TEXT))

        # 2. Make sure it has the expected values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(len(myobj.text), 9)
        self.assertEqual(len(myobj.csi.text), 10)
        self.assertEqual(len(myobj.aunts), 9)
Esempio n. 4
0
    def test_empty_init(self):
        "Test the default Detective creation"

        # 1. Create default Detective object
        myobj = detective.Detective()

        # 2. Make sure it has the default values
        self.assertEqual(myobj.part2, False)
        self.assertEqual(myobj.text, None)
        self.assertEqual(len(myobj.csi.text), 10)
        self.assertEqual(len(myobj.aunts), 0)
Esempio n. 5
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the puzzle solver
    solver = detective.Detective(part2=True, text=input_lines)

    # 2. Determine the solution for part two
    solution = solver.part_two(verbose=args.verbose, limit=args.limit)
    if solution is None:
        print("There is no solution")
    else:
        print("The solution for part two is %s" % (solution))

    # 3. Return result
    return solution is not None
Esempio n. 6
0
randomdata = [randint(0, 1) for i in range(WIDTH * HEIGHT)]

original = life.Life(WIDTH, HEIGHT, randomdata)
saved = original.clone()

print "Original:"
print original
print

original.tick()
print "Given:"
print original
print

gumshoe = detective.Detective(original)
print "Initial confidence:"
print gumshoe
print

print "Guessing..."
last_span = 0
confidence = 0.0
while gumshoe.span > 1:
    gumshoe.guess(confidence)
    confidence = (confidence + 0.5) / 2.0
    span = gumshoe.span
    if span != last_span:
        print "\t%i" % span
    last_span = span