package aoc20;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Day6 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int sum = 0;
        while (in.hasNextLine()) {
            List<String> response = gatherResponses(in);
            int answers = countAnswers(response);
            sum += answers;
            System.out.println(sum);
        }
    }

    private static int countAnswers(List<String> response) {
        Set<Character> chars = new HashSet<>();
        for (String str : response) {
            for (char c : str.toCharArray()) {
                chars.add(c);
            }
        }
        return chars.size();
    }

    private static List<String> gatherResponses(Scanner in) {
        List<String> result = new ArrayList<>();
        String line = in.nextLine();
        while (!line.isEmpty()) {
            result.add(line);
            line = in.nextLine();
        }
        return result;
    }
}

@@ -33,24 +33,50 @@
 .ArrayList;%0A
+import java.util.HashMap;%0A
 import java.
@@ -108,24 +108,46 @@
 .util.List;%0A
+import java.util.Map;%0A
 import java.
@@ -607,19 +607,19 @@
         
-Set
+Map
 %3CCharact
@@ -624,14 +624,28 @@
 cter
+, Integer
 %3E char
+Count
 s = 
@@ -652,19 +652,19 @@
 new Hash
-Set
+Map
 %3C%3E();%0A  
@@ -766,71 +766,210 @@
     
-chars.add(c);%0A            %7D%0A        %7D%0A        return chars.size
+int count = charCounts.getOrDefault(c, 0);%0A                charCounts.put(c, count + 1);%0A            %7D%0A        %7D%0A        return (int) charCounts.values().stream().filter(c -%3E c == response.size()).count
 ();%0A

day 6 2