diff --git a/2018/day-12/20-generations.txt b/2018/day-12/20-generations.txt new file mode 100644 index 0000000..b8514a9 --- /dev/null +++ b/2018/day-12/20-generations.txt @@ -0,0 +1,22 @@ +Generating 20 generations from the input looks like this: +..#...#...##..####..##.####.#...#...#.#.#.#......##....#....######.####.##..#..#..##.##..##....#######..................... +..##..##.#.#....##...##..#..##..##...#######....#.##...##..#..###.#..#.#.#.######..##.#...##..#..######.................... +.#.#...#.####..#.##.#.#.###..#...##.#..######....#.##.#.#.###..#..###.#####..####...#.##.#.#.###...#####................... +..###...#..##.#.#.#.####.##.###.#.#.##...#####....#.#.####.##.###..#.#..###....###...#.#.####.###.#..####.................. +.#.###..##..#.######..#.#.##.#..####.##.#..####....###..#.#.##.##.#.###..###..#.###...###..#.#.#..##...###................. +..#.##...#.#.#..####.#.###.#.##...#.#.#.##...###..#.##.#.###.##.#.##.##...##.#.#.###.#.##.#.#####..##.#.###................ +...#.##...#####...#..##.#..##.##...#####.##.#.##.#.#.#.##.#.#.#.##.##.##.#.#.####.#..##.#.##..###...#.##.###............... +....#.##.#..####..##..#.##..##.##.#..##.#.#.##.#.######.#.######.##.##.#.####..#..##..#.##.#...###...#.##.###.............. +.....#.#.##...##...#.#.#.#...##.#.##..#.####.#.##..###..##..###.#.##.#.##..##.###..#.#.#.#.##.#.###...#.##.###............. +......###.##.#.##...#######.#.#.##.#.#.#..#..##.#...##...#...#..##.#.##.#...##.##.#.#######.#.##.###...#.##.###............ +.....#.#.#.#.##.##.#..####..####.#.#########..#.##.#.##..##..##..#.##.#.##.#.##.#.##..####..##.##.###...#.##.###........... +......#######.##.#.##...##....#..##..#######.#.#.#.##.#...#...#.#.#.#.##.#.##.#.##.#....##...##.##.###...#.##.###.......... +.....#..####.#.#.##.##.#.##...##..#....####..######.#.##..##...#######.#.##.#.##.#.##..#.##.#.##.##.###...#.##.###......... +.....##...#..####.##.#.##.##.#.#.###..#..##....###..##.#...##.#..####..##.#.##.#.##.#.#.#.#.##.##.##.###...#.##.###........ +....#.##..##...#.#.#.##.##.#.####.##.###..##..#.##...#.##.#.#.##...##...#.##.#.##.#.########.##.##.##.###...#.##.###....... +.....#.#...##...#####.##.#.##..#.#.##.##...#.#.#.##...#.#.####.##.#.##...#.#.##.#.##..#####.#.##.##.##.###...#.##.###...... +......###.#.##.#..##.#.#.##.#.#.###.##.##...#####.##...###..#.#.#.##.##...###.#.##.#....##..##.##.##.##.###...#.##.###..... +.....#.#..##.#.##..#.####.#.####.#.#.##.##.#..##.#.##.#.##.#.#####.##.##.#.#..##.#.##..#.#...##.##.##.##.###...#.##.###.... +......###..#.##.#.#.#..#..##..#..####.##.#.##..#.##.#.##.#.##..##.#.##.#.####..#.##.#.#.###.#.##.##.##.##.###...#.##.###... +.....#.##.#.#.#.#########..#.###...#.#.#.##.#.#.#.#.##.#.##.#...#.##.#.##..##.#.#.#.####.#..##.##.##.##.##.###...#.##.###.. +......#.#.######..#######.#.#.###...#####.#.########.#.##.#.##...#.#.##.#...#.######..#..##..##.##.##.##.##.###...#.##.###. diff --git a/2018/day-12/output/500-generations.png b/2018/day-12/output/500-generations.png new file mode 100644 index 0000000..c9412e1 Binary files /dev/null and b/2018/day-12/output/500-generations.png differ diff --git a/2018/day-12/output/500-generations.txt b/2018/day-12/output/500-generations.txt new file mode 100644 index 0000000..b8514a9 --- /dev/null +++ b/2018/day-12/output/500-generations.txt @@ -0,0 +1,22 @@ +Generating 20 generations from the input looks like this: +..#...#...##..####..##.####.#...#...#.#.#.#......##....#....######.####.##..#..#..##.##..##....#######..................... +..##..##.#.#....##...##..#..##..##...#######....#.##...##..#..###.#..#.#.#.######..##.#...##..#..######.................... +.#.#...#.####..#.##.#.#.###..#...##.#..######....#.##.#.#.###..#..###.#####..####...#.##.#.#.###...#####................... +..###...#..##.#.#.#.####.##.###.#.#.##...#####....#.#.####.##.###..#.#..###....###...#.#.####.###.#..####.................. +.#.###..##..#.######..#.#.##.#..####.##.#..####....###..#.#.##.##.#.###..###..#.###...###..#.#.#..##...###................. +..#.##...#.#.#..####.#.###.#.##...#.#.#.##...###..#.##.#.###.##.#.##.##...##.#.#.###.#.##.#.#####..##.#.###................ +...#.##...#####...#..##.#..##.##...#####.##.#.##.#.#.#.##.#.#.#.##.##.##.#.#.####.#..##.#.##..###...#.##.###............... +....#.##.#..####..##..#.##..##.##.#..##.#.#.##.#.######.#.######.##.##.#.####..#..##..#.##.#...###...#.##.###.............. +.....#.#.##...##...#.#.#.#...##.#.##..#.####.#.##..###..##..###.#.##.#.##..##.###..#.#.#.#.##.#.###...#.##.###............. +......###.##.#.##...#######.#.#.##.#.#.#..#..##.#...##...#...#..##.#.##.#...##.##.#.#######.#.##.###...#.##.###............ +.....#.#.#.#.##.##.#..####..####.#.#########..#.##.#.##..##..##..#.##.#.##.#.##.#.##..####..##.##.###...#.##.###........... +......#######.##.#.##...##....#..##..#######.#.#.#.##.#...#...#.#.#.#.##.#.##.#.##.#....##...##.##.###...#.##.###.......... +.....#..####.#.#.##.##.#.##...##..#....####..######.#.##..##...#######.#.##.#.##.#.##..#.##.#.##.##.###...#.##.###......... +.....##...#..####.##.#.##.##.#.#.###..#..##....###..##.#...##.#..####..##.#.##.#.##.#.#.#.#.##.##.##.###...#.##.###........ +....#.##..##...#.#.#.##.##.#.####.##.###..##..#.##...#.##.#.#.##...##...#.##.#.##.#.########.##.##.##.###...#.##.###....... +.....#.#...##...#####.##.#.##..#.#.##.##...#.#.#.##...#.#.####.##.#.##...#.#.##.#.##..#####.#.##.##.##.###...#.##.###...... +......###.#.##.#..##.#.#.##.#.#.###.##.##...#####.##...###..#.#.#.##.##...###.#.##.#....##..##.##.##.##.###...#.##.###..... +.....#.#..##.#.##..#.####.#.####.#.#.##.##.#..##.#.##.#.##.#.#####.##.##.#.#..##.#.##..#.#...##.##.##.##.###...#.##.###.... +......###..#.##.#.#.#..#..##..#..####.##.#.##..#.##.#.##.#.##..##.#.##.#.####..#.##.#.#.###.#.##.##.##.##.###...#.##.###... +.....#.##.#.#.#.#########..#.###...#.#.#.##.#.#.#.#.##.#.##.#...#.##.#.##..##.#.#.#.####.#..##.##.##.##.##.###...#.##.###.. +......#.#.######..#######.#.#.###...#####.#.########.#.##.#.##...#.#.##.#...#.######..#..##..##.##.##.##.##.###...#.##.###. diff --git a/2018/day-12/solution.js b/2018/day-12/solution.js index c2d7ef0..2bcc025 100644 --- a/2018/day-12/solution.js +++ b/2018/day-12/solution.js @@ -10,7 +10,7 @@ const initialState = '#...#...##..####..##.####.#...#...#.#.#.#......##....#.... const init = (data) => { const rules = data - const plantTracker = new Plants(initialState, rules) + let plantTracker = new Plants(initialState, rules) const generations = 20 for (let gen = 1; gen <= generations; gen++) { plantTracker.advance() @@ -18,7 +18,47 @@ const init = (data) => { console.log(`Generating ${generations} generations from the input looks like this:`) plantTracker.display() const answer = plantTracker.getCheckSum(generations) - const answer2 = '' + + // Start for part 2 + const generations2 = 500 + for (let gen = generations + 1; gen <= generations2; gen++) { + plantTracker.advance() + } + console.log(`Generating ${generations2} generations from the input looks like this:`) + plantTracker.display() + + // 500 generations takes about 30s, so running 50B generations isn't possible. It's + // clear looking at the log there's a "Game of Life"-style glider. + // See output/500-generations.txt and output/500-generations.png + // This probably is reflected in a pattern in the checksum. + let prevCheckSum = 0 + let prevDelta = 0 + const stableThreshold = 5 // The number of sequentially identical deltas necessary to determine stabilization + const stableDeltas = Array(stableThreshold).fill(0) + let stableGeneration = 0 + let stableCheckSum = 0 + for (let gen = 0; gen <= generations2; gen++) { + const checkSum = plantTracker.getCheckSum(gen) + const delta = checkSum - prevCheckSum + console.log(`Generation ${gen} checksum: ${plantTracker.getCheckSum(gen)} which is Δ of ${delta})`) + + // When delta matches previous generation, we may have reached stabilization + if (delta === prevDelta) { + stableDeltas.shift() + stableDeltas.push(delta) + // Reached true stable point when there are N deltas in a row that are the same. + if (stableDeltas.filter((Δ) => Δ === delta).length === stableDeltas.length) { + stableCheckSum = checkSum + stableGeneration = gen + break + } + } + prevCheckSum = checkSum + prevDelta = delta + } + console.log(`At generation ${stableGeneration} the Δ is ${stableDeltas[0]} and the checksum is ${stableCheckSum}.`) + // Calculate the checksum for 50B generations (minus the generation we're already at) + const answer2 = (stableDeltas[0] * (50000000000 - stableGeneration - 1)) + stableCheckSum console.log(`-- Part 1 --`) console.log(`Answer: ${answer}`) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy