2017-12-04 - High-Entropy Passphrases
(original .ipynb)puzzle_input_str = open("puzzle_input/day4.txt").read() def valid_passphrase(passphrase): words = passphrase.split(" ") words_seen = set() for word in words: if word in words_seen: return False words_seen.add(word) return True def part_one(input_str): passphrases = [ passphrase.strip() for passphrase in input_str.split("\n") ] return len([p for p in passphrases if valid_passphrase(p)]) print("part one:", part_one(puzzle_input_str))
part one: 455
def valid_passphrase2(passphrase): words = passphrase.split(" ") words_seen = set() for word in words: sorted_word = str("".join(sorted([c for c in word]))) if sorted_word in words_seen: return False words_seen.add(sorted_word) return True def part_two(input_str): passphrases = [ passphrase.strip() for passphrase in input_str.split("\n") ] return len([p for p in passphrases if valid_passphrase2(p)]) print("part two:", part_two(puzzle_input_str))
part two: 187