aoc/Dec03_Tmp/one.js

23 lines
20 KiB
JavaScript
Raw Normal View History

2024-12-18 12:49:31 +00:00
const input = JSON.stringify(")+when())~why(),),mul(712,171)@}-?}mul(506,85)who()%mul(613,601)/;#from()#mul(977,581)~what()?/$^-+(*mul(142,89)[who();*):*mul(64,644)}when()select()mul(652,872)mul(594,202)?%$when(196,699)mul(311,646)<>/how()where()(+:mul(867,971)}&where()'/&[&$mul(192,659)select();<#}mul(367,411)mul(841,862)when()(%!mul(922,272)^;}mul(593,223)mul(918,232)mul(760,145)]^?why()>mul(558,476)where()who()&do()^]($,~&-{where()mul(855,134),(--{mul(691,389)+mul(352,712)why()<(]'/}-mul(138,405)$where()mul(176,679) from()'!why(){:mul(516,55)%*>mul(97,636)mul(30,945)**~what()$,mul(486,399)# ,~~!]mul(277,667);~$[from()how()&mul(412,36)([@@,what()% mul(478,68)&mul(293,979)mul(218,379)~)'?-&from()@mul(887,161)(mul(156,481)who();&[:mul(308,96)mul(718,985),] when())/~>^$mul(84,469)*<where()how()[mul(257,600)<~mul(660,909)select()mul(510,180)what()mul(619,634)#mul(721,403)why()@!,~:>where()mul(500,291)who()])]*don't()who()select()^;,@mul(837,399)$(,(-who()}'mul(835,602)~:]mul(99,872)how()what()<select()how()(don't()[[@, ,mul(962,879)who()])mul(828,134)$where()when())>%{who(794,618)>mul(227,398)why()where()-why()what()^/:; mul(753,183)[{ ]#^#%%~mul(196,63)}%don't()who()$ :how(),select()~@mul(214,483),:select()%)}who()mul(198,36)*do()what()mul(330,804)what():+>mul(10,447)*/!mul(580,733):&where()'mul(247,9)$)[:#-select()?do()mul(157,768)why()/ who()$from()where()don't()mul(527,694){how(206,792)mul(314,331)/from()/what()#mul(49,792)',-(why()#/]mul(645,190)from()$?mul(775,2)!+select()+^]from(104,329)!mul(287,711)}select():){mul(770,682)!don't()! *^+ when()]%-mul(291,143)mul(956,213)[[>{%'#*{~mul(569,514)[}how()@;mul(291,643)what()%&-where()#@<mul(729,139){^mul(501,801)]mul(261,648)}+~>when()mul(678,494)>%mul(303?<%where()what()mul(601,775)mul(91,748)&why()mul(648,173)~*mul(101,949)*:}>'from()-what()^}mul(890,865)what()mul(398,428),select(261,665)where()when()+mul(315,619what()mul(301,311)^~ where(297,851)#{!+&:mul(548,329)mul(239,714)who()@why()(#+!select()why()do()when()mul(249,859)}<select()&mul(239,140{from(149,864)]#]*~ mul(382,788)select(519,600)select(),from()(mul(350,980)@([-,~~%select()mul(710,125)what()how()]-/where()from()%mul(621,643)+what()~!how()what(814,400)<>>@mul(174,437)how(131,486)mul(294,93)mul(605,381)@#}what():~mul(873,431)#)who()^<why()mul(463,819);mul(961,13)what()why(474,300)@}&!]mul(507,494)/@}mul(636,958)^ ~from();!where()how()mul(801,95#; ;<when()who()*(mul(539,800))don't()mul(361,163)>how()select()from()#mul(411,803)-(>why(){{mul(400,846)mul(705(~+%mul(235,314)how(),where()++<{mul(795,270)how()#? $'*select()mul(301,531)mul(109,954)/mul(451,416)%%!select()mul(834,747)%select()[ mul(457,765)do()when()@<!how()mul(520,202):where(41,552)!'&@-,$mul(493,844)-?'*what()when()<^mul(937,957)who()where()who()mul(301,646)/^select()#;how()}select()mul(954,724)mul(695,132))*%mul(976,455)when()**from()]what()@how()')mul(492,975);what();^''#/?~mul(258,829)#*how()#>mul(779,58)('who()mul(275,708)])$&mul(546,476)&]mul<}~mul(490,931) why()>~)from()@mul(302,82)mul(625,374)-;>%where()mul(864,633):!-,how()when()mul(748,5)what()!how(447,20)]what()/where()<'}don't()from()}why()mul(837,78)what()&:%where()?mul(402,690)mul(689,472)(:{+&}*+mul(915,883)}?)#from(62,762)-mul(512,958)+who()$#^{*mul(798,476{:@who()#mul(89,309),how()!what()what()where()mul(613,761)^[~~:&do()>mul(375,874))?{why()'@mul(75,714)!<%why():!don't()select()?when()@:?<[~mul(43,740)mul(389,134{'(~- >who()mul(755,490)when() what()mul(391,722);what()mul(107,927)~mul(901,762)+;when()+$^select()mul(609,510)#how():select()@)mul(937,386)) +&){mul(757,236)?how()/[who()'*how(937,357)&when()mul(521,787)where(954,730)#what()^mul(158,498)+mul']do() select()}$mul(60,389):~/;;#where()^mul(958,451)*!{{ %/#:mul(855,921)]mul(558,622))-mul(269,240)+how(626,93)+,$(!mul(735,376)%%[where()mul(868,976)~& @;]mul(597,168)from()what()select()@what()mul(40,231):who()({&who()~don't()+~who()-mul(693,922)/why()mul(597,656)mul(826,321)when()mul(793,429)select()~:~}how()how()@mul(837,77)when()mul(389,114)@mul(362,967)+mul(342,929)#where()~mul(218,879)--+[%]who(933,163)mul(314,457)'&/&,)(mul(
// Filter for 'mul(XXX,YYY)' where XXX and YYY are 1-3 digit numbers
const regExp = /mul\((\d{1,3}),(\d{1,3})\)/g;
const matches = input.match(regExp);
const matchResults = new Array();
let matchSum = 0;
for (let i = 0; i < matches.length; i++) {
const match = matches[i]; // mul(XXX,YYY)
const [a, b] = match.match(/\d{1,3}/g);
console.log(`Multiplying ${a} and ${b}`);
const result = parseInt(a) * parseInt(b);
matchResults.push(result);
}
for (let i = 0; i < matchResults.length; i++) {
const result = matchResults[i];
console.log(`Result ${i+1}: ${result}`);
matchSum += result;
}
console.log(`Sum of all results: ${matchSum}`);