@@ -25,74 +25,139 @@ Blueprint 2: Each ore robot costs 2 ore.\
2525
2626const  lineTpl  =  tpl `\ 
2727Blueprint ${ "index|int" }  
28-  Each ore robot costs ${ "ao |int" }  
29-  Each clay robot costs ${ "bo |int" }  
30-  Each obsidian robot costs ${ "co |int" } ${ "cc |int" }  
31-  Each geode robot costs ${ "do |int" } ${ "dg |int" }  
28+  Each ore robot costs ${ "oreBotOre |int" }  
29+  Each clay robot costs ${ "clayBotOre |int" }  
30+  Each obsidian robot costs ${ "obsBotOre |int" } ${ "obsBotClay |int" }  
31+  Each geode robot costs ${ "geoBotOre |int" } ${ "geoBotObs |int" }  
3232` 
3333
3434/** 
3535 * 
36-  * @param  {ReturnType<typeof lineTpl> } p  
36+  * @param  {ReturnType<typeof lineTpl> } blueprint  
3737 * @param  {number } timeLeft 
3838 */ 
39- function  countGeodes ( p ,  timeLeft )  { 
40-  const  maxOreRobots  =  Math . max ( p . ao ,  p . bo ,  p . co ,  p . do ) 
41-  const  maxClayRobots  =  p . cc 
42-  const  maxObsidianRobots  =  p . dg 
39+ function  countGeodes ( blueprint ,  timeLeft )  { 
40+  const  maxOreRobots  =  Math . max ( 
41+  blueprint . oreBotOre , 
42+  blueprint . clayBotOre , 
43+  blueprint . obsBotOre , 
44+  blueprint . geoBotOre , 
45+  ) 
46+  const  maxClayRobots  =  blueprint . obsBotClay 
47+  const  maxObsidianRobots  =  blueprint . geoBotObs 
4348
4449 /** 
45-  * @param  {number } a  - ore robots 
46-  * @param  {number } b  - clay robots 
47-  * @param  {number } c  - obsidian robots 
48-  * @param  {number } d  - geode robots 
49-  * @param  {number } ar  - ore 
50-  * @param  {number } br  - clay 
51-  * @param  {number } or  - obsidian 
52-  * @param  {number } gr  - geode 
53-  * @param  {number } tp  - time passed 
54-  * @param  {number } t  - time total 
50+  * @param  {number } oreBots  - ore robots 
51+  * @param  {number } clayBots  - clay robots 
52+  * @param  {number } obsBots  - obsidian robots 
53+  * @param  {number } geoBots  - geode robots 
54+  * @param  {number } ore  - ore 
55+  * @param  {number } clay  - clay 
56+  * @param  {number } obs  - obsidian 
57+  * @param  {number } geode  - geode 
58+  * @param  {number } timePassed  - time passed 
59+  * @param  {number } timeTotal  - time total 
5560 */ 
56-  function  dfs ( a ,  b ,  c ,  d ,  ar ,  br ,  or ,  gr ,  tp ,  t )  { 
61+  function  dfs ( 
62+  oreBots , 
63+  clayBots , 
64+  obsBots , 
65+  geoBots , 
66+  ore , 
67+  clay , 
68+  obs , 
69+  geode , 
70+  timePassed , 
71+  timeTotal , 
72+  )  { 
5773 let  isOreRobotBuilt  =  false 
5874 let  isClayBotBuilt  =  false 
5975 let  isObsBotBuilt  =  false 
6076 let  isGeodeBotBuilt  =  false 
6177
62-  let  max  =  gr 
78+  let  max  =  geode 
6379
64-  for  ( let  i  =  tp ;  i  <  t ;  i ++ )  { 
65-  const  canBuildOreBot  =  p . ao  <=  ar 
66-  const  canBuildClayBot  =  p . bo  <=  ar 
67-  const  canBuildObsBot  =  p . co  <=  ar  &&  p . cc  <=  br 
68-  const  canBuildGeoBot  =  p . do  <=  ar  &&  p . dg  <=  or 
80+  for  ( let  i  =  timePassed ;  i  <  timeTotal ;  i ++ )  { 
81+  const  canBuildOreBot  =  blueprint . oreBotOre  <=  ore 
82+  const  canBuildClayBot  =  blueprint . clayBotOre  <=  ore 
83+  const  canBuildObsBot  = 
84+  blueprint . obsBotOre  <=  ore  &&  blueprint . obsBotClay  <=  clay 
85+  const  canBuildGeoBot  = 
86+  blueprint . geoBotOre  <=  ore  &&  blueprint . geoBotObs  <=  obs 
6987
70-  ; ( ar  +=  a ) ,  ( br  +=  b ) ,  ( or  +=  c ) ,  ( gr  +=  d ) 
88+  ore  +=  oreBots 
89+  clay  +=  clayBots 
90+  obs  +=  obsBots 
91+  geode  +=  geoBots 
7192
7293 if  ( canBuildGeoBot  &&  ! isGeodeBotBuilt )  { 
73-  const  r  =  dfs ( a ,  b ,  c ,  d  +  1 ,  ar  -  p . do ,  br ,  or  -  p . dg ,  gr ,  i  +  1 ,  t ) 
94+  const  r  =  dfs ( 
95+  oreBots , 
96+  clayBots , 
97+  obsBots , 
98+  geoBots  +  1 , 
99+  ore  -  blueprint . geoBotOre , 
100+  clay , 
101+  obs  -  blueprint . geoBotObs , 
102+  geode , 
103+  i  +  1 , 
104+  timeTotal , 
105+  ) 
74106 max  =  Math . max ( max ,  r ) 
75107 isGeodeBotBuilt  =  true 
76108 continue 
77109 } 
78-  if  ( canBuildObsBot  &&  ! isObsBotBuilt  &&  c  <  maxObsidianRobots )  { 
79-  const  r  =  dfs ( a ,  b ,  c  +  1 ,  d ,  ar  -  p . co ,  br  -  p . cc ,  or ,  gr ,  i  +  1 ,  t ) 
110+  if  ( canBuildObsBot  &&  ! isObsBotBuilt  &&  obsBots  <  maxObsidianRobots )  { 
111+  const  r  =  dfs ( 
112+  oreBots , 
113+  clayBots , 
114+  obsBots  +  1 , 
115+  geoBots , 
116+  ore  -  blueprint . obsBotOre , 
117+  clay  -  blueprint . obsBotClay , 
118+  obs , 
119+  geode , 
120+  i  +  1 , 
121+  timeTotal , 
122+  ) 
80123 max  =  Math . max ( max ,  r ) 
81124 isObsBotBuilt  =  true 
82125 continue 
83126 } 
84-  if  ( canBuildClayBot  &&  ! isClayBotBuilt  &&  b  <  maxClayRobots )  { 
85-  const  r  =  dfs ( a ,  b  +  1 ,  c ,  d ,  ar  -  p . bo ,  br ,  or ,  gr ,  i  +  1 ,  t ) 
127+  if  ( canBuildClayBot  &&  ! isClayBotBuilt  &&  clayBots  <  maxClayRobots )  { 
128+  const  r  =  dfs ( 
129+  oreBots , 
130+  clayBots  +  1 , 
131+  obsBots , 
132+  geoBots , 
133+  ore  -  blueprint . clayBotOre , 
134+  clay , 
135+  obs , 
136+  geode , 
137+  i  +  1 , 
138+  timeTotal , 
139+  ) 
86140 max  =  Math . max ( max ,  r ) 
87141 isClayBotBuilt  =  true 
88142 } 
89-  if  ( canBuildOreBot  &&  ! isOreRobotBuilt  &&  a  <  maxOreRobots )  { 
90-  const  r  =  dfs ( a  +  1 ,  b ,  c ,  d ,  ar  -  p . ao ,  br ,  or ,  gr ,  i  +  1 ,  t ) 
143+  if  ( canBuildOreBot  &&  ! isOreRobotBuilt  &&  oreBots  <  maxOreRobots )  { 
144+  const  r  =  dfs ( 
145+  oreBots  +  1 , 
146+  clayBots , 
147+  obsBots , 
148+  geoBots , 
149+  ore  -  blueprint . oreBotOre , 
150+  clay , 
151+  obs , 
152+  geode , 
153+  i  +  1 , 
154+  timeTotal , 
155+  ) 
91156 max  =  Math . max ( max ,  r ) 
92157 isOreRobotBuilt  =  true 
93158 } 
94159
95-  max  =  Math . max ( max ,  gr ) 
160+  max  =  Math . max ( max ,  geode ) 
96161 } 
97162 return  max 
98163 } 
0 commit comments