@@ -10,13 +10,9 @@ const {
10
10
11
11
describe ( '--- Day 14: Chocolate Charts ---' , ( ) => {
12
12
let recipes
13
- let elves
14
13
describe ( 'Part 1:' , ( ) => {
15
14
beforeEach ( ( ) => {
16
- elves = [ 3 , 7 ]
17
- recipes = new Recipes ( elves )
18
- elves [ 0 ] = recipes . tail
19
- elves [ 1 ] = recipes . head
15
+ recipes = new Recipes ( [ 3 , 7 ] )
20
16
} )
21
17
describe ( 'new Recipes()' , ( ) => {
22
18
it ( 'builds a linked list' , ( ) => {
@@ -54,12 +50,10 @@ describe('--- Day 14: Chocolate Charts ---', () => {
54
50
describe ( 'loopRecipeForEleves()' , ( ) => {
55
51
it ( 'loops through the recipe object for the specified elves the specified number of times' , ( ) => {
56
52
const expected = '37101012451589167792' // list of recipe values in the last iteration of the example
57
- let actual = ''
58
-
59
- loopRecipesForElves ( elves , recipes , 15 )
60
53
54
+ loopRecipesForElves ( recipes , 15 )
55
+ let actual = recipes . tail . value . toString ( )
61
56
let iterator = recipes . tail . next
62
- actual += recipes . tail . value . toString ( )
63
57
while ( iterator !== recipes . tail ) {
64
58
actual += iterator . value . toString ( )
65
59
iterator = iterator . next
@@ -68,45 +62,49 @@ describe('--- Day 14: Chocolate Charts ---', () => {
68
62
expect ( expected ) . to . equal ( actual )
69
63
} )
70
64
} )
71
- describe ( 'calculateXAfterY(x, y, recipe, elves )' , ( ) => {
65
+ describe ( 'calculateXAfterY(x, y, recipe)' , ( ) => {
72
66
it ( 'predicts the next X results after the elves have executed Y' , ( ) => {
73
- let actual = calculateXAfterY ( 10 , 9 , recipes , elves )
67
+ let actual = calculateXAfterY ( 10 , 9 , recipes )
74
68
expect ( actual ) . to . equal ( '5158916779' )
75
69
} )
76
70
it ( 'predicts the next X results after the elves have executed Y' , ( ) => {
77
- const actual = calculateXAfterY ( 10 , 5 , recipes , elves )
71
+ const actual = calculateXAfterY ( 10 , 5 , recipes )
78
72
expect ( actual ) . to . equal ( '0124515891' )
79
73
} )
80
74
it ( 'predicts the next X results after the elves have executed Y' , ( ) => {
81
- const actual = calculateXAfterY ( 10 , 18 , recipes , elves )
75
+ const actual = calculateXAfterY ( 10 , 18 , recipes )
82
76
expect ( actual ) . to . equal ( '9251071085' )
83
77
} )
84
78
it ( 'predicts the next X results after the elves have executed Y' , ( ) => {
85
- const actual = calculateXAfterY ( 10 , 2018 , recipes , elves )
79
+ const actual = calculateXAfterY ( 10 , 2018 , recipes )
86
80
expect ( actual ) . to . equal ( '5941429882' )
87
81
} )
82
+ it ( 'positions results correctly if X triggers 2 recipes being added' , ( ) => {
83
+ let actual = calculateXAfterY ( 3 , 15 , recipes )
84
+ expect ( actual ) . to . equal ( '677' )
85
+ } )
88
86
} )
89
87
describe ( 'findPattern()' , ( ) => {
90
88
it ( 'counts the number of recipes to the left of the specified pattern' , ( ) => {
91
- const actual = findPattern ( '51589' , recipes , elves )
89
+ const actual = findPattern ( '51589' , recipes )
92
90
expect ( actual ) . to . equal ( 9 )
93
91
} )
94
92
} )
95
93
describe ( 'findPattern()' , ( ) => {
96
94
it ( 'counts the number of recipes to the left of the specified pattern' , ( ) => {
97
- const actual = findPattern ( '01245' , recipes , elves )
95
+ const actual = findPattern ( '01245' , recipes )
98
96
expect ( actual ) . to . equal ( 5 )
99
97
} )
100
98
} )
101
99
describe ( 'findPattern()' , ( ) => {
102
100
it ( 'counts the number of recipes to the left of the specified pattern' , ( ) => {
103
- const actual = findPattern ( '92510' , recipes , elves )
101
+ const actual = findPattern ( '92510' , recipes )
104
102
expect ( actual ) . to . equal ( 18 )
105
103
} )
106
104
} )
107
105
describe ( 'findPattern()' , ( ) => {
108
106
it ( 'counts the number of recipes to the left of the specified pattern' , ( ) => {
109
- const actual = findPattern ( '59414' , recipes , elves )
107
+ const actual = findPattern ( '59414' , recipes )
110
108
expect ( actual ) . to . equal ( 2018 )
111
109
} )
112
110
} )
0 commit comments