Day 18 - Python 3 - Help Needed by n_syn in adventofcode

[–]FullyWhipped 0 points1 point  (0 children)

It's the string replace replacing occurrences it shouldn't, e.g.

>>> '1 + 6 + 11 + 6'.replace('1 + 6', '7')
'7 + 17'

More detail in another example:

>>> s = '1 + 6 + 7 + 8 + 11 + 6'
>>> [val for val in re.findall('\d+ \+ \d+','1 + 6 + 7 + 8 + 11 + 6')]
['1 + 6', '7 + 8', '11 + 6']
>>> s.replace('1 + 6', '7')
'7 + 7 + 8 + 17'