Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.stream.Stream;
- class AOC2021_6 {
- private static long fishCount = 0;
- public static void main(String[] args) {
- long start = System.currentTimeMillis();
- String sample = "3,4,3,1,2";
- String input = "2,1,2,1,5,1,5,1,2,2,1,1,5,1,4,4,4,3,1,2,2,3,4,1,1,5,1,1,4,2,5,5,5,1,1,4,5,4,1,1,4,2,1,4,1,2,2,5,1,1,5,1,1,3,4,4,1,2,3,1,5,5,4,1,4,1,2,1,5,1,1,1,3,4,1,1,5,1,5,1,1,5,1,1,4,3,2,4,1,4,1,5,3,3,1,5,1,3,1,1,4,1,4,5,2,3,1,1,1,1,3,1,2,1,5,1,1,5,1,1,1,1,4,1,4,3,1,5,1,1,5,4,4,2,1,4,5,1,1,3,3,1,1,4,2,5,5,2,4,1,4,5,4,5,3,1,4,1,5,2,4,5,3,1,3,2,4,5,4,4,1,5,1,5,1,2,2,1,4,1,1,4,2,2,2,4,1,1,5,3,1,1,5,4,4,1,5,1,3,1,3,2,2,1,1,4,1,4,1,2,2,1,1,3,5,1,2,1,3,1,4,5,1,3,4,1,1,1,1,4,3,3,4,5,1,1,1,1,1,2,4,5,3,4,2,1,1,1,3,3,1,4,1,1,4,2,1,5,1,1,2,3,4,2,5,1,1,1,5,1,1,4,1,2,4,1,1,2,4,3,4,2,3,1,1,2,1,5,4,2,3,5,1,2,3,1,2,2,1,4";
- String dataFish = input;
- int TTL = 256;
- Integer[] fish = Stream.of(dataFish.split(",")).map(Integer::valueOf).toArray(Integer[]::new);
- long[] data_ar = new long[8];
- for (int data=1; data<=7; data++) {
- fishCount = 1;
- reproduce(data, TTL);
- data_ar[data] = fishCount;
- System.out.println(data + " day-to-repro after " + TTL + " iterations leads to " + data_ar[data] + " fish.");
- }
- System.out.println("Counting fish...");
- fishCount = 0;
- for (int i=0; i<fish.length; i++){
- fishCount += data_ar[fish[i]];
- }
- System.out.println("Total fishcount: " + fishCount);
- long finish = System.currentTimeMillis();
- System.out.println("Time in msec: " + (finish - start));
- System.out.println("Time in sec: " + (finish - start) / 1000);
- }
- static void reproduce(int daysToReproduce, int rTTL) {
- for (int j = rTTL; j >= 0; j--) {
- if (daysToReproduce == -1) {
- daysToReproduce = 6;
- fishCount++;
- reproduce(8, j);
- }
- daysToReproduce--;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement