Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Advent2019;
- import util.AdventOfCode;
- import java.util.List;
- public class Day1 extends AdventOfCode {
- public Day1(List<String> input) {
- super(input);
- title = "The Tyranny of the Rocket Equation";
- part1Description = "Total Fuel Requirements: ";
- part2Description = "Total Fuel Requirements to Wishing Really Hard Point: ";
- }
- static int calculate(int n) {
- if (n <= 0) return 0;
- n = n / 3 - 2;
- return Math.max(n, 0) + calculate(n);
- }
- @Override
- public Object part1() {
- return input.stream()
- .mapToInt(Integer::parseInt)
- .map(x -> x / 3 - 2)
- .sum();
- }
- @Override
- public Object part2() {
- return input.stream()
- .mapToInt(Integer::parseInt)
- .map(Day1::calculate)
- .sum();
- }
- @Override
- public void parse() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement