Last active
December 4, 2020 09:12
-
-
Save msx80/7d88ba81ab51619cd953b1e6a34a0b63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package aoc; | |
import java.io.IOException; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.stream.Collectors; | |
import java.util.stream.Stream; | |
public class Day4 { | |
static List<String> NEEDED = Arrays.asList( "byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid" ); | |
static Map<String, String> makePassport(String[] tokens) | |
{ | |
return Stream | |
.of(tokens) | |
.map(t -> t.split(":")) | |
.collect(Collectors.toMap(s->s[0], s->s[1])); | |
} | |
public static void main(String[] args) throws IOException | |
{ | |
String[] passports = Files.readString(Paths.get("input4.txt")).split("\n\n"); | |
var count = Stream.of(passports) | |
.map(s -> s.split(" |\n")) | |
.map(Day4::makePassport) | |
.filter(p -> p.keySet().containsAll(NEEDED)) | |
.count(); | |
System.out.println(count); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment