diff --git a/out.js b/out.js index b047a68..4f8f95a 100644 --- a/out.js +++ b/out.js @@ -1242,6 +1242,21 @@ utils = { if (typeof window == "undefined" && process.argv[2] == "test") { const fs = require("fs") + function test(name, answer, func, ...args) { + console.time(name) + let res = func(...args) + console.timeEnd(name) + + console.log(`${name}: Got ${res}, expected ${answer}`) + + if (res == answer) { + console.log(`${name}: SUCCESS`) + } else { + console.error(`${name}: FAIL`) + process.exit(1) + } + } + const year = "2021" for (let i = +process.argv[3] || 1; i <= 25; i++) { @@ -1249,28 +1264,11 @@ if (typeof window == "undefined" && process.argv[2] == "test") { const input = fs.readFileSync(`./${year}/inputs/${i}`, "utf8") const answers = fs.readFileSync(`./${year}/answers/${i}`, "utf8").split("\n-----\n") - let res = func(input, false) - - console.log(`${year} day ${i} part 1: Got ${res}, expected ${answers[0]}`) - - if (res == answers[0]) { - console.log(`${year} day ${i} part 1: SUCCESS`) - } else { - console.error(`${year} day ${i} part 1: FAIL`) - process.exit(1) - } - if (i != 25) { - res = func(input, true) - - console.log(`${year} day ${i} part 2: Got ${res}, expected ${answers[1]}`) - - if (res == answers[1]) { - console.log(`${year} day ${i} part 2: SUCCESS`) - } else { - console.error(`${year} day ${i} part 2: FAIL`) - process.exit(1) - } + test(`${year} day ${i} part 1`, answers[0], func, input, false) + test(`${year} day ${i} part 2`, answers[1], func, input, true) + } else { + test(`${year} day ${i}`, answers[0], func, input) } } } diff --git a/out.txt b/out.txt new file mode 100644 index 0000000..cad4de8 --- /dev/null +++ b/out.txt @@ -0,0 +1,1703 @@ +2021 day 1 part 1: 0.658ms +2021 day 1 part 1: Got 1292, expected 1292 +2021 day 1 part 1: SUCCESS +2021 day 1 part 2: 0.469ms +2021 day 1 part 2: Got 1262, expected 1262 +2021 day 1 part 2: SUCCESS +2021 day 2 part 1: 1.951ms +2021 day 2 part 1: Got 1813801, expected 1813801 +2021 day 2 part 1: SUCCESS +2021 day 2 part 2: 2.567ms +2021 day 2 part 2: Got 1960569556, expected 1960569556 +2021 day 2 part 2: SUCCESS +2021 day 3 part 1: 15.677ms +2021 day 3 part 1: Got 3882564, expected 3882564 +2021 day 3 part 1: SUCCESS +2021 day 3 part 2: 7.946ms +2021 day 3 part 2: Got 3385170, expected 3385170 +2021 day 3 part 2: SUCCESS +2021 day 4 part 1: 23.222ms +2021 day 4 part 1: Got 54275, expected 54275 +2021 day 4 part 1: SUCCESS +2021 day 4 part 2: 12.334ms +2021 day 4 part 2: Got 13158, expected 13158 +2021 day 4 part 2: SUCCESS +2021 day 5 part 1: 375.817ms +2021 day 5 part 1: Got 6856, expected 6856 +2021 day 5 part 1: SUCCESS +2021 day 5 part 2: 580.205ms +2021 day 5 part 2: Got 20666, expected 20666 +2021 day 5 part 2: SUCCESS +2021 day 6 part 1: 0.237ms +2021 day 6 part 1: Got 353274, expected 353274 +2021 day 6 part 1: SUCCESS +2021 day 6 part 2: 0.167ms +2021 day 6 part 2: Got 1609314870967, expected 1609314870967 +2021 day 6 part 2: SUCCESS +2021 day 7 part 1: 99.013ms +2021 day 7 part 1: Got 347011, expected 347011 +2021 day 7 part 1: SUCCESS +2021 day 7 part 2: 78.519ms +2021 day 7 part 2: Got 98363777, expected 98363777 +2021 day 7 part 2: SUCCESS +2021 day 8 part 1: 3.902ms +2021 day 8 part 1: Got 525, expected 525 +2021 day 8 part 1: SUCCESS +2021 day 8 part 2: 10.451ms +2021 day 8 part 2: Got 1083859, expected 1083859 +2021 day 8 part 2: SUCCESS +2021 day 9 part 1: 62.451ms +2021 day 9 part 1: Got 585, expected 585 +2021 day 9 part 1: SUCCESS +2021 day 9 part 2: 278.819ms +2021 day 9 part 2: Got 827904, expected 827904 +2021 day 9 part 2: SUCCESS +2021 day 10 part 1: 3.629ms +2021 day 10 part 1: Got 469755, expected 469755 +2021 day 10 part 1: SUCCESS +2021 day 10 part 2: 2.604ms +2021 day 10 part 2: Got 2762335572, expected 2762335572 +2021 day 10 part 2: SUCCESS +2021 day 11 part 1: 27.719ms +2021 day 11 part 1: Got 1691, expected 1691 +2021 day 11 part 1: SUCCESS +2021 day 11 part 2: 31.766ms +2021 day 11 part 2: Got 216, expected 216 +2021 day 11 part 2: SUCCESS +2021 day 12 part 1: 62.505ms +2021 day 12 part 1: Got 4241, expected 4241 +2021 day 12 part 1: SUCCESS +2021 day 12 part 2: 1.964s +2021 day 12 part 2: Got 122134, expected 122134 +2021 day 12 part 2: SUCCESS +2021 day 13 part 1: 24.749ms +2021 day 13 part 1: Got 695, expected 695 +2021 day 13 part 1: SUCCESS +2021 day 13 part 2: 77.991ms +2021 day 13 part 2: Got ## ## #### ## # # # ### ## +# # # # # # # # # # # # +# # # # # # # # # # +# ## # # # ## # # # ### # +# # # # # # # # # # # # # + ### ## #### ### #### ## # ## , expected ## ## #### ## # # # ### ## +# # # # # # # # # # # # +# # # # # # # # # # +# ## # # # ## # # # ### # +# # # # # # # # # # # # # + ### ## #### ### #### ## # ## +2021 day 13 part 2: SUCCESS +2021 day 14 part 1: 2.116ms +2021 day 14 part 1: Got 2068, expected 2068 +2021 day 14 part 1: SUCCESS +2021 day 14 part 2: 4.458ms +2021 day 14 part 2: Got 2158894777814, expected 2158894777814 +2021 day 14 part 2: SUCCESS +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +99 +98 +97 +96 +95 +94 +93 +92 +91 +90 +89 +88 +87 +86 +85 +84 +83 +82 +81 +80 +79 +78 +77 +76 +75 +74 +73 +72 +71 +70 +69 +68 +67 +66 +65 +64 +63 +62 +61 +60 +59 +58 +57 +56 +55 +54 +53 +52 +51 +50 +49 +48 +47 +46 +45 +44 +43 +42 +41 +40 +39 +38 +37 +36 +35 +34 +33 +32 +31 +30 +29 +28 +27 +26 +25 +24 +23 +22 +21 +20 +19 +18 +17 +16 +15 +14 +13 +12 +11 +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 +0 +heap gen: 34.92ms +9000 +8000 +7000 +6000 +5000 +4000 +3000 +2000 +1000 +search: 69.697ms +2021 day 15 part 1: 184.613ms +2021 day 15 part 1: Got 498, expected 498 +2021 day 15 part 1: SUCCESS +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 +100 +101 +102 +103 +104 +105 +106 +107 +108 +109 +110 +111 +112 +113 +114 +115 +116 +117 +118 +119 +120 +121 +122 +123 +124 +125 +126 +127 +128 +129 +130 +131 +132 +133 +134 +135 +136 +137 +138 +139 +140 +141 +142 +143 +144 +145 +146 +147 +148 +149 +150 +151 +152 +153 +154 +155 +156 +157 +158 +159 +160 +161 +162 +163 +164 +165 +166 +167 +168 +169 +170 +171 +172 +173 +174 +175 +176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232 +233 +234 +235 +236 +237 +238 +239 +240 +241 +242 +243 +244 +245 +246 +247 +248 +249 +250 +251 +252 +253 +254 +255 +256 +257 +258 +259 +260 +261 +262 +263 +264 +265 +266 +267 +268 +269 +270 +271 +272 +273 +274 +275 +276 +277 +278 +279 +280 +281 +282 +283 +284 +285 +286 +287 +288 +289 +290 +291 +292 +293 +294 +295 +296 +297 +298 +299 +300 +301 +302 +303 +304 +305 +306 +307 +308 +309 +310 +311 +312 +313 +314 +315 +316 +317 +318 +319 +320 +321 +322 +323 +324 +325 +326 +327 +328 +329 +330 +331 +332 +333 +334 +335 +336 +337 +338 +339 +340 +341 +342 +343 +344 +345 +346 +347 +348 +349 +350 +351 +352 +353 +354 +355 +356 +357 +358 +359 +360 +361 +362 +363 +364 +365 +366 +367 +368 +369 +370 +371 +372 +373 +374 +375 +376 +377 +378 +379 +380 +381 +382 +383 +384 +385 +386 +387 +388 +389 +390 +391 +392 +393 +394 +395 +396 +397 +398 +399 +400 +401 +402 +403 +404 +405 +406 +407 +408 +409 +410 +411 +412 +413 +414 +415 +416 +417 +418 +419 +420 +421 +422 +423 +424 +425 +426 +427 +428 +429 +430 +431 +432 +433 +434 +435 +436 +437 +438 +439 +440 +441 +442 +443 +444 +445 +446 +447 +448 +449 +450 +451 +452 +453 +454 +455 +456 +457 +458 +459 +460 +461 +462 +463 +464 +465 +466 +467 +468 +469 +470 +471 +472 +473 +474 +475 +476 +477 +478 +479 +480 +481 +482 +483 +484 +485 +486 +487 +488 +489 +490 +491 +492 +493 +494 +495 +496 +497 +498 +499 +500 +499 +498 +497 +496 +495 +494 +493 +492 +491 +490 +489 +488 +487 +486 +485 +484 +483 +482 +481 +480 +479 +478 +477 +476 +475 +474 +473 +472 +471 +470 +469 +468 +467 +466 +465 +464 +463 +462 +461 +460 +459 +458 +457 +456 +455 +454 +453 +452 +451 +450 +449 +448 +447 +446 +445 +444 +443 +442 +441 +440 +439 +438 +437 +436 +435 +434 +433 +432 +431 +430 +429 +428 +427 +426 +425 +424 +423 +422 +421 +420 +419 +418 +417 +416 +415 +414 +413 +412 +411 +410 +409 +408 +407 +406 +405 +404 +403 +402 +401 +400 +399 +398 +397 +396 +395 +394 +393 +392 +391 +390 +389 +388 +387 +386 +385 +384 +383 +382 +381 +380 +379 +378 +377 +376 +375 +374 +373 +372 +371 +370 +369 +368 +367 +366 +365 +364 +363 +362 +361 +360 +359 +358 +357 +356 +355 +354 +353 +352 +351 +350 +349 +348 +347 +346 +345 +344 +343 +342 +341 +340 +339 +338 +337 +336 +335 +334 +333 +332 +331 +330 +329 +328 +327 +326 +325 +324 +323 +322 +321 +320 +319 +318 +317 +316 +315 +314 +313 +312 +311 +310 +309 +308 +307 +306 +305 +304 +303 +302 +301 +300 +299 +298 +297 +296 +295 +294 +293 +292 +291 +290 +289 +288 +287 +286 +285 +284 +283 +282 +281 +280 +279 +278 +277 +276 +275 +274 +273 +272 +271 +270 +269 +268 +267 +266 +265 +264 +263 +262 +261 +260 +259 +258 +257 +256 +255 +254 +253 +252 +251 +250 +249 +248 +247 +246 +245 +244 +243 +242 +241 +240 +239 +238 +237 +236 +235 +234 +233 +232 +231 +230 +229 +228 +227 +226 +225 +224 +223 +222 +221 +220 +219 +218 +217 +216 +215 +214 +213 +212 +211 +210 +209 +208 +207 +206 +205 +204 +203 +202 +201 +200 +199 +198 +197 +196 +195 +194 +193 +192 +191 +190 +189 +188 +187 +186 +185 +184 +183 +182 +181 +180 +179 +178 +177 +176 +175 +174 +173 +172 +171 +170 +169 +168 +167 +166 +165 +164 +163 +162 +161 +160 +159 +158 +157 +156 +155 +154 +153 +152 +151 +150 +149 +148 +147 +146 +145 +144 +143 +142 +141 +140 +139 +138 +137 +136 +135 +134 +133 +132 +131 +130 +129 +128 +127 +126 +125 +124 +123 +122 +121 +120 +119 +118 +117 +116 +115 +114 +113 +112 +111 +110 +109 +108 +107 +106 +105 +104 +103 +102 +101 +100 +99 +98 +97 +96 +95 +94 +93 +92 +91 +90 +89 +88 +87 +86 +85 +84 +83 +82 +81 +80 +79 +78 +77 +76 +75 +74 +73 +72 +71 +70 +69 +68 +67 +66 +65 +64 +63 +62 +61 +60 +59 +58 +57 +56 +55 +54 +53 +52 +51 +50 +49 +48 +47 +46 +45 +44 +43 +42 +41 +40 +39 +38 +37 +36 +35 +34 +33 +32 +31 +30 +29 +28 +27 +26 +25 +24 +23 +22 +21 +20 +19 +18 +17 +16 +15 +14 +13 +12 +11 +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 +0 +heap gen: 568.484ms +249000 +248000 +247000 +246000 +245000 +244000 +243000 +242000 +241000 +240000 +239000 +238000 +237000 +236000 +235000 +234000 +233000 +232000 +231000 +230000 +229000 +228000 +227000 +226000 +225000 +224000 +223000 +222000 +221000 +220000 +219000 +218000 +217000 +216000 +215000 +214000 +213000 +212000 +211000 +210000 +209000 +208000 +207000 +206000 +205000 +204000 +203000 +202000 +201000 +200000 +199000 +198000 +197000 +196000 +195000 +194000 +193000 +192000 +191000 +190000 +189000 +188000 +187000 +186000 +185000 +184000 +183000 +182000 +181000 +180000 +179000 +178000 +177000 +176000 +175000 +174000 +173000 +172000 +171000 +170000 +169000 +168000 +167000 +166000 +165000 +164000 +163000 +162000 +161000 +160000 +159000 +158000 +157000 +156000 +155000 +154000 +153000 +152000 +151000 +150000 +149000 +148000 +147000 +146000 +145000 +144000 +143000 +142000 +141000 +140000 +139000 +138000 +137000 +136000 +135000 +134000 +133000 +132000 +131000 +130000 +129000 +128000 +127000 +126000 +125000 +124000 +123000 +122000 +121000 +120000 +119000 +118000 +117000 +116000 +115000 +114000 +113000 +112000 +111000 +110000 +109000 +108000 +107000 +106000 +105000 +104000 +103000 +102000 +101000 +100000 +99000 +98000 +97000 +96000 +95000 +94000 +93000 +92000 +91000 +90000 +89000 +88000 +87000 +86000 +85000 +84000 +83000 +82000 +81000 +80000 +79000 +78000 +77000 +76000 +75000 +74000 +73000 +72000 +71000 +70000 +69000 +68000 +67000 +66000 +65000 +64000 +63000 +62000 +61000 +60000 +59000 +58000 +57000 +56000 +55000 +54000 +53000 +52000 +51000 +50000 +49000 +48000 +47000 +46000 +45000 +44000 +43000 +42000 +41000 +40000 +39000 +38000 +37000 +36000 +35000 +34000 +33000 +32000 +31000 +30000 +29000 +28000 +27000 +26000 +25000 +24000 +23000 +22000 +21000 +20000 +19000 +18000 +17000 +16000 +15000 +14000 +13000 +12000 +11000 +10000 +9000 +8000 +7000 +6000 +5000 +4000 +3000 +2000 +1000 +search: 16.241s +2021 day 15 part 2: 18.613s +2021 day 15 part 2: Got 2901, expected 2901 +2021 day 15 part 2: SUCCESS +2021 day 16 part 1: 34.339ms +2021 day 16 part 1: Got 1038, expected 1038 +2021 day 16 part 1: SUCCESS +2021 day 16 part 2: 18.058ms +2021 day 16 part 2: Got 246761930504, expected 246761930504 +2021 day 16 part 2: SUCCESS +2021 day 17 part 1: 65.675ms +2021 day 17 part 1: Got 4656, expected 4656 +2021 day 17 part 1: SUCCESS +2021 day 17 part 2: 55.43ms +2021 day 17 part 2: Got 1908, expected 1908 +2021 day 17 part 2: SUCCESS +2021 day 18 part 1: 23.883ms +2021 day 18 part 1: Got 3494, expected 3494 +2021 day 18 part 1: SUCCESS +2021 day 18 part 2: 236.218ms +2021 day 18 part 2: Got 4712, expected 4712 +2021 day 18 part 2: SUCCESS +linked 0<->5 (0 point 0 == 5 point 9 with rotation 8) +linked 5<->31 (5 point 0 == 31 point 5 with rotation 9) +linked 31<->14 (31 point 0 == 14 point 8 with rotation 11) +linked 14<->3 (14 point 4 == 3 point 11 with rotation 13) +linked 3<->10 (3 point 0 == 10 point 5 with rotation 15) +linked 10<->30 (10 point 0 == 30 point 16 with rotation 13) +linked 30<->8 (30 point 1 == 8 point 11 with rotation 16) +linked 30<->13 (30 point 1 == 13 point 23 with rotation 15) +linked 13<->4 (13 point 0 == 4 point 9 with rotation 19) +linked 4<->28 (4 point 0 == 28 point 9 with rotation 13) +linked 28<->20 (28 point 0 == 20 point 17 with rotation 22) +linked 20<->11 (20 point 0 == 11 point 18 with rotation 13) +linked 20<->18 (20 point 0 == 18 point 22 with rotation 10) +linked 18<->12 (18 point 3 == 12 point 24 with rotation 14) +linked 12<->16 (12 point 1 == 16 point 4 with rotation 6) +linked 16<->34 (16 point 1 == 34 point 25 with rotation 17) +linked 34<->2 (34 point 0 == 2 point 2 with rotation 3) +linked 2<->1 (2 point 1 == 1 point 15 with rotation 18) +linked 1<->33 (1 point 0 == 33 point 7 with rotation 4) +linked 12<->17 (12 point 1 == 17 point 10 with rotation 18) +linked 20<->32 (20 point 1 == 32 point 12 with rotation 12) +linked 32<->19 (32 point 0 == 19 point 5 with rotation 23) +linked 19<->23 (19 point 1 == 23 point 9 with rotation 2) +linked 19<->24 (19 point 1 == 24 point 4 with rotation 6) +linked 4<->7 (4 point 3 == 7 point 3 with rotation 7) +linked 7<->26 (7 point 3 == 26 point 16 with rotation 12) +linked 4<->22 (4 point 3 == 22 point 25 with rotation 19) +linked 3<->15 (3 point 0 == 15 point 15 with rotation 1) +linked 15<->27 (15 point 2 == 27 point 15 with rotation 20) +linked 27<->6 (27 point 0 == 6 point 7 with rotation 5) +linked 27<->35 (27 point 0 == 35 point 14 with rotation 20) +linked 35<->9 (35 point 0 == 9 point 11 with rotation 9) +linked 9<->25 (9 point 0 == 25 point 18 with rotation 5) +linked 25<->29 (25 point 0 == 29 point 7 with rotation 23) +linked 29<->21 (29 point 0 == 21 point 6 with rotation 3) +2021 day 19 part 1: 37.496s +2021 day 19 part 1: Got 447, expected 447 +2021 day 19 part 1: SUCCESS +linked 0<->5 (0 point 0 == 5 point 9 with rotation 8) +linked 5<->31 (5 point 0 == 31 point 5 with rotation 9) +linked 31<->14 (31 point 0 == 14 point 8 with rotation 11) +linked 14<->3 (14 point 4 == 3 point 11 with rotation 13) +linked 3<->10 (3 point 0 == 10 point 5 with rotation 15) +linked 10<->30 (10 point 0 == 30 point 16 with rotation 13) +linked 30<->8 (30 point 1 == 8 point 11 with rotation 16) +linked 30<->13 (30 point 1 == 13 point 23 with rotation 15) +linked 13<->4 (13 point 0 == 4 point 9 with rotation 19) +linked 4<->28 (4 point 0 == 28 point 9 with rotation 13) +linked 28<->20 (28 point 0 == 20 point 17 with rotation 22) +linked 20<->11 (20 point 0 == 11 point 18 with rotation 13) +linked 20<->18 (20 point 0 == 18 point 22 with rotation 10) +linked 18<->12 (18 point 3 == 12 point 24 with rotation 14) +linked 12<->16 (12 point 1 == 16 point 4 with rotation 6) +linked 16<->34 (16 point 1 == 34 point 25 with rotation 17) +linked 34<->2 (34 point 0 == 2 point 2 with rotation 3) +linked 2<->1 (2 point 1 == 1 point 15 with rotation 18) +linked 1<->33 (1 point 0 == 33 point 7 with rotation 4) +linked 12<->17 (12 point 1 == 17 point 10 with rotation 18) +linked 20<->32 (20 point 1 == 32 point 12 with rotation 12) +linked 32<->19 (32 point 0 == 19 point 5 with rotation 23) +linked 19<->23 (19 point 1 == 23 point 9 with rotation 2) +linked 19<->24 (19 point 1 == 24 point 4 with rotation 6) +linked 4<->7 (4 point 3 == 7 point 3 with rotation 7) +linked 7<->26 (7 point 3 == 26 point 16 with rotation 12) +linked 4<->22 (4 point 3 == 22 point 25 with rotation 19) +linked 3<->15 (3 point 0 == 15 point 15 with rotation 1) +linked 15<->27 (15 point 2 == 27 point 15 with rotation 20) +linked 27<->6 (27 point 0 == 6 point 7 with rotation 5) +linked 27<->35 (27 point 0 == 35 point 14 with rotation 20) +linked 35<->9 (35 point 0 == 9 point 11 with rotation 9) +linked 9<->25 (9 point 0 == 25 point 18 with rotation 5) +linked 25<->29 (25 point 0 == 29 point 7 with rotation 23) +linked 29<->21 (29 point 0 == 21 point 6 with rotation 3) +2021 day 19 part 2: 37.058s +2021 day 19 part 2: Got 15672, expected 15672 +2021 day 19 part 2: SUCCESS +2021 day 20 part 1: 88.768ms +2021 day 20 part 1: Got 4873, expected 4873 +2021 day 20 part 1: SUCCESS +2021 day 20 part 2: 1.912s +2021 day 20 part 2: Got 16394, expected 16394 +2021 day 20 part 2: SUCCESS +2021 day 21 part 1: 0.553ms +2021 day 21 part 1: Got 597600, expected 597600 +2021 day 21 part 1: SUCCESS +2021 day 21 part 2: 320.731ms +2021 day 21 part 2: Got 634769613696613, expected 634769613696613 +2021 day 21 part 2: SUCCESS +2021 day 22 part 1: 38.235ms +2021 day 22 part 1: Got 589411, expected 589411 +2021 day 22 part 1: SUCCESS +2021 day 22 part 2: 117.909ms +2021 day 22 part 2: Got 1130514303649907, expected 1130514303649907 +2021 day 22 part 2: SUCCESS +iteration 0 heap size 28 min energy 0 +iteration 10000 heap size 9147 min energy 4409 +iteration 20000 heap size 10357 min energy 6015 +iteration 30000 heap size 14414 min energy 7695 +iteration 40000 heap size 15108 min energy 8555 +iteration 50000 heap size 14881 min energy 9425 +iteration 60000 heap size 12860 min energy 10003 +2021 day 23 part 1: 2.509s +2021 day 23 part 1: Got 10607, expected 10607 +2021 day 23 part 1: SUCCESS +iteration 0 heap size 28 min energy 0 +iteration 10000 heap size 11415 min energy 4130 +iteration 20000 heap size 12145 min energy 5620 +iteration 30000 heap size 12156 min energy 6971 +iteration 40000 heap size 12984 min energy 8071 +iteration 50000 heap size 11889 min energy 9313 +iteration 60000 heap size 11552 min energy 10455 +iteration 70000 heap size 7414 min energy 12084 +iteration 80000 heap size 3371 min energy 14557 +2021 day 23 part 2: 2.632s +2021 day 23 part 2: Got 59071, expected 59071 +2021 day 23 part 2: SUCCESS +2021 day 24 part 1: 0.302ms +2021 day 24 part 1: Got 99691891979938, expected 99691891979938 +2021 day 24 part 1: SUCCESS +2021 day 24 part 2: 0.309ms +2021 day 24 part 2: Got 27141191213911, expected 27141191213911 +2021 day 24 part 2: SUCCESS +2021 day 25: 2.220s +2021 day 25: Got 534, expected 534 +2021 day 25: SUCCESS diff --git a/test.js b/test.js index 0804e60..20c34cf 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,21 @@ if (typeof window == "undefined" && process.argv[2] == "test") { const fs = require("fs") + function test(name, answer, func, ...args) { + console.time(name) + let res = func(...args) + console.timeEnd(name) + + console.log(`${name}: Got ${res}, expected ${answer}`) + + if (res == answer) { + console.log(`${name}: SUCCESS`) + } else { + console.error(`${name}: FAIL`) + process.exit(1) + } + } + const year = "2021" for (let i = +process.argv[3] || 1; i <= 25; i++) { @@ -8,28 +23,11 @@ if (typeof window == "undefined" && process.argv[2] == "test") { const input = fs.readFileSync(`./${year}/inputs/${i}`, "utf8") const answers = fs.readFileSync(`./${year}/answers/${i}`, "utf8").split("\n-----\n") - let res = func(input, false) - - console.log(`${year} day ${i} part 1: Got ${res}, expected ${answers[0]}`) - - if (res == answers[0]) { - console.log(`${year} day ${i} part 1: SUCCESS`) - } else { - console.error(`${year} day ${i} part 1: FAIL`) - process.exit(1) - } - if (i != 25) { - res = func(input, true) - - console.log(`${year} day ${i} part 2: Got ${res}, expected ${answers[1]}`) - - if (res == answers[1]) { - console.log(`${year} day ${i} part 2: SUCCESS`) - } else { - console.error(`${year} day ${i} part 2: FAIL`) - process.exit(1) - } + test(`${year} day ${i} part 1`, answers[0], func, input, false) + test(`${year} day ${i} part 2`, answers[1], func, input, true) + } else { + test(`${year} day ${i}`, answers[0], func, input) } } }