Created
December 1, 2022 09:46
-
-
Save msx80/368e40930f6e2bd67f978e993c23fec6 to your computer and use it in GitHub Desktop.
Aoc1
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 esperimentini; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.util.Comparator; | |
import java.util.stream.Stream; | |
public class AOC1 { | |
public static void main(String[] args) throws Exception { | |
var sums = Stream | |
.of( Files.readString(Path.of("input1.txt")).split("\n\n") ) | |
.map(t -> Stream.of(t.split("\n")).mapToLong(Long::parseLong).sum() ) | |
.toList(); | |
System.out.println(sums.stream().max(Comparator.naturalOrder()).get()); | |
System.out.println(sums.stream().sorted(Comparator.reverseOrder()).limit(3).reduce(Long::sum).get()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment