package UE12_310125_AOC22;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;


public class year2024_day22 {
    public static List<String> readFile(String s) {
        List<String> lines;
        try {
            lines = Files.readAllLines(Path.of(s));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        return lines;
    }

    public static void main(String[] args) {
        List<String> lines = readFile("src/UE12_310125_AOC22/day22_input.txt");
        System.out.println(day22(lines, 2000));
    }

    public static long day22(List<String> lines, int cycles) {
        long out = 0;
        for (String line : lines) {
            long secret = Integer.parseInt(line);
            for (int i = 0; i < cycles; i++) {
                secret ^= (secret << 6) & 0xFFFFFF;
                secret ^= (secret >> 5) & 0xFFFFFF;
                secret ^= (secret << 11) & 0xFFFFFF;
            }
            out += secret;
        }
        return out;
    }
}