Guest User

AdventOfCode 2017-Day04

a guest
Dec 4th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.83 KB | None | 0 0
  1. var lines = Properties.Resources.TextFile1.Split('\n'); //Split the input to single lines
  2.            
  3. int resultA = lines.Select(x => x.Trim().Split(' ')) //split to seperate words
  4.             .Where(x => x.Count() == x.Distinct().Count()) //Compare start count with distinct count (removes duplicates)
  5.             .Count(); //count the result is the andwer
  6.  
  7. int resultB = lines.Select(x => x.Trim().Split(' ') //split to seperate words                
  8.             .Select(z=> string.Join("-", //joins the result of below
  9.                 z.GroupBy(y=> y) //get the freq count of each used letter
  10.                 .OrderBy(y=> y.Key) //sort so all the letters anagrams look the same
  11.                 .Select(y=> $"{y.Key}{y.Count()}"))) //make a string a5 => a5-b4-etc
  12.             ).Where(x => x.Count() == x.Distinct().Count()).Count(); //same as partA
Advertisement
Add Comment
Please, Sign In to add comment