86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
# IDEAS(dev):
|
|
# - You might not have to determine all the positions if the numbers to decode don't use them
|
|
# e.g. while(number to decode NOT IN numbers decodable) { do everything }
|
|
# -
|
|
|
|
# NOTES(dev):
|
|
# - It looks like the codes are NOT always printed in the same order. For example, if one shows up
|
|
# as 'cg', it might also later show up as 'gc' in the same line.
|
|
# 0: 1: 2: 3: 4:
|
|
|
|
# aaaa .... aaaa aaaa ....
|
|
# b c . c . c . c b c
|
|
# b c . c . c . c b c
|
|
# .... .... dddd dddd dddd
|
|
# e f . f e . . f . f
|
|
# e f . f e . . f . f
|
|
# gggg .... gggg gggg ....
|
|
|
|
# 5: 6: 7: 8: 9:
|
|
# aaaa aaaa aaaa aaaa aaaa
|
|
# b . b . . c b c b c
|
|
# b . b . . c b c b c
|
|
# dddd dddd .... dddd dddd
|
|
# . f e f . f e f . f
|
|
# . f e f . f e f . f
|
|
# gggg gggg .... gggg gggg
|
|
|
|
# initialize shared data:
|
|
possibilities = {}
|
|
all_possibilities = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ]
|
|
|
|
# functions:
|
|
def ResetData():
|
|
possibilities.clear()
|
|
for letter in all_possibilities:
|
|
possibilities[letter] = list(all_possibilities)
|
|
|
|
def ParsePossibilities(text):
|
|
text_len = len(text)
|
|
if(text_len == 2):
|
|
good_letters = [ text[0], text[1] ]
|
|
print(good_letters)
|
|
|
|
# first, get rid of the good letters from all the other positions
|
|
for letter in ['a', 'b', 'd', 'e', 'g']: # all the positions not used by #1
|
|
for to_remove in good_letters:
|
|
possibilities[letter].remove(to_remove)
|
|
|
|
# second, get rid of the other letters from the positions used by #1
|
|
for letter in ['c', 'f']:
|
|
to_remove_list = []
|
|
for l in possibilities[letter]:
|
|
if(not (l in good_letters)):
|
|
to_remove_list.append(l)
|
|
for to_remove in to_remove_list:
|
|
possibilities[letter].remove(to_remove)
|
|
|
|
total = 0
|
|
with open('example_data', 'r') as fp:
|
|
# NOTE(dev): We assume all lines are the same length
|
|
for line in fp:
|
|
ResetData()
|
|
split_line = line.split(' | ')
|
|
data = split_line[0].split()
|
|
print(data)
|
|
codes = split_line[1]
|
|
for val in codes.split():
|
|
if(len(val) in [2, 3, 4, 7]):
|
|
total += 1
|
|
|
|
for text in data:
|
|
ParsePossibilities(text.strip())
|
|
|
|
asdf = possibilities.items()
|
|
asdf = list(asdf)
|
|
asdf.sort()
|
|
print(asdf)
|
|
|
|
# part 1 answer:
|
|
print(total)
|
|
|
|
|
|
|
|
# # DEBUG(dev):
|
|
# print(possibilities)
|