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.
Read the full puzzle.
using System;
using System.Linq;
namespace AdventOfCode.Y2017.Day04;
[ProblemName("High-Entropy Passphrases")]
class Solution : Solver {
public object PartOne(string lines) =>
ValidLineCount(lines, word => word);
public object PartTwo(string lines) =>
ValidLineCount(lines, word => string.Concat(word.OrderBy(ch => ch)));
int ValidLineCount(string lines, Func<string, string> normalizer) =>
lines.Split('\n').Where(line => IsValidLine(line.Split(' '), normalizer)).Count();
bool IsValidLine(string[] words, Func<string, string> normalizer) =>
words.Select(normalizer).Distinct().Count() == words.Count();
}
Please ☆ my repo if you like it!