Solved 2015/05 part 2
This commit is contained in:
parent
d2d97b442b
commit
0e83d8f589
12
2015/05/5.md
12
2015/05/5.md
@ -28,8 +28,6 @@ How many strings are nice?
|
|||||||
|
|
||||||
Your puzzle answer was `236`.
|
Your puzzle answer was `236`.
|
||||||
|
|
||||||
The first half of this puzzle is complete! It provides one gold star: \*
|
|
||||||
|
|
||||||
## \-\-- Part Two \-\-- {#part2}
|
## \-\-- Part Two \-\-- {#part2}
|
||||||
|
|
||||||
Realizing the error of his ways, Santa has switched to a better model of
|
Realizing the error of his ways, Santa has switched to a better model of
|
||||||
@ -60,8 +58,14 @@ For example:
|
|||||||
|
|
||||||
How many strings are nice under these new rules?
|
How many strings are nice under these new rules?
|
||||||
|
|
||||||
Answer:
|
Your puzzle answer was `51`.
|
||||||
|
|
||||||
Although it hasn\'t changed, you can still [get your puzzle
|
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.
|
||||||
|
|
||||||
|
If you still want to see it, you can [get your puzzle
|
||||||
input](5/input).
|
input](5/input).
|
||||||
|
|
||||||
|
@ -46,47 +46,16 @@ if part == 1:
|
|||||||
# #
|
# #
|
||||||
#########################################
|
#########################################
|
||||||
|
|
||||||
|
def find_non_overlapping_pairs(string):
|
||||||
|
pattern = r'(..).*?\1'
|
||||||
|
matches = re.findall(pattern, string)
|
||||||
|
return list(set(matches))
|
||||||
|
|
||||||
def isNaughty2(inst):
|
def isNaughty2(inst):
|
||||||
# bad_words = ['ab','cd','pq','xy']
|
|
||||||
|
|
||||||
# if any(w in inst for w in bad_words):
|
|
||||||
# return True
|
|
||||||
# if sum(inst.lower().count(v) for v in "aeiou") < 3:
|
|
||||||
# return True
|
|
||||||
# for i in range(0,len(inst)-1):
|
|
||||||
# if inst[i] == inst[i+1]:
|
|
||||||
# return False
|
|
||||||
# return True
|
|
||||||
|
|
||||||
pairs = []
|
|
||||||
for i in range(0,len(inst)-1):
|
|
||||||
tmp = inst[i]+inst[i+1]
|
|
||||||
pairs.append(tmp)
|
|
||||||
#print(inst)
|
|
||||||
#print(pairs)
|
|
||||||
n_pairs = []
|
|
||||||
sdx = 0
|
|
||||||
while sdx < len(pairs)-2:
|
|
||||||
#for sdx in range(0,len(pairs)-1):
|
|
||||||
if pairs[sdx] != pairs[sdx+1]:
|
|
||||||
n_pairs.append(pairs[sdx])
|
|
||||||
if pairs[sdx] == pairs[sdx+1] and pairs[sdx] == pairs[sdx+2]:
|
|
||||||
n_pairs.append(pairs[sdx])
|
|
||||||
n_pairs.append(pairs[sdx+2])
|
|
||||||
sdx+=1
|
|
||||||
#print(n_pairs)
|
|
||||||
|
|
||||||
opt = [item for item in set(pairs) if n_pairs.count(item) > 1]
|
|
||||||
|
|
||||||
|
|
||||||
#print(opt)
|
|
||||||
if len(opt) > 0:
|
|
||||||
for i in range(0,len(inst)-2):
|
for i in range(0,len(inst)-2):
|
||||||
if inst[i] == inst[i+2]:
|
if inst[i] == inst[i+2] and len(find_non_overlapping_pairs(inst)) > 0:
|
||||||
print(inst[i], inst[i+1],inst[i+2])
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
if part == 2:
|
if part == 2:
|
||||||
instructions = []
|
instructions = []
|
||||||
@ -98,7 +67,5 @@ if part == 2:
|
|||||||
|
|
||||||
for inst in instructions:
|
for inst in instructions:
|
||||||
if not isNaughty2(inst):
|
if not isNaughty2(inst):
|
||||||
#print('Nice')
|
|
||||||
count += 1
|
count += 1
|
||||||
#input()
|
|
||||||
print(count)
|
print(count)
|
||||||
|
@ -1,2 +1,6 @@
|
|||||||
aaaa
|
aaaa
|
||||||
|
aaa
|
||||||
aaabcb
|
aaabcb
|
||||||
|
xxyxyxx
|
||||||
|
xxxyyx
|
||||||
|
hejejk
|
||||||
|
Loading…
Reference in New Issue
Block a user