|
2 | 2 | const expect = require('chai').expect
|
3 | 3 | const {
|
4 | 4 | calculateXAfterY,
|
| 5 | + findPattern, |
5 | 6 | loopRecipesForElves,
|
6 | 7 | Recipes,
|
7 | 8 | totalDigitsInArray
|
@@ -136,5 +137,77 @@ describe('--- Day 14: Chocolate Charts ---', () => {
|
136 | 137 | expect(actual).to.equal('5941429882')
|
137 | 138 | })
|
138 | 139 | })
|
| 140 | + describe('findPattern()', () => { |
| 141 | + it('counts the number of recipes to the left of the specified pattern', () => { |
| 142 | + const elves = [3, 7] |
| 143 | + const recipes = new Recipes(elves[0]) |
| 144 | + let actual = '' |
| 145 | + |
| 146 | + elves.forEach((elf, idx) => { |
| 147 | + if (idx === 0) { |
| 148 | + elves[0] = recipes.head |
| 149 | + } else { |
| 150 | + elves[idx] = recipes.addRecipe(elf) |
| 151 | + } |
| 152 | + }) |
| 153 | + |
| 154 | + actual = findPattern('51589', recipes, elves) |
| 155 | + expect(actual).to.equal(9) |
| 156 | + }) |
| 157 | + }) |
| 158 | + describe('findPattern()', () => { |
| 159 | + it('counts the number of recipes to the left of the specified pattern', () => { |
| 160 | + const elves = [3, 7] |
| 161 | + const recipes = new Recipes(elves[0]) |
| 162 | + let actual = '' |
| 163 | + |
| 164 | + elves.forEach((elf, idx) => { |
| 165 | + if (idx === 0) { |
| 166 | + elves[0] = recipes.head |
| 167 | + } else { |
| 168 | + elves[idx] = recipes.addRecipe(elf) |
| 169 | + } |
| 170 | + }) |
| 171 | + |
| 172 | + actual = findPattern('01245', recipes, elves) |
| 173 | + expect(actual).to.equal(5) |
| 174 | + }) |
| 175 | + }) |
| 176 | + describe('findPattern()', () => { |
| 177 | + it('counts the number of recipes to the left of the specified pattern', () => { |
| 178 | + const elves = [3, 7] |
| 179 | + const recipes = new Recipes(elves[0]) |
| 180 | + let actual = '' |
| 181 | + |
| 182 | + elves.forEach((elf, idx) => { |
| 183 | + if (idx === 0) { |
| 184 | + elves[0] = recipes.head |
| 185 | + } else { |
| 186 | + elves[idx] = recipes.addRecipe(elf) |
| 187 | + } |
| 188 | + }) |
| 189 | + |
| 190 | + actual = findPattern('92510', recipes, elves) |
| 191 | + expect(actual).to.equal(18) |
| 192 | + }) |
| 193 | + }) |
| 194 | + describe('findPattern()', () => { |
| 195 | + it('counts the number of recipes to the left of the specified pattern', () => { |
| 196 | + const elves = [3, 7] |
| 197 | + const recipes = new Recipes(elves[0]) |
| 198 | + let actual = '' |
| 199 | + |
| 200 | + elves.forEach((elf, idx) => { |
| 201 | + if (idx === 0) { |
| 202 | + elves[0] = recipes.head |
| 203 | + } else { |
| 204 | + elves[idx] = recipes.addRecipe(elf) |
| 205 | + } |
| 206 | + }) |
| 207 | + |
| 208 | + actual = findPattern('59414', recipes, elves) |
| 209 | + expect(actual).to.equal(2018) |
| 210 | + }) |
| 211 | + }) |
139 | 212 | })
|
140 | 213 | })
|
0 commit comments