Skip to content

Instantly share code, notes, and snippets.

@csuzw
Last active December 4, 2017 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csuzw/b1478da9ee4c5caa4b86045a8b8dace7 to your computer and use it in GitHub Desktop.
Save csuzw/b1478da9ee4c5caa4b86045a8b8dace7 to your computer and use it in GitHub Desktop.
Advent of Code 2017 Day 4
int HighEntropyPassphrasesPartOne(string[] passPhrases)
{
return DoHighEntropyPassphrases(passPhrases, w => w);
}
int HighEntropyPassphrasesPartTwo(string[] passPhrases)
{
return DoHighEntropyPassphrases(passPhrases, w => string.Concat(w.OrderBy(c => c)));
}
int DoHighEntropyPassphrases(string[] passPhrases, Func<string, string> map)
{
return passPhrases.Count(words =>
{
var set = new HashSet<string>();
return words.Split(' ').All(word => set.Add(map(word)));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment