#!/usr/bin/python def increment(string): last = string[-1] if last == "z": return increment(string[0:-1]) + "a" else: return string[0:-1] + chr(ord(last) + 1) def solve_part1(old): valid = False while not valid: new = increment(old) # Rule 2: no "i", "o" or "l" # Cheap to check and likely to fail, so we do this first rule2 = True for c in ["i", "o", "l"]: if new.count(c) > 0: rule2 = False break if not rule2: old = new continue # Rule 1: one increasing straight of three letters rule1 = False ords = [ord(c) for c in new] for i in range(len(new) - 2): if ords[i + 1] == ords[i] + 1 and ords[i + 2] == ords[i] + 2: rule1 = True break # Rule 3: two different pair of letters rule3 = False count = 0 taken = [] for i in range(len(new) - 1): if new[i] not in taken and new[i] == new[i + 1]: count += 1 taken.append(new[i]) if count >= 2: rule3 = True old = new valid = rule1 and rule3 return new def solve_part2(old): return solve_part1(solve_part1(old)) def main(): # My personal input password passwd = "vzbxkghb" print("Part 1 solution:", solve_part1(passwd)) # "vzbxxyzz" for me print("Part 2 solution:", solve_part2(passwd)) # "vzcaabcc" for me if __name__ == "__main__": main()