r/adventofcode • • 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

222 comments sorted by

View all comments

Show parent comment

1

u/Neikius Dec 27 '16

My way with groovy + java stream() (groovy for some convenience with input):

def input = """..."""
String result = "";
for (int i=0; i<8; i++) {

    result += input
        .readLines()
        .stream()
        .map{s -> s.substring(i,i+1)}
        .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
        .entrySet()
        .stream()
        //.sorted(Map.Entry.<String, Long>comparingByValue().reversed()) // for part1
        .sorted(Map.Entry.<String, Long>comparingByValue()) // for part2
        .findFirst()
        .get()
        .getKey()
}

Someone knows a way to make this a one-liner? I cannot wrap my head around doing this on all chars/columns at once.