Skip to content

Instantly share code, notes, and snippets.

@msx80
Created December 1, 2020 07:53
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/2727f3183068799bd4cd7311f123baac to your computer and use it in GitHub Desktop.
Save msx80/2727f3183068799bd4cd7311f123baac 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;
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