diff --git a/2015/day 5/P2/string.py b/2015/day 5/P2/string.py index 4698d3e..9f371d6 100644 --- a/2015/day 5/P2/string.py +++ b/2015/day 5/P2/string.py @@ -1,14 +1,17 @@ strings = open("input.txt").read().split("\n")[:-1] nice = 0 for i in strings: + pair = False double = False for j in range(len(i)-1): - if i.count(f"{i[j]}{i[j+1]}") >= 2 and f"{i[j]}{i[j]}{i[j]}" not in i: - double = True - break - for j in range(len(i)): - f2 = i.find(i[j], j+1) - if f2-j == 2 and double: + if not pair: + if i.count(f"{i[j]}{i[j+1]}") >= 2 and f"{i[j]}{i[j]}{i[j]}" not in i: + pair = True + if not double: + f2 = i.find(i[j], j+1) + if f2-j == 2: + double = True + if pair and double: nice+=1 break print(nice)