Skip to content

Commit 6cbd22d

Browse files
feat(2018 day-12): initialize plant states
1 parent 9e63219 commit 6cbd22d

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

2018/day-12/plants.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Plants {
2+
constructor (initial) {
3+
this.generations = []
4+
this._setInitialGeneration(initial)
5+
}
6+
7+
_setInitialGeneration (initial) {
8+
this.generations.push(
9+
initial.split('').map((plant, idx) => {
10+
return {
11+
position: idx,
12+
state: plant
13+
}
14+
})
15+
)
16+
}
17+
}
18+
19+
module.exports = {
20+
Plants
21+
}

2018/day-12/plants.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* eslint-env mocha */
2+
const expect = require('chai').expect
3+
const {
4+
Plants
5+
} = require('./plants')
6+
7+
const initialState = '#..#.#..##......###...###'
8+
9+
describe('--- Day 12: Subterranean Sustainability ---', () => {
10+
describe('Plants:', () => {
11+
describe('new Plants()', () => {
12+
it('creates a Plants object with the initial state', () => {
13+
const expected = [
14+
{ position: 0, state: '#' },
15+
{ position: 1, state: '.' },
16+
{ position: 2, state: '.' },
17+
{ position: 3, state: '#' },
18+
{ position: 4, state: '.' },
19+
{ position: 5, state: '#' },
20+
{ position: 6, state: '.' },
21+
{ position: 7, state: '.' },
22+
{ position: 8, state: '#' },
23+
{ position: 9, state: '#' },
24+
{ position: 10, state: '.' },
25+
{ position: 11, state: '.' },
26+
{ position: 12, state: '.' },
27+
{ position: 13, state: '.' },
28+
{ position: 14, state: '.' },
29+
{ position: 15, state: '.' },
30+
{ position: 16, state: '#' },
31+
{ position: 17, state: '#' },
32+
{ position: 18, state: '#' },
33+
{ position: 19, state: '.' },
34+
{ position: 20, state: '.' },
35+
{ position: 21, state: '.' },
36+
{ position: 22, state: '#' },
37+
{ position: 23, state: '#' },
38+
{ position: 24, state: '#' }
39+
]
40+
let plantTracker = new Plants(initialState)
41+
const actual = plantTracker.generations[0]
42+
expect(actual).to.deep.equal(expected)
43+
})
44+
})
45+
})
46+
})

2018/day-12/solution.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// const {
2+
// parseLine
3+
// } = require('./helpers')
4+
const {
5+
Plants
6+
} = require('./plants')
7+
8+
const initialState = '#..#.#..##......###...###'
9+
const plantTracker = new Plants(initialState)
10+
11+
console.log(plantTracker.generations[0])

0 commit comments

Comments
 (0)