Last active
December 12, 2022 13:39
-
-
Save rtt/ba82379810bb21d3dbcaee77798a0011 to your computer and use it in GitHub Desktop.
Revisions
-
rtt revised this gist
Dec 12, 2022 . No changes.There are no files selected for viewing
-
rtt revised this gist
Dec 12, 2022 . 1 changed file with 5 additions and 13 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,15 @@ def partN(input_data, step): for i, window in enumerate( [input_data[i:i + step] for i in range(len(input_data) - step)]): if len(set(window)) == step: return i + step if __name__ == '__main__': with open('./input.txt') as f: inp = f.read().strip() print(partN(inp, 4)) print(partN(inp, 14)) -
rtt created this gist
Dec 12, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ def partN(input_data, step): i = 0 while True: chunk = input_data[i:step + i] if not len(chunk) == step: # reached end break if len(set(chunk)) == step: return i + step i += 1 if __name__ == '__main__': with open('./input.txt') as f: inp = f.read().strip() print(partN(inp, 4)) print(partN(inp, 14))