Skip to content

Instantly share code, notes, and snippets.

@msx80
Last active December 4, 2020 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msx80/7d88ba81ab51619cd953b1e6a34a0b63 to your computer and use it in GitHub Desktop.
Save msx80/7d88ba81ab51619cd953b1e6a34a0b63 to your computer and use it in GitHub Desktop.
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