Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Advent2018;
- import util.AdventOfCode;
- import java.util.List;
- public class Day14 extends AdventOfCode {
- int intInput;
- public Day14(List<String> input) {
- super(input);
- title = "Chocolate Charts";
- part1Description = "Scores of ten recipes after goal: ";
- part2Description = "Number of recipes to get to input sequence: ";
- }
- StringBuilder makeRecipes(int goal) {
- StringBuilder scores = new StringBuilder();
- int a = 3;
- int b = 7;
- int aPos = 0;
- int bPos = 1;
- scores.append(String.valueOf(a));
- scores.append(String.valueOf(b));
- while (scores.length() < goal + 10) {
- int sum = a + b;
- if (sum > 9) {
- scores.append(String.valueOf(sum / 10));
- scores.append(String.valueOf(sum % 10));
- } else {
- scores.append(String.valueOf(sum));
- }
- aPos = (aPos + (1 + a)) % scores.length();
- bPos = (bPos + (1 + b)) % scores.length();
- a = scores.charAt(aPos) - '0';
- b = scores.charAt(bPos) - '0';
- }
- return scores;
- }
- @Override
- public Object part1() {
- return makeRecipes(intInput).substring(intInput);
- }
- @Override
- public Object part2() {
- return makeRecipes(30_000_000).indexOf(input.get(0));
- }
- @Override
- public void parse() {
- intInput = Integer.parseInt(input.get(0));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement