package aoc20;

import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Day13 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int time = in.nextInt();
        in.nextLine();
        List<Integer> numsLine = Arrays.stream(in.nextLine().split(","))
                .filter(s -> !"x".equals(s))
                .map(Integer::parseInt)
                .collect(Collectors.toList());
        final List<Integer> waits = numsLine.stream().map(n -> n - (time % n)).collect(Collectors.toList());
        int minIndex = 0;
        int minVal = waits.get(0);
        for (int i = 0; i < waits.size(); i++) {
            if (waits.get(i) < minVal) {
                minIndex = i;
                minVal = waits.get(i);
            }
        }
        System.out.println(numsLine.get(minIndex));
        System.out.println(waits.get(minIndex));
        System.out.println(numsLine.get(minIndex) * waits.get(minIndex));
    }
}

@@ -31,17 +31,133 @@
 il.Array
-s
+List;%0Aimport java.util.Arrays;%0Aimport java.util.Collections;%0Aimport java.util.HashMap;%0Aimport java.util.LinkedHashMap
 ;%0Aimport
@@ -169,24 +169,46 @@
 .util.List;%0A
+import java.util.Map;%0A
 import java.
@@ -437,204 +437,2071 @@
     
-List%3CInteger%3E numsLine = Arrays.stream(in.nextLine().split(%22,%22))%0A                .filter(s -%3E !%22x%22.equals(s))%0A                .map(Integer::parseInt)%0A                .collect(Collectors.toList());
+final String%5B%5D values = in.nextLine().split(%22,%22);%0A        List%3CInteger%3E numsLine = Arrays.stream(values)%0A                .filter(s -%3E !%22x%22.equals(s))%0A                .map(Integer::parseInt)%0A                .collect(Collectors.toList());%0A        Map%3CInteger, Integer%3E schedule = new LinkedHashMap%3C%3E();%0A        for (int i = 0; i %3C values.length; i++) %7B%0A            if (!values%5Bi%5D.equals(%22x%22)) %7B%0A                schedule.put(Integer.parseInt(values%5Bi%5D), i);%0A            %7D%0A        %7D%0A        System.out.println(schedule);%0A%0A        part2(schedule);%0A%0A        // part1(time, numsLine);%0A    %7D%0A%0A    private static void part2(Map%3CInteger, Integer%3E schedule) %7B%0A        List%3CInteger%3E ids = new ArrayList%3C%3E(schedule.keySet());%0A        long multFactor = ids.get(0);%0A        long soFar = ids.get(0);%0A        for (int i = 1; i %3C ids.size(); i++) %7B%0A            int mult = ids.get(i);%0A            System.out.println(%22mult of %22 + mult);%0A            int desiredMod = mult - schedule.get(ids.get(i));%0A            while (desiredMod %3C 0) %7B%0A                desiredMod += mult;%0A            %7D%0A            System.out.println(%22desired mod of %22 + desiredMod);%0A            while ((soFar %25 mult) != desiredMod) %7B%0A                soFar += multFactor;%0A            %7D%0A            System.out.println(%22satisfied at %22 + soFar);%0A            multFactor *= mult;%0A            System.out.println(%22mult factor to %22 + multFactor);%0A        %7D%0A        System.out.println(soFar);%0A    %7D%0A%0A    private static boolean isDone(long computedVal, Map%3CInteger, Integer%3E schedule) %7B%0A        for (Map.Entry%3CInteger, Integer%3E entry : schedule.entrySet()) %7B%0A            if ((computedVal %25 entry.getKey()) != entry.getValue()) %7B%0A                return false;%0A            %7D%0A        %7D%0A        return true;%0A    %7D%0A%0A    private static long computeVal(long%5B%5D multiples, List%3CInteger%3E schedule) %7B%0A        long result = 0;%0A        for (int i = 0; i %3C multiples.length; i++) %7B%0A            result += multiples%5Bi%5D * schedule.get(i);%0A        %7D%0A        return result;%0A    %7D%0A%0A    private static void part1(int time, List%3CInteger%3E numsLine) %7B
 %0A   

day 13 2