From 067decada0d74b2ef3e9e6fa3da5d91c2a3d7b2a Mon Sep 17 00:00:00 2001 From: setop Date: Sun, 3 Dec 2023 02:02:18 +0100 Subject: [PATCH] boring, get cheat online --- d11/run.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 d11/run.py diff --git a/d11/run.py b/d11/run.py new file mode 100644 index 0000000..d5741dc --- /dev/null +++ b/d11/run.py @@ -0,0 +1,40 @@ +import sys + +letters = 'abcdefghijklmnopqrstuvwxyz' +doubles = [c+c for c in letters] +straights = [a+b+c for a,b,c in zip(letters, letters[1:], letters[2:])] +next_letter = {c1: c2 for c1, c2 in zip(letters, letters[1:]+'a')} + + +def is_valid(s): + # cannot contain i, o, or l + if 'i' in s or 'o' in s or 'l' in s: + return False + # must include two different pairs of letters + if sum([d in s for d in doubles]) < 2: + return False + # must include a straight of length 3 or greater + if not any([d in s for d in straights]): + return False + return True + + +def next_password(s): + s = s[:-1] + next_letter[s[-1]] # increment the last letter + for i in range(-1, -8, -1): + if s[i] == 'a': # increment n-1 letter is n letter changed to 'a' + s = s[:i-1] + next_letter[s[i-1]] + s[i:] + else: + break + return s + + +password = sys.argv[1] +while not is_valid(password): + password = next_password(password) +print(password) + +password = next_password(password) +while not is_valid(password): + password = next_password(password) +print(password)