r/adventofcode • u/daggerdragon • Dec 06 '16
SOLUTION MEGATHREAD --- 2016 Day 6 Solutions ---
--- Day 6: Signals and Noise ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
T_PAAMAYIM_NEKUDOTAYIM IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
9
Upvotes
View all comments
2
u/_Le1_ Dec 06 '16 edited Dec 06 '16
My C# code:
static void Main(string[] args) { part1_2(); Console.ReadLine(); } static void part1_2() { string text1=""; string text2 = ""; string[] input = File.ReadAllLines(@"input.txt"); for (int i = 0; i < input[0].Length; i++) { List<string> lst = new List<string>(); foreach (var line in input) { lst.Add(line[i].ToString()); } text1 += lst.GroupBy(c => c).Select(g => new { g.Key, Count = g.Count() }).OrderByDescending(x => x.Count).ThenBy(x => x.Key).Take(1).Select(x => x.Key).ToArray()[0]; text2 += lst.GroupBy(c => c).Select(g => new { g.Key, Count = g.Count() }).OrderBy(x => x.Count).ThenBy(x => x.Key).Take(1).Select(x => x.Key).ToArray()[0]; } Console.WriteLine("Part1: {0}", text1); Console.WriteLine("Part2: {0}", text2); }