Skip to content

Instantly share code, notes, and snippets.

@msx80
Created Dec 1, 2020
Embed
What would you like to do?
package aoc;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class Day1 {
public static void main(String[] args) throws IOException {
// part 1
var lines = Files.readAllLines(Paths.get("input1.txt")).stream().mapToInt(Integer::parseInt).toArray();
System.out.println(part1(lines));
// part 2
System.out.println(part2(lines));
}
public static int part2(int[] lines) {
for (int n1 : lines)
for (int n2 : lines)
for (int n3 : lines)
if(n1+n2+n3 == 2020)
return n1*n2*n3;
return -1;
}
public static int part1(int[] lines) {
for (int n1 : lines)
for (int n2 : lines)
if(n1+n2 == 2020)
return n1*n2;
return -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment