@@ 0,0 1,29 @@
+#! /usr/bin/env python3
+# vim:fenc=utf-8
+#
+# Copyright © 2022 Adrian Perez de Castro <aperez@igalia.com>
+#
+# Distributed under terms of the MIT license.
+
+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
+
+class SelfTest(unittest.TestCase):
+ def testDoit(self):
+ self.assertEqual(7, doit("mjqjpqmgbljsphdztnvjfqwrcgsmlb"))
+ self.assertEqual(5, doit("bvwbjplbgvbhsrlpgdmjqwftvncz"))
+ self.assertEqual(6, doit("nppdvjthqldpwncqszvftbrmjlhg"))
+ self.assertEqual(10, doit("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"))
+ self.assertEqual(11, doit("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw"))
+
+if __name__ == "__main__":
+ from sys import argv
+ if len(argv) == 1:
+ unittest.main()
+ else:
+ [print(doit(data)) for data in argv[1:]]