Skip to content

Instantly share code, notes, and snippets.

@msx80
Created December 1, 2022 09:46
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/368e40930f6e2bd67f978e993c23fec6 to your computer and use it in GitHub Desktop.
Save msx80/368e40930f6e2bd67f978e993c23fec6 to your computer and use it in GitHub Desktop.
Aoc1
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