Skip to content

Instantly share code, notes, and snippets.

@robhol
Last active December 7, 2017 09:45
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 robhol/d57bc9d635402495b8be50487559d473 to your computer and use it in GitHub Desktop.
Save robhol/d57bc9d635402495b8be50487559d473 to your computer and use it in GitHub Desktop.
int Part1(string[] passphrases) => passphrases.Where(IsValidPart1).Count();
int Part2(string[] passphrases) => passphrases.Where(IsValidPart2).Count();
bool IsValidPart1(string str) => IsValid(str, x => x);
bool IsValidPart2(string str) => IsValid(str, Alphabetize);
bool IsValid(string str, Func<string, string> projection)
{
var segs = str.Split(' ').Select(projection).ToArray();
return segs.Length > 1 && segs.SequenceEqual(segs.Distinct());
}
string Alphabetize(string str) => string.Concat(str.ToCharArray().OrderBy(c => c));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment