~aperezdc/aoc2022

ce7b15e810a94a2a52f219102450af85d1b3ccfc — Adrian Perez de Castro 2 years ago 63084cd
Day 6, second part
1 files changed, 7 insertions(+), 6 deletions(-)

M day06/day06.py
M day06/day06.py => day06/day06.py +7 -6
@@ 7,11 7,11 @@

import unittest

def doit(data):
    assert len(data) >= 4
    for i in range(len(data) - 4):
        if len(frozenset(data[i:i+4])) == 4:
            return i + 4
def doit(data, n=4):
    assert len(data) >= n
    for i in range(len(data) - n):
        if len(frozenset(data[i:i+n])) == n:
            return i + n

class SelfTest(unittest.TestCase):
    def testDoit(self):


@@ 26,4 26,5 @@ if __name__ == "__main__":
    if len(argv) == 1:
        unittest.main()
    else:
        [print(doit(data)) for data in argv[1:]]
        [print("Part 1:", doit(data, n=4)) for data in argv[1:]]
        [print("Part 2:", doit(data, n=14)) for data in argv[1:]]