1 files changed, 70 insertions(+), 0 deletions(-)

A => src/ninja/scoopta/software/advent_of_code_12020/Day6.java
A => src/ninja/scoopta/software/advent_of_code_12020/Day6.java +70 -0
@@ 0,0 1,70 @@ 
+package ninja.scoopta.software.advent_of_code_12020;
+
+import java.util.*;
+import java.nio.file.*;
+import java.io.IOException;
+
+final class Day6 {
+	public static final void main(String[] args) {
+		try {
+			List<String> lines = Files.readAllLines(Paths.get("day6.txt"));
+			System.out.println("Part 1");
+			pt1(lines);
+			System.out.println("Part 2");
+			pt2(lines);
+		} catch(IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	private static final void pt1(List<String> lines) {
+		TreeSet<Character> answers = new TreeSet<>();
+		int yeses = 0;
+		for(String line : lines) {
+			if(line.equals("")) {
+				yeses += answers.size();
+				answers.clear();
+				continue;
+			}
+			for(char chr : line.toCharArray()) {
+				answers.add(chr);
+			}
+		}
+		yeses += answers.size();
+		System.out.println(yeses);
+	}
+	
+	private static final void pt2(List<String> lines) {
+		TreeMap<Character, Integer> answers = new TreeMap<>();
+		
+		int people = 0;
+		int yeses = 0;
+		for(String line : lines) {
+			if(line.equals("")) {
+				for(int count : answers.values()) {
+					if(count == people) {
+						++yeses;
+					}
+				}
+				people = 0;
+				answers.clear();
+				continue;
+			}
+			++people;
+			for(char chr : line.toCharArray()) {
+				Integer count = answers.get(chr);
+				if(count != null) {
+					answers.put(chr, ++count);
+				} else {
+					answers.put(chr, 1);
+				}
+			}
+		}
+		for(int count : answers.values()) {
+			if(count == people) {
+				++yeses;
+			}
+		}
+		System.out.println(yeses);
+	}
+}