#!/bin/python3 import sys,time,re from pprint import pprint sys.path.insert(0, '../../') from fred import list2int,get_re,nprint,lprint,loadFile start_time = time.time() input_f = 'test' part = 1 ######################################### # # # 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'] def findpairs(text): pattern = r"([a-zA-Z])\1" matches = [] i = 0 while i < len(text): match = re.search(pattern, text[i:]) if match: matches.append(match.group(0)) i += match.end(0) else: break return matches 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 len(findpairs(''.join(password))) <= 1: return False return valid instructions = loadFile(input_f) for i in instructions: i = list(i) print(i) if validate(i): input() #print(instructions) ######################################### # # # Part 2 # # # ######################################### if part == 2: exit() print("--- %s seconds ---" % (time.time() - start_time))