Advertisement
Guest User

Untitled

a guest
Dec 1st, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package Advent2019;
  2.  
  3. import util.AdventOfCode;
  4.  
  5. import java.util.List;
  6.  
  7. public class Day1 extends AdventOfCode {
  8.  
  9.     public Day1(List<String> input) {
  10.         super(input);
  11.         title = "The Tyranny of the Rocket Equation";
  12.         part1Description = "Total Fuel Requirements: ";
  13.         part2Description = "Total Fuel Requirements to Wishing Really Hard Point: ";
  14.     }
  15.  
  16.     static int calculate(int n) {
  17.         if (n <= 0) return 0;
  18.         n = n / 3 - 2;
  19.         return Math.max(n, 0) + calculate(n);
  20.     }
  21.  
  22.     @Override
  23.     public Object part1() {
  24.         return input.stream()
  25.                 .mapToInt(Integer::parseInt)
  26.                 .map(x -> x / 3 - 2)
  27.                 .sum();
  28.     }
  29.  
  30.     @Override
  31.     public Object part2() {
  32.  
  33.         return input.stream()
  34.                 .mapToInt(Integer::parseInt)
  35.                 .map(Day1::calculate)
  36.                 .sum();
  37.     }
  38.  
  39.     @Override
  40.     public void parse() {
  41.  
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement