File tree Expand file tree Collapse file tree 3 files changed +51
-20
lines changed
Expand file tree Collapse file tree 3 files changed +51
-20
lines changed Original file line number Diff line number Diff line change 11const { listToProps } = require ( '../day-10/helpers' )
2+ const fs = require ( 'fs' )
3+ const path = require ( 'path' )
4+ const filePath = path . join ( __dirname , 'input.txt' )
5+ const { linesToArray } = require ( '../inputParser' )
6+
7+ const loadInput = ( callback ) => {
8+ fs . readFile ( filePath , { encoding : 'utf8' } , ( err , data ) => {
9+ if ( err ) throw err
10+
11+ const list = linesToArray ( data ) . map ( parseLine )
12+ if ( typeof callback === 'function' ) {
13+ callback ( list )
14+ }
15+ } )
16+ }
217
318/**
419 * Parses a line from the input into structured data
@@ -10,5 +25,6 @@ const parseLine = (input) => {
1025}
1126
1227module . exports = {
28+ loadInput,
1329 parseLine
1430}
Original file line number Diff line number Diff line change 1+ ...## => #
2+ ..#.. => #
3+ .#... => #
4+ .#.#. => #
5+ .#.## => #
6+ .##.. => #
7+ .#### => #
8+ #.#.# => #
9+ #.### => #
10+ ##.#. => #
11+ ##.## => #
12+ ###.. => #
13+ ###.# => #
14+ ####. => #
Original file line number Diff line number Diff line change 11const {
2- parseLine
2+ loadInput
33} = require ( './helpers' )
44const {
55 Plants
66} = require ( './plants' )
77
8- const initialState = '#..#.#..##......###...###'
9- const rules = ` ...## => #
10- ..#.. => #
11- .#... => #
12- .#.#. => #
13- .#.## => #
14- .##.. => #
15- .#### => #
16- #.#.# => #
17- #.### => #
18- ##.#. => #
19- ##.## => #
20- ###.. => #
21- ###.# => #
22- ####. => #` . split ( '\n' ) . map ( parseLine )
23- const plantTracker = new Plants ( initialState , rules )
24- for ( let gen = 1 ; gen <= 20 ; gen ++ ) {
25- plantTracker . advance ( )
8+ // Initial state from my puzzle input
9+ const initialState = '# ...#...##..####..##.####.#...#...#.#.#.#......##....#....######.####.##..#..#..##.##..##....#######'
10+
11+ const init = ( data ) => {
12+ const rules = data
13+ const plantTracker = new Plants ( initialState , rules )
14+ for ( let gen = 1 ; gen <= 20 ; gen ++ ) {
15+ plantTracker . advance ( )
16+ }
17+ console . log ( 'Generating 20 generations from the input looks like this:' )
18+ plantTracker . display ( )
19+ const answer = plantTracker . getCheckSum ( 20 )
20+ const answer2 = ''
21+
22+ console . log ( `-- Part 1 --` )
23+ console . log ( `Answer: ${ answer } ` )
24+ console . log ( `-- Part 2 --` )
25+ console . log ( `Answer: ${ answer2 } ` )
2626}
27- plantTracker . display ( )
27+
28+ loadInput ( init )
You can’t perform that action at this time.
0 commit comments