<jupyter_start><jupyter_text>Advent of Code 2018 - Day 2  Input<jupyter_code>input = []
with open('input.txt', 'r') as f:
    input = [i.rstrip() for i in f]<jupyter_output><empty_output><jupyter_text>Part 1<jupyter_code>has_letter_2x = 0
has_letter_3x = 0

for id in input:
    letters = {}
    for letter in id:
        letters[letter] = letters.get(letter, 0) + 1
    
    letter_frequency = letters.values()
    if 2 in letter_frequency:
        has_letter_2x += 1
    if 3 in letter_frequency:
        has_letter_3x += 1
        
print "has letter 2x: {}".format(has_letter_2x)
print "has letter 3x: {}".format(has_letter_3x)
print "checksum: {}".format(has_letter_2x * has_letter_3x)<jupyter_output>has letter 2x: 246
has letter 3x: 33
checksum: 8118<jupyter_text>Part 2<jupyter_code># brute force approach:
# - iterate over all ids
# - store all permutations missing one char in a set
# - when storing, check to see if it already exists
# - if so, it's the match
permutations_by_pos = {}
for id in input:
    id_length = len(id)

    for pos in range(0, id_length):
        # store sets of permutation by position, since
        # the differing letter must be in the same position
        if pos not in permutations_by_pos:
            permutations_by_pos[pos] = set()

        permutation = id[:pos] + id[pos + 1:]

        if permutation in permutations_by_pos[pos]:
            print "match: {}".format(permutation)
            break
        else:
            permutations_by_pos[pos].add(permutation)<jupyter_output>match: jbbenqtlaxhivmwyscjukztdp
{'fraction_non_alphanumeric': 0.09878127004490057, 'fraction_numerical': 0.024374599101988453, 'mean_word_length': 3.227642276422764, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '620547', 'license': 'MIT', 'n_tokens_mistral': 583, 'n_tokens_neox': 532, 'n_words': 153, 'path': '2018/02/solution.ipynb', 'repo_name': 'MWers/advent-of-code', 'size': '1559'}