<commit_before>package aoc2016;

import java.io.IOException;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;

public class Day06 {
  public static String solve(Character[][] input,Comparator<Map.Entry<String, Long>> sortBy) {
    StringBuilder sb = new StringBuilder();
    for (Character[] xs : input) {
      Map<String, Long> freqDist = Arrays.stream(xs).map(c -> String.valueOf(c)).collect(Collectors.groupingBy(c -> c, Collectors.counting()));
      sb.append(freqDist.entrySet().stream().sorted(sortBy).limit(1).map(Map.Entry::getKey).collect(Collectors.joining()));
    }
    return sb.toString();
  }

  public static Character[][] transpose(Character[][] input) {
    return IntStream.range(0, input[0].length).mapToObj(r -> IntStream.range(0, input.length).mapToObj(c -> Character.valueOf((char) input[c][r])).toArray(Character[]::new)).toArray(Character[][]::new);
  }

  public static Character[][] parse(List<String> lines) {
    return lines.stream().map(s -> s.chars().mapToObj(c -> Character.valueOf((char) c)).toArray(Character[]::new)).toArray(Character[][]::new);
  }

  public static void main(String[] args) throws IOException {
    List<String> lines = Files.readAllLines(Paths.get("./input/2016/Day06_input.txt"));
    System.out.println("Part One = " + solve(transpose(parse(lines)),Collections.reverseOrder(Map.Entry.comparingByValue())));
    System.out.println("Part Two = " + solve(transpose(parse(lines)),Map.Entry.comparingByValue()));    
  }
}<commit_msg>AoC 2016 - Day 06 - small improvments<commit_after>package aoc2016;

import java.io.IOException;
import java.nio.file.*;
import java.util.*;
import java.util.function.Function;
import java.util.stream.*;

public class Day06 {
  public static String solve(Character[][] input, Comparator<Map.Entry<Character, Long>> sortBy) {
    StringBuilder sb = new StringBuilder();
    for (Character[] xs : input) {
      Map<Character, Long> freqDist = Arrays.stream(xs).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
      freqDist.entrySet().stream().sorted(sortBy).limit(1).map(Map.Entry::getKey).forEachOrdered(sb::append);
    }
    return sb.toString();
  }

  public static Character[][] transpose(Character[][] input) {
    return IntStream.range(0, input[0].length).mapToObj(r -> IntStream.range(0, input.length).mapToObj(c -> (char) input[c][r]).toArray(Character[]::new)).toArray(Character[][]::new);
  }

  public static Character[][] parse(List<String> lines) {
    return lines.stream().map(s -> s.chars().mapToObj(c -> (char) c).toArray(Character[]::new)).toArray(Character[][]::new);
  }

  public static void main(String[] args) throws IOException {
    List<String> lines = Files.readAllLines(Paths.get("./input/2016/Day06_input.txt"));
    System.out.println("Part One = " + solve(transpose(parse(lines)),Collections.reverseOrder(Map.Entry.comparingByValue())));
    System.out.println("Part Two = " + solve(transpose(parse(lines)),Map.Entry.comparingByValue()));    
  }
}
{'fraction_non_alphanumeric': 0.1837748344370861, 'fraction_numerical': 0.012582781456953643, 'mean_word_length': 5.2032854209445585, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4516746', 'n_tokens_mistral': 969, 'n_tokens_neox': 941, 'n_words': 158}