Skip to content

Instantly share code, notes, and snippets.

@themistoklik
Last active December 21, 2018 17:00
Show Gist options
  • Save themistoklik/3d20bdddfb9044d4e206cd2e091cd45f to your computer and use it in GitHub Desktop.
Save themistoklik/3d20bdddfb9044d4e206cd2e091cd45f to your computer and use it in GitHub Desktop.
aoc18 day 5 both parts, naive
def react(s):
stack = [s[0]]
def push(letter,stack):
if stack and abs(ord(stack[-1])-ord(letter)) == 32:
stack.pop()
else:
stack.append(letter)
for letter in s[1:]:
push(letter,stack)
return ''.join(stack)
reacted=react(s)
alphabet='qazwsxedcrfvtgbyhnujmiklop'
lens=[]
for letter in alphabet:
lens.append(len(
react(
reacted
.replace(letter,'')
.replace(str.upper(letter),''))))
#ans 2 is min(lens)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment