Last active
May 14, 2018 16:59
-
-
Save sphvn/6d5a922b11b51822df5f385dd50f1f9f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Day Four in Node for fun | |
# http://adventofcode.com/2017/day/4/ | |
require! "fs" | |
require! 'prelude-ls': {lines, words, zip, map, filter, unique} | |
length = (.length) | |
sort = (.split('').sort().join('')) | |
input = map words, lines (fs.read-file-sync "input.txt", 'utf-8') | |
sorted = map ((x) -> map ((y) -> sort y), x), input | |
zippers = zip (map length, sorted), (map length, map unique, sorted) | |
console.log (length (filter ((x) -> x[0] is x[1]), zippers)) |
--- Part Two ---
For added security, yet another system policy has been put in place. Now, a valid passphrase must contain no two words that are anagrams of each other - that is, a passphrase is invalid if any word's letters can be rearranged to form any other word in the passphrase.
For example:
abcde fghij is a valid passphrase.
abcde xyz ecdab is not valid - the letters from the third word can be rearranged to form the first word.
a ab abc abd abf abj is a valid passphrase, because all letters need to be used when forming another word.
iiii oiii ooii oooi oooo is valid.
oiii ioii iioi iiio is not valid - any of these words can be rearranged to form any other word.
Under this new system policy, how many passphrases are valid?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
--- Day 4: High-Entropy Passphrases ---
A new system policy has been put in place that requires all accounts to use a passphrase instead of simply a password. A passphrase consists of a series of words (lowercase letters) separated by spaces.
To ensure security, a valid passphrase must contain no duplicate words.
For example:
aa bb cc dd ee is valid.
aa bb cc dd aa is not valid - the word aa appears more than once.
aa bb cc dd aaa is valid - aa and aaa count as different words.
The system's full passphrase list is available as your puzzle input. How many passphrases are valid?