Untitled
unknown
python
3 years ago
611 B
4
Indexable
with open('C:/Users/romor/Desktop/python/advent 3.txt') as f: puzzle_input = f.read().strip().split('\n') def get_similar(word): first = word[:len(word)//2] second = word[len(word)//2:] for i in first: for j in second: if i == j: return(i) lc = {} count = 1 for i in range(ord('a'), ord('z')+1): lc[chr(i)] = count count += 1 hc = {} for i in range(ord('A'), ord('Z')+1): lc[chr(i)] = count count += 1 lc.update(hc) solution = 0 for i in range(len(puzzle_input)): solution += lc[get_similar(puzzle_input[i])]
Editor is loading...