-
-
Save msx80/2727f3183068799bd4cd7311f123baac 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; | |
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