Skip to content

Instantly share code, notes, and snippets.

@akent
Last active December 5, 2018 16:29
Show Gist options
  • Save akent/264aade97bdb12b019b5422717265a70 to your computer and use it in GitHub Desktop.
Save akent/264aade97bdb12b019b5422717265a70 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import string
from collections import deque
f = open("input.txt", "r")
data = deque()
for char in f.read():
if char != '\n':
data.append(char)
def process(inp):
outp = deque()
lastC = inp.popleft()
outp.append(lastC)
while True:
# print ("%s-%s" % ("".join(outp), "".join(inp)))
if not inp:
break
c = inp.popleft()
if (lastC.lower() == c.lower() and ((lastC.isupper() and c.islower()) or (lastC.islower() and c.isupper()))):
# print ('%s and %s react' % (lastC, c))
# print ("%s-%s" % ("".join(outp), "".join(inp))))
if outp:
lastC = outp.pop()
if outp:
# rewind
inp.appendleft(outp.pop())
else:
lastC = c
outp.append(c)
return outp
def removeLetter(inp, letter):
outp = deque()
inp = inp.copy()
while True:
if not inp:
break
c = inp.popleft()
if c.lower() == letter:
continue
outp.append(c)
return outp
newData = process(data)
for c in string.ascii_lowercase:
print (c, len(process(removeLetter(newData, c))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment