Skip to content

Feature/2018 day 12 part 2 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions 2018/day-12/20-generations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Generating 20 generations from the input looks like this:
..#...#...##..####..##.####.#...#...#.#.#.#......##....#....######.####.##..#..#..##.##..##....#######.....................
..##..##.#.#....##...##..#..##..##...#######....#.##...##..#..###.#..#.#.#.######..##.#...##..#..######....................
.#.#...#.####..#.##.#.#.###..#...##.#..######....#.##.#.#.###..#..###.#####..####...#.##.#.#.###...#####...................
..###...#..##.#.#.#.####.##.###.#.#.##...#####....#.#.####.##.###..#.#..###....###...#.#.####.###.#..####..................
.#.###..##..#.######..#.#.##.#..####.##.#..####....###..#.#.##.##.#.###..###..#.###...###..#.#.#..##...###.................
..#.##...#.#.#..####.#.###.#.##...#.#.#.##...###..#.##.#.###.##.#.##.##...##.#.#.###.#.##.#.#####..##.#.###................
...#.##...#####...#..##.#..##.##...#####.##.#.##.#.#.#.##.#.#.#.##.##.##.#.#.####.#..##.#.##..###...#.##.###...............
....#.##.#..####..##..#.##..##.##.#..##.#.#.##.#.######.#.######.##.##.#.####..#..##..#.##.#...###...#.##.###..............
.....#.#.##...##...#.#.#.#...##.#.##..#.####.#.##..###..##..###.#.##.#.##..##.###..#.#.#.#.##.#.###...#.##.###.............
......###.##.#.##...#######.#.#.##.#.#.#..#..##.#...##...#...#..##.#.##.#...##.##.#.#######.#.##.###...#.##.###............
.....#.#.#.#.##.##.#..####..####.#.#########..#.##.#.##..##..##..#.##.#.##.#.##.#.##..####..##.##.###...#.##.###...........
......#######.##.#.##...##....#..##..#######.#.#.#.##.#...#...#.#.#.#.##.#.##.#.##.#....##...##.##.###...#.##.###..........
.....#..####.#.#.##.##.#.##...##..#....####..######.#.##..##...#######.#.##.#.##.#.##..#.##.#.##.##.###...#.##.###.........
.....##...#..####.##.#.##.##.#.#.###..#..##....###..##.#...##.#..####..##.#.##.#.##.#.#.#.#.##.##.##.###...#.##.###........
....#.##..##...#.#.#.##.##.#.####.##.###..##..#.##...#.##.#.#.##...##...#.##.#.##.#.########.##.##.##.###...#.##.###.......
.....#.#...##...#####.##.#.##..#.#.##.##...#.#.#.##...#.#.####.##.#.##...#.#.##.#.##..#####.#.##.##.##.###...#.##.###......
......###.#.##.#..##.#.#.##.#.#.###.##.##...#####.##...###..#.#.#.##.##...###.#.##.#....##..##.##.##.##.###...#.##.###.....
.....#.#..##.#.##..#.####.#.####.#.#.##.##.#..##.#.##.#.##.#.#####.##.##.#.#..##.#.##..#.#...##.##.##.##.###...#.##.###....
......###..#.##.#.#.#..#..##..#..####.##.#.##..#.##.#.##.#.##..##.#.##.#.####..#.##.#.#.###.#.##.##.##.##.###...#.##.###...
.....#.##.#.#.#.#########..#.###...#.#.#.##.#.#.#.#.##.#.##.#...#.##.#.##..##.#.#.#.####.#..##.##.##.##.##.###...#.##.###..
......#.#.######..#######.#.#.###...#####.#.########.#.##.#.##...#.#.##.#...#.######..#..##..##.##.##.##.##.###...#.##.###.
Binary file added 2018/day-12/output/500-generations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions 2018/day-12/output/500-generations.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Generating 20 generations from the input looks like this:
..#...#...##..####..##.####.#...#...#.#.#.#......##....#....######.####.##..#..#..##.##..##....#######.....................
..##..##.#.#....##...##..#..##..##...#######....#.##...##..#..###.#..#.#.#.######..##.#...##..#..######....................
.#.#...#.####..#.##.#.#.###..#...##.#..######....#.##.#.#.###..#..###.#####..####...#.##.#.#.###...#####...................
..###...#..##.#.#.#.####.##.###.#.#.##...#####....#.#.####.##.###..#.#..###....###...#.#.####.###.#..####..................
.#.###..##..#.######..#.#.##.#..####.##.#..####....###..#.#.##.##.#.###..###..#.###...###..#.#.#..##...###.................
..#.##...#.#.#..####.#.###.#.##...#.#.#.##...###..#.##.#.###.##.#.##.##...##.#.#.###.#.##.#.#####..##.#.###................
...#.##...#####...#..##.#..##.##...#####.##.#.##.#.#.#.##.#.#.#.##.##.##.#.#.####.#..##.#.##..###...#.##.###...............
....#.##.#..####..##..#.##..##.##.#..##.#.#.##.#.######.#.######.##.##.#.####..#..##..#.##.#...###...#.##.###..............
.....#.#.##...##...#.#.#.#...##.#.##..#.####.#.##..###..##..###.#.##.#.##..##.###..#.#.#.#.##.#.###...#.##.###.............
......###.##.#.##...#######.#.#.##.#.#.#..#..##.#...##...#...#..##.#.##.#...##.##.#.#######.#.##.###...#.##.###............
.....#.#.#.#.##.##.#..####..####.#.#########..#.##.#.##..##..##..#.##.#.##.#.##.#.##..####..##.##.###...#.##.###...........
......#######.##.#.##...##....#..##..#######.#.#.#.##.#...#...#.#.#.#.##.#.##.#.##.#....##...##.##.###...#.##.###..........
.....#..####.#.#.##.##.#.##...##..#....####..######.#.##..##...#######.#.##.#.##.#.##..#.##.#.##.##.###...#.##.###.........
.....##...#..####.##.#.##.##.#.#.###..#..##....###..##.#...##.#..####..##.#.##.#.##.#.#.#.#.##.##.##.###...#.##.###........
....#.##..##...#.#.#.##.##.#.####.##.###..##..#.##...#.##.#.#.##...##...#.##.#.##.#.########.##.##.##.###...#.##.###.......
.....#.#...##...#####.##.#.##..#.#.##.##...#.#.#.##...#.#.####.##.#.##...#.#.##.#.##..#####.#.##.##.##.###...#.##.###......
......###.#.##.#..##.#.#.##.#.#.###.##.##...#####.##...###..#.#.#.##.##...###.#.##.#....##..##.##.##.##.###...#.##.###.....
.....#.#..##.#.##..#.####.#.####.#.#.##.##.#..##.#.##.#.##.#.#####.##.##.#.#..##.#.##..#.#...##.##.##.##.###...#.##.###....
......###..#.##.#.#.#..#..##..#..####.##.#.##..#.##.#.##.#.##..##.#.##.#.####..#.##.#.#.###.#.##.##.##.##.###...#.##.###...
.....#.##.#.#.#.#########..#.###...#.#.#.##.#.#.#.#.##.#.##.#...#.##.#.##..##.#.#.#.####.#..##.##.##.##.##.###...#.##.###..
......#.#.######..#######.#.#.###...#####.#.########.#.##.#.##...#.#.##.#...#.######..#..##..##.##.##.##.##.###...#.##.###.
44 changes: 42 additions & 2 deletions 2018/day-12/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,55 @@ 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()
}
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}`)
Expand Down
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