-
-
Save robhol/d57bc9d635402495b8be50487559d473 to your computer and use it in GitHub Desktop.
This file contains 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
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