From 5b4728200ff1c4e10f5ce9ac200a1332d947a2b1 Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Mon, 9 Dec 2024 15:22:12 +0100 Subject: [PATCH] Solved 2015/11 P1+P2 --- 2015/11/11.md | 18 +++++++++++++-- 2015/11/input2 | 1 + 2015/11/solution.py | 54 ++++++++++++++++++++++++++++++--------------- 3 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 2015/11/input2 diff --git a/2015/11/11.md b/2015/11/11.md index d89df80..b33a029 100644 --- a/2015/11/11.md +++ b/2015/11/11.md @@ -43,7 +43,21 @@ For example: Given Santa\'s current password (your puzzle input), what should his *next password* be? -Your puzzle input is `hxbxwxba`{.puzzle-input}. +Your puzzle answer was `hxbxxyzz`. -Answer: +## \-\-- Part Two \-\-- {#part2} + +Santa\'s password [expired +again]{title="The corporate policy says your password expires after 12 seconds. For security."}. +What\'s the next one? + +Your puzzle answer was `hxcaabcc`. + +Both parts of this puzzle are complete! They provide two gold stars: +\*\* + +At this point, you should [return to your Advent calendar](/2015) and +try another puzzle. + +Your puzzle input was `hxbxwxba`{.puzzle-input}. diff --git a/2015/11/input2 b/2015/11/input2 new file mode 100644 index 0000000..c0ccdcb --- /dev/null +++ b/2015/11/input2 @@ -0,0 +1 @@ +hxbxxyzz diff --git a/2015/11/solution.py b/2015/11/solution.py index 2124097..427bd38 100644 --- a/2015/11/solution.py +++ b/2015/11/solution.py @@ -1,11 +1,11 @@ #!/bin/python3 -import sys,time,re +import sys,time,re,string from pprint import pprint sys.path.insert(0, '../../') from fred import list2int,get_re,nprint,lprint,loadFile start_time = time.time() -input_f = 'test' +input_f = 'input' part = 1 ######################################### @@ -15,8 +15,8 @@ part = 1 ######################################### if part == 1: - letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] - + letters = string.ascii_lowercase + def findpairs(text): pattern = r"([a-zA-Z])\1" matches = [] @@ -31,29 +31,47 @@ if part == 1: break return matches + def find3chars(text): + pattern = r"abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz" + matches = re.findall(pattern, text) + #print(matches) + if len(matches) > 0: + return True + else: + return False + def validate(password:list): - valid = False for i in ['l','i','o']: if i in password: return False - for i in range(0,len(password)-2): - idx = letters.index(password[i]) - if password[i+1] == letters[idx+1] and password[i+2] == letters[idx+2]: - valid = True - #print(password[i],password[i+1],password[i+2]) + if not find3chars(''.join(password)): + return False if len(findpairs(''.join(password))) <= 1: return False - return valid + return True instructions = loadFile(input_f) - for i in instructions: - i = list(i) - print(i) - if validate(i): - - input() - #print(instructions) + for inst in instructions: + print('Start',inst) + count = 0 + current_word = list(inst) + while True: + new_word = "".join(current_word) + + if validate(new_word): + print("Word found for Part",count+1,":",new_word) + count += 1 + if count == 2: + break + + for i in range(len(current_word) - 1, -1, -1): + current_letter_index = letters.index(current_word[i]) + + if current_letter_index < len(letters) - 1: + current_word[i] = letters[current_letter_index + 1] + current_word[i + 1:] = 'a' * (len(current_word) - i - 1) + break #########################################