Example #1
0
def test_n_real():
    names = '''aaaaa-bbb-z-y-x-123[abxyz]
a-b-c-d-e-f-g-h-987[abcde]
not-a-real-room-404[oarel]
totally-real-room-200[decoy]'''
    names = names.split('\n')
    rooms = [day4.Room(name) for name in names]
    n_real = sum([1 for r in rooms if r.is_real])
    assert n_real == 3
Example #2
0
         for r in rawrooms)


def flipneg(iter_):
    return ((-t[1], t[0]) for t in iter_)


def rotate(c, n):
    return chr(96 + ((ord(c) - 96 + (n % 26)) % 26))


def rotateword(word, n):
    return ''.join(map(lambda c: rotate(c, n) if c != '-' else ' ', word))


i = 0
for name, roomid, cksum in rooms:
    c = Counter(name.replace('-', ''))
    v = ''.join(x[1] for x in sorted(flipneg(c.most_common())))[:5]
    string = name + '-' + roomid + '[' + cksum + ']'
    room = day4.Room(name + '-' + roomid + '[' + cksum + ']')
    is_real = v == cksum
    if is_real:
        i += int(roomid)
    if not is_real == room.is_real:
        print(string, 'Mine:', room.is_real, 'Reference:', is_real)
        assert not room.is_real  # check mine is only producing false negatives.

    # if 'pole' in rotateword(name, int(roomid)):
    #     print("Part 2: {}".format(roomid))
print("Part 1: {}".format(i))
Example #3
0
 def test_Day4Example(self):
     room = day4.Room('aaaaa-bbb-z-y-x-123[abxyz]')
     self.assertTrue(room.validate())
Example #4
0
 def test_Day4_2Example(self):
     room = day4.Room('qzmt-zixmtkozy-ivhz-343[abcde]')
     self.assertEqual(room.translate(), 'very encrypted name')
Example #5
0
 def test_Day4Example_4(self):
     room = day4.Room('totally-real-room-200[decoy]')
     self.assertFalse(room.validate())
Example #6
0
 def test_Day4Example_3(self):
     room = day4.Room('not-a-real-room-404[oarel]')
     self.assertTrue(room.validate())
Example #7
0
 def test_Day4Example_2(self):
     room = day4.Room('a-b-c-d-e-f-g-h-987[abcde]')
     self.assertTrue(room.validate())
Example #8
0
def test_real6():
    data = 'rgllk-qss-etubbuzs-430[sblue]'
    assert day4.Room(data).is_real
Example #9
0
def test_real1():
    # is a real room because the most common letters are a (5), b (3), and then a tie
    # between x, y, and z, which are listed alphabetically.
    data = 'aaaaa-bbb-z-y-x-123[abxyz]'
    assert day4.Room(data).is_real
Example #10
0
def test_real6():
    data = 'totalf-[taflo]'
    assert day4.Room(data).is_real
Example #11
0
def test_real4():
    data = 'totally-real-room-200[decoy]'
    assert not day4.Room(data).is_real
Example #12
0
def test_real3():
    # not-a-real-room-404[oarel] is a real room.
    data = 'not-a-real-room-404[oarel]'
    assert day4.Room(data).is_real
Example #13
0
def test_real2():
    # a-b-c-d-e-f-g-h-987[abcde] is a real room because although the letters are all tied (1 of each),
    # the first five are listed alphabetically.
    data = 'a-b-c-d-e-f-g-h-987[abcde]'
    assert day4.Room(data).is_real