puzzle2.py (679B)
1 file = [s[0:-1] for s in open('files/puzzle2.txt').readlines()] 2 two_count = 0 3 three_count = 0 4 5 for i, s in enumerate(file): 6 letter_table = [0 for idx in range(26)] 7 two_count_inc = 0 8 three_count_inc = 0 9 10 for c in s: 11 letter_table[ord(c) - ord('a')] += 1 12 13 for l in letter_table: 14 if l == 2: 15 two_count_inc = 1 16 if l == 3: 17 three_count_inc = 1 18 19 two_count += two_count_inc 20 three_count += three_count_inc 21 22 for ss in file[0: i]: 23 if sum([a != b for a, b in zip(s, ss)]) == 1: 24 print ''.join([a if a == b else '' for a, b in zip(s, ss)]) 25 26 print two_count * three_count