Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var lines = Properties.Resources.TextFile1.Split('\n'); //Split the input to single lines
- int resultA = lines.Select(x => x.Trim().Split(' ')) //split to seperate words
- .Where(x => x.Count() == x.Distinct().Count()) //Compare start count with distinct count (removes duplicates)
- .Count(); //count the result is the andwer
- int resultB = lines.Select(x => x.Trim().Split(' ') //split to seperate words
- .Select(z=> string.Join("-", //joins the result of below
- z.GroupBy(y=> y) //get the freq count of each used letter
- .OrderBy(y=> y.Key) //sort so all the letters anagrams look the same
- .Select(y=> $"{y.Key}{y.Count()}"))) //make a string a5 => a5-b4-etc
- ).Where(x => x.Count() == x.Distinct().Count()).Count(); //same as partA
Advertisement
Add Comment
Please, Sign In to add comment