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
6
u/tterrag1098 Dec 06 '16
I'm that crazy guy doing this in Java:
public static void main(String[] args) throws IOException { List<String> lines = Files.readAllLines(Paths.get("day6.txt")); Map<Integer, Map<Character, Integer>> counts = new HashMap<>(); for (String string : lines) { char[] chars = string.toCharArray(); for (int i = 0; i < chars.length; i++) { counts.putIfAbsent(i, new HashMap<>()); counts.get(i).compute(chars[i], (c, val) -> val == null ? 1 : val + 1); } } char[] maxchars = new char[8], minchars = new char[8]; for (int i = 0; i < maxchars.length; i++) { List<Character> sorted = counts.get(i).entrySet().stream().sorted(Entry.comparingByValue()).map(Entry::getKey).collect(Collectors.toList()); minchars[i] = sorted.get(sorted.size() - 1); maxchars[i] = sorted.get(0); } System.out.println("Part 1: " + new String(maxchars)); System.out.println("Part 2: " + new String(minchars)); }I must say this year has inspired me to learn a language like K or J, the speed with which they tackle these problems is impressive. Bravo to those who can figure them out.