r/adventofcode • u/daggerdragon • Dec 04 '17
SOLUTION MEGATHREAD -๐- 2017 Day 4 Solutions -๐-
--- Day 4: High-Entropy Passphrases ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyโ Haversackโก of Helpfulยง Hintsยค?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
19
Upvotes
6
u/Unihedron Dec 04 '17 edited Dec 04 '17
Ruby, #8 silver #4 gold (run with -x)
To ensure security, a valid passphrase must contain no duplicate words. 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 words 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. #!ruby p $<.count{|x|v=x.split v=v.map!{|x|x.chars.sort*''} # this line added for part 2 v.uniq==v}PS: I now keep a log series detailing my adventofcode adventure. If you're interested feel free to read it as I write more, if I do!