Skip to content

Commit

Permalink
Start 2020 java
Browse files Browse the repository at this point in the history
  • Loading branch information
tjpalmer committed Apr 10, 2021
1 parent 953d3a8 commit 18e4dc4
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions 2020/java/Day1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import java.io.File;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.stream.IntStream;

class Day1 {
public static void main(String[] args) throws Exception {
System.out.printf("Hi %s\n", args[0]);
int[] numbers;
try (var lineStream = Files.lines(new File(args[0]).toPath())) {
numbers = lineStream.mapToInt(Integer::parseInt).toArray();
}
IntStream
.range(0, numbers.length)
.filter(i -> {
var a = numbers[i];
// Arrays.stream(numbers).skip(i + 1);
var optionalB = IntStream
.range(i + 1, numbers.length)
.filter(j -> a + numbers[j] == 2020)
.findFirst();
optionalB.ifPresent(j -> System.out.println(a * numbers[j]));
return optionalB.isPresent();
})
.findFirst();
}
}

0 comments on commit 18e4dc4

Please sign in to comment.