From 3d251f96241393aad59846312c14510e2e7cf79d Mon Sep 17 00:00:00 2001 From: Shaun Burdick Date: Tue, 3 Dec 2024 10:50:59 -0500 Subject: [PATCH] Day 3: I gave up and used RegExp... --- README.md | 1 + day-3/README.md | 42 ++++++++++++++++++ day-3/input.txt | 6 +++ day-3/main.go | 107 +++++++++++++++++++++++++++++++++++++++++++++ day-3/main_test.go | 73 +++++++++++++++++++++++++++++++ 5 files changed, 229 insertions(+) create mode 100644 day-3/README.md create mode 100644 day-3/input.txt create mode 100644 day-3/main.go create mode 100644 day-3/main_test.go diff --git a/README.md b/README.md index f0c37b0..c9fff1e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Each day will be setup as a separate folder. - [Day 0](/day-0/) - Trebuchet?! (2023 Day 1) - [Day 1](/day-1/) - Historian Hysteria - [Day 2](/day-2/) - Red-Nosed Reports +- [Day 3](/day-3/) - Mull It Over ## Environment Setup diff --git a/day-3/README.md b/day-3/README.md new file mode 100644 index 0000000..e56e418 --- /dev/null +++ b/day-3/README.md @@ -0,0 +1,42 @@ +# Day 3 - Title + +## Part 1 + +"Our computers are having issues, so I have no idea if we have any Chief Historians in stock! You're welcome to check the warehouse, though," says the mildly flustered shopkeeper at the North Pole Toboggan Rental Shop. The Historians head out to take a look. + +The shopkeeper turns to you. "Any chance you can see why our computers are having issues again?" + +The computer appears to be trying to run a program, but its memory (your puzzle input) is corrupted. All of the instructions have been jumbled up! + +It seems like the goal of the program is just to multiply some numbers. It does that with instructions like mul(X,Y), where X and Y are each 1-3 digit numbers. For instance, mul(44,46) multiplies 44 by 46 to get a result of 2024. Similarly, mul(123,4) would multiply 123 by 4. + +However, because the program's memory has been corrupted, there are also many invalid characters that should be ignored, even if they look like part of a mul instruction. Sequences like mul(4\*, mul(6,9!, ?(12,34), or mul ( 2 , 4 ) do nothing. + +For example, consider the following section of corrupted memory: + +`xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))` + +Only the four highlighted sections are real mul instructions. Adding up the result of each instruction produces 161 `(2*4 + 5*5 + 11*8 + 8*5)`. + +Scan the corrupted memory for uncorrupted mul instructions. What do you get if you add up all of the results of the multiplications? + +## Part 2 + +As you scan through the corrupted memory, you notice that some of the conditional statements are also still intact. If you handle some of the uncorrupted conditional statements in the program, you might be able to get an even more accurate result. + +There are two new instructions you'll need to handle: + +- The `do()` instruction enables future mul instructions. +- The `don't()` instruction disables future mul instructions. + +Only the most recent `do()` or `don't()` instruction applies. At the beginning of the program, mul instructions are enabled. + +For example: + +`xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))` + +This corrupted memory is similar to the example from before, but this time the mul(5,5) and mul(11,8) instructions are disabled because there is a `don't()` instruction before them. The other mul instructions function normally, including the one at the end that gets re-enabled by a `do()` instruction. + +This time, the sum of the results is 48 `(2*4 + 8*5)`. + +Handle the new instructions; what do you get if you add up all of the results of just the enabled multiplications? diff --git a/day-3/input.txt b/day-3/input.txt new file mode 100644 index 0000000..2ea189e --- /dev/null +++ b/day-3/input.txt @@ -0,0 +1,6 @@ +;(,)mul(858,702)-*(?from()/mul(35,359)who()mul(856,94){why(114,10)-}[how()]#mul(778,521)why()where()??^mul(990,780):(how()don't()^why()>^mul(352,9)~)when()-where()when()&why()$^mul(379,297)}*#]when()~from(116,753)'((mul(478,803))#where()''*mul(893,529)~@how()#mul(170,765)?what();mul(630,481)who()@]mul(576,452)!>+$mul(839,395))~&select()*mul(630,148)mul(637,733)from(),{select()$what()&don't()}mul(965,332)$;{*mul(563,908)from()?~why()how()mul(907,261)why()mul(683,576)from()when()}!]!mul(687,422)> [<*mul(811,962)^mul(717,674)~@{)who()when()]mul(402,513)%when()%$*mul(922,320)~!*%$^mul(536,772)-#>select()where()({'#mul(217,696)select()>{select()~select()%mul(41,999)&mul(615,164)/%[-#*&}mul(488,200)what()?$mul(235,838):@what():mul(428,894)<(#&#don't(),[*$ mul(502,555)>who()'~]'*}mul(397,619)mul(677,653)@from(443,650)where()*;-@)]mul(761,412)mul(434,521)/!/what()@,why(),mul(319,307)-[~/}from()-)mul(13,180):?~{&*,'mul(560,200))#$[;+/!]mul(269,735)mul(131,915)@* when()@:why(256,731)')#mul(455,277)<+{how():'@!#mul(721,65)from()?!(mul(387,564)!how(742,879)from()%select()-(^mul(854,744)<%: ^~}mul(176,188)[<>,;mul(914,199)>**mul(248,259);what()~?;}*{select()mul(559,588)*)do()~*{*what();[ mul(445,787)how()mul(833,324)'[ #how() why()$;~mul(929what()mul(687,390)select()when()what(499,700)!*when(158,490)mul(929,336)>mul(865,751)*:''mul(881,809)%from()<{what(),why())mul(467when()>from()-/mul(396,641):@/ what()how()*{$(do()from()}what()mul(210,926)what()#'@mul(437,84)how():why()where()'}!{where()mul(86,264)'/when()mul(344,101);%#%@'who()#}mul(274,657)what()'what()from()';mul(997,598),['?mul(534,554)mul(466,734){mul(910,968)&{why()~,;!:mul(308,302^~[}<:mul(745,927)>$~%mul(897,144)~who()#[{+what()what()*mul(408,883)?]when()where()when()>~?mul(319,561)>>mul%mul(423,423)where()why()('why()don't()#)&;where()]mul(478,184)select()]>]]''*do()}^{why()mul(928,991)*+!{from()*#-mul(113,915)}why()what()from(){(:?!mul(768,68)-%*^>&^&mul(799,399)where()/mul(451^@mul(476,439)[](>{!who()}mul(401,954) )when()!-%~mul(150,216)[select()<+who()^mul(76,864))select();:select()mul(576,9)when()]what()from()mul(228,354))^!^;-$%mul(623,265)(when(470,524)#select()where()-mul(113,681)when()mul(521,682)@/when()select()mul(651,598)$~-#how()mul(840,408)do()#where()/:select()how()mul(820,511)how()mul(727,13)mul(970,417)^~:}~^where()from()':do()<;when()[>mul(259,372)/,:%mul(255,971)/!)}where()select()-mul(460,320)!!mul(849,743)]when())*mul(180,806)when()>?!from()*mul(595select()mul(649,876):->-(what()when(180,454)]how(968,910)do()what()how()/*from()select()++),mul(482,581)>,#{mul(66,275)mul(647,525)&#'mul(377,626)+where()]mul(630,898)?mul(317,506)mul(903,888)],what()#mul(766,841)+}%-what(287,912)+/#why()don't()>where()from():mul(145,488}-[mul(712,25)/mul(797,334),from()who()}from():),mul(323,141):#}where()where()%from() }*mul(848,645)why()';?+;];from()mul(181,788)}{?when()from()<^mul(103,568)}&~(>how()#>when()+mul(343,438)%/?-!why()]^why()mul(349,623)?mul(614,519)where()who(608,465)+, mul(318,996)$)from(322,982)mul(929,651) @:(%mul(683,248)who()when()who()why(594,423)>]mul(717,522)$select()do()#select()mul(4,875)@]<$why()*do() )<']*[?mul(22,93)'who()what()#'/[;/mul(130,509)&(${mul(348 '@mul(984,787):-/[mul(454,365)]what()$mul(249,223)mul(503,598)>:mul(369,549)who()[what()?from()where()^&-do()mul(977,871)%what()mul(762,528))@^-^who()}/:-mul(917,277)#{?%mul(659,953)who()from():+<^}:<mul(896,392)]select()--(;!(mul(121,437)-~[[?%>mul(63,503)select(){{!]#who()mul(977,491)**:*%%don't()]where()/mul(292,954);]>~(from()<$%mul(683,74)where()where()<$[mul(204,861)from()@what()~ #-mul(455,989)$when(595,175)?}:]%)+mul(218,118)$from()*select())how(632,888)from()don't()/}why()select()+@?where(){mul(773how():mul(731,156)%']?when()mul(390,980))where()what()mul(698,483)mul(617,983)#,)[when()%;mul#*%don't()mul(446,527)@@*%who()where()#when()~mul(418,536*;why()when()mul(651,531)$mul(532,68),/~what()mul(12,180):mul(654,368' from()select(772,96)where()when()%}mul(32,581)from()*$?how();where()&mul(41,175)/[mul(36,825)do()/how()when()<*~#^;mul(413,399)]select()*'where(988,834)do()from()}mul(589,631)+{!-%[+~,{do()/who()&from()%$$*{%mul(87,334)&{}from()]mul(293,208)&&*'who()*mul(333,989)%[[ ]mul(516,15)~{#mul(888,937)when()%from()'$~mul(299,886)how(74,112)}+]mul(304,310) mul(222,429)!$}$who(),:@(mul(249,734)~what()?how(418,670)do()!what(),'&who()}];select()mul(499,633)?[?,who()^<-mul(593,430)^#why() [$where(50,106)who()mul(911,397)[) [)@-who()when()(mul(939,597)>where())~~-mul(53,794);<~/how()mul(297,882)do()how()++]select()-+mul(651,458)when()what()@^mul(773,576)$what()what()from()}:<&why()mul(699,864)from()!/$[where()mul(456,889)&)don't()!?@who()why(853,185)mul(303,720)what(358,684)]%where()!what()mul(14,909) +<][mul(520,164)@ %$;mul(118who())(mul(433,718)select()~: mul]*who()&mul(186,91)&#how()^from()where()from()!mul(872,843)where()+&@'?what()where(242,351)mulwhy()what()when())*(!^why()mul(285,779)!>>mul(912,530)}}from()mul(439,204'what();]/#-]mul(724,984)$:how()where()}mul(291,595))<*+&#mul(710,846{what()& how()!/~mul(719,20)%what()don't()from()%!/)%#-when()'mul(390,194)select()*%+who()mul(620,559)where()-+where():>what()%[don't()&*'{mul(487,458)from()@}<&':mul(284,240)'what()}from()) where()mul(140,943)>)'/(mul(379,292)!+[~&({:mul(184,248)?,where()from(668,581)}]%mul(476,864)'([><(<}mul(383,543)(mul(54,809)where()who()where()[:mul(732,830)$who()%when()what()#) -mul(156,846)}'$%<,'~mul(241,296)}'what(225,40)?how()%from()from()#mul(331,481):$how()-)](!mul(342,855)who()/~,from()#'$;~@)mul(858,699),@/do()~%how()when()<>/mul(894,669)&+mul(734,520);mul(690,168*)+/mul(84,758)>!select()from()<{mul(374,587){&$$@where()';when(402,673)mul(887,673)@'[[what()^from()mul(17,756)%%(<]mul(814,306)where()+who()mul(138,523)mul(961,961)>how(960,295) <^}why()where()mul(529,982)!;~mul(489,849)(*)?>%mul(570,381)who()*select()@ +mul(826,522)&+:^~$how()what()$select()do()~why()]why()what()mul(643,495)mul(34,439)mul(657,375)!(how()?mul(177,65)&>[what()mul(552,376)where(633,38){(:(*do()&)+mul(689,184)/{mul(711,957)+?what()-&~-,!/mul(106,102$mul(468,125);}-$mul(451,95)mul(792,372)}select()select()select():][!mul(207,775when(){+&; who()#mul(877,149);])'[+,&;mul(994,994)'}select()mul(503,637)'{#why(37,49)from())<#(mul(301,442)>,!when()] who()select():what()mul(727,66)what()~*[+where()[^mul(438,988)}how()~;*%~?-don't()'who()}!($:mul(581,545)&{how()?from(650,743)!:)#mul(11,800)?&??$>mul(816,96)$]where()%%^:select()select()mul(529,111)select()from()%?^*mul(360,694)select())* *@*<#&mul(30,413):^''@mul(319,911)!)-select()select()why(152,790)}mul(148,10)how()!]mul(247,811): ~&,$-mul(660,54);why()@mul(694,449)(what()+mul(615,285)<)>do()from()why()~mul(800,658)why()')select()who()mul(155,2)}')^select()from()'^[{mul(763,673):}:where()({how()mul(813,428)&?!-why() ,]]mul(865,165)do()when();:how(408,266)mul(328,267)}how(614,872) ^@^#mul(714,826) [mul(826,638)[ why()'(%}/(mul(500,76)'! ,#mul(10,267)' ;^mulwhen(16,622)~? select()',?}mul(541,994)-from()select()-~why()how()mul(47,669)(who()why()when()~mul(998,298))mul(937,507)^when()select()[}$],%mul(148,102)mul(39,980)+-+%;who()why()(mul(690,355)+!#^'-do())!-$,mul(59,509)],how()~?mul(57,388)how()( mul(442,904)[$from():&;^~mul(702,195)what(),why()^mul(244,471)(>select()^select(694,426): how()*mul(19,675)why()what()from(734,40)#where()mul(270,397[}*from()]/from()*+mul(855,233)~, @from():mul(935,285)mul(834,256)]mul(880select()mul(915,279))where(764,367)]$mul]who()how()mul(805,164)$}select()%@select()@,>#don't()]]why();select()%from(96,570){!}]mul(432,373)~)-mul(436,907)<$@what()why()who()$mul(236,42)from(758,332):*#who(),$how()mul(528,36){mul(514,585)}mul(263,66)-<:$?select()}*mul(665,667)+{{<+!]>([mul(430,685$~'mul(842,44)/%select()mul(759,831))$:!#!/usr/bin/perl~$mul(155,353),*select()^#}mul(570,117)from()*from(),:^select()!%-mul(643,646)-:)#()where()why(){^mul(840,147)from())mulwhere()< !;;+{ %'mul(365,934)mul(68,395)>}from()mul(271,627)*mul(701,973)~mul(781,778)@mul(815,159)when()}-#?'mul(746,396)mul(724,844)what()how()what()%mul(954,395)how()<+from()*?mul(27,969)select()]from()$##[mul(652,117)what()who()?$?who()mul(513,501)]]%what()mul(906,170)+!)[[~/^mul(341,349)mul(990,89)/ how(){^{what()mul(543,751)^/{:mul(161,830)>;$$&mul(60,852)mul(110,789)why() @select()!mul(232,23)-#where()[(}mul(113,909),)how(){) (;>mul(218,441)~,%(^select()[mul(383,714)-*<~+)when()~&mul(802,923 from()>what()select()mul(875,944)!select()<%+[mul(974,967);mul(359,518)who()%mul(725,236)$<'{mul(223,195)[!mulwho()@&:mul(965,312)>why())$mul(651,272)><&}mul(586,166)):<&[*;mul(973,90)<>where()-&when()when()-[&mul(522,382)where()&when()--where()mul(327,551)mulfrom()]{?why(126,484)<]mul(759,5)?what()who()';+:;mul(676,54)'from())how()#$where()++mul(108,594)mul(470,453)where()~:&,mul(540,6)/mul(34,148)from():%[#when()}mul(543,235)who()?how()why()!!' mul(293,694) ?do()^@mul(194,754)(+^{<(mul(695,979)from(190,23)where()])&[why()mul(347,45)[select()^mul(257,87))why(66,98)^mul(315,641)who())$how()mul(513 +)%*(:*who()how()]don't()why()#$mul(313,874)where() ^when()+*what()[mul(819,556)why(231,430):,mul(317,224)%!!)&how():don't()where()^mul(724,210)''how()how()what()where()+-)mul(653,313)how()/(mul(718,132){mul(304,399)+mul(813,580)why()select()from()*)[:do(),from()how()@why()when()mul(420,147)why()<;mul(286,778)/@?%-mul(843,55)?mul(708,572),)who()-mul(804,987):}/%?},where()?when()why(831,88)mul>^]'}(where() ]~where()mul(447,399)-&why(360,508):@{* mul(190,685)*,?how()mul(562,517)~mul(276,16)mul(804,20)]]what() from()){{mul(88,726)-where()/)-from()what()*mul(261,86); }who()why()what()[%%mul(845,611),+mul(579,992)%$why()don't()?&!(mul(159,448)!how() mul(13,152<'(;mul(418,959)%who()?from()mul(929,190) ~when()}'%&^mul(541,283)#>mul(998,260)-?where()who(403,852):)mul(505,488)mul(435,756)+;select()+[mul(483,501)+( ^how()>@(mul(614,830)what()mul(248,34)*when()*,@where(371,503)@#]mul(620,74)~who()select()why();#?mul(686,263!why(),;when()*/%mul(363,968)(*#what()#{~select(926,636)why(681,621)mul(551,129)+;,*>mul(543,78);mul(706,409)),who()$]>what(803,604)why()what()mul(673,839) +@}[->why()when()mul(736,440)'what()@>$}mul(747,892)?!]mul(49,971)who()?){;;![}?mul(383,914)}(who()-}how()mul(618,311)who()('{,from()where()mul(502,765)mul(436,416)select(){:who()[&<mul(828,942)@)/who()mul(806,221):{-from()what()/-!%select()mul(222,135)[,what())-+from()mul(789,51)how()>;^$')when()!where(449,459)mul(134,544)#mul(592,830)$what(),mul(450,952)from()(what()?what()%+mul(491,815)where()^{^+/mul(964,386)^why()%,'when()'mul(751,11)?mul(990,552)-who()$>/$)%(mul(847,756)#:where(891,107)^['from()why())from()mul(989,549))/mul(128,819)'?mul(315,133))+#select()()*select()[where(692,300)mul(658,119)mul(68,966):<-,:)}{@mul(542,35)]who(683,885),-how()]}mul(793,264)when()do()+where();why()when()mul(435,912)?+select()when()(:%mul,,*'when()<[,from()mul(319,351)'($(#[mul(983,596)$}])@),mul(958,131)@@!;!}}!select()}mul(703,609)!*#]#mul(757,8)>}}mul(417,359)mul(871,898)where()from(549,555)mul(48,800)[when())!mul(42,556)&from()+&#mul(917,10);>mul(332,621)}+['{mul(401,135)~%[;:$))do()what()+mul(779,9))()mul(901,432)!'(select()~mul(64,712) ,don't()]who()~+^#&what()/mul(900,5)select()-*mul(267,404)mul(136,977) #!@mul(465,853)what()select()/~~+where()mul(101,322) #/'why(135,719)do()select()}%%mul]}: /what()}mul(548,867)>'~-&-$;!mul(775,563)select()/:(^@]how()}%mul(593,707)#&mul(786,814)/)%]&}'*mul(653,744),what()#&mul(545,436){@%*@>who(183,90)/;what()mul(13,919)don't()@}&)?(mul(131,107)mul(233,301)mul(222,55)}who()-why()mul(828,783)$}how()select()mul !mul(378,347):}@mul(139,917)+]^):how()[[^mul(593,751)*'!select()$select()*mul(859,230)))>{;<#who()mul(37,617)%from()why()):':mul(207,241)^when()mul(982,474&from()mul(202,531)why()why()$where()!how()}mul(196,19)#when()>mul(600,831))&why()from()@~<mul(113,738)%}what()%when()-^*'[mul(659,665)'-<}where()who()from()<~mul(779,45)mul(964,79);-mul(454,704)%,[}^^mul(714,902)?how()&$$/>mul(678,277))select()@!}}mul(973,867)/how())/~+mul(961,737)~ don't()'< where()who()}mul(902$$when(),@select()mul(9,964);from()},'<{how(654,359)mul(788,711)[select();%);mul(618,648))mul(622,99)]why()(when()why()*>(mul(456,858)/$who()where()(mul(691,120)?&{#!$mul(841,857)mul(792,885)*mul(919,871)(/>^':%$mul(829,758)where();mul/what()~/;from())^^where()do()~?+/(who()'}mul(655,175)from();what()when()$!^mul(216,476)[}?'$}[how()from()$mul(611,263)where()>,@-mul(747*mul(351,765)[mul(469,471)from()how(){;/select()#mul(423,493)why()where()mul(66,973)why(132,717)):*{select()mul(612,848)}^?where()$when()]/}:mul(527,124)}how()/,&>?/mul(870,331)^* mul(130,565)>~]&}#where()#[[mul(626,163)?-how()mul(153,137)?what()>@:>)>mul(972,544)-@,$[who(342,586)/don't()$[$~who()?:[/;mul(930,217)&}{what()mul(241,121)+mul(850,9)where()from()why()^}(#don't(),#how()#mul(821,737){*mul(726,629)<$why():select()mul(556,762)%*$'^&when()mul(432,395)#$':*/&when()when()when()mul(466,888):'what()mul(967,260)]##;how(458,10)@-$who(),mul(693,120)+,select()^from()mul(281,907)(@]-[mul(807,218)select()how(){ select()mul(773,151)'$;(};+mul(962,731)}^/where()#from()[~-mul(944,522)(mul(253,853)(@from()where()--don't()mul(434,54)who()^-when()/?don't()->!what()when(){*?mul(140,314)who()[@mul(21,934)(when()mul(446,332)^^when(32,819)don't()select()what()^why()when()mul(353,42)&(*&*mul(515,560)]^select(13,885)mul(341,643)%mul(772,777)]how():-why(835,947):select()>mul(780,58){~@from(12,674))mul(24,327)why()!$when()why();from()from()mul(53,613)who()when(),$'who()%mul(130,984)}-}^mul(634,685)do()+mul(835,113)when();/how()'mul(516,246)@from()}do()):;;{why()how()-^mul(866,121)(/mul(289,117)select()}^who()*>@,/)mul(494,764)why()how()where();mul(263,332)%,%^{&@mul(470,641) {%mul(572,709)>#,/ from()[mul(189,623)$mul(359,331),how()>why(10,98)!do() where()*:mul(908,32) diff --git a/day-3/main.go b/day-3/main.go new file mode 100644 index 0000000..b4780c0 --- /dev/null +++ b/day-3/main.go @@ -0,0 +1,107 @@ +package main + +import ( + _ "embed" + "flag" + "fmt" + "regexp" + "strconv" + "strings" +) + +//go:embed input.txt +var input string + +func init() { + // do this in init (not main) so test file has same input + input = strings.TrimRight(input, "\n") + if len(input) == 0 { + panic("empty input.txt file") + } +} + +func main() { + var part int + flag.IntVar(&part, "part", 1, "part 1 or 2") + flag.Parse() + fmt.Println("Running part", part) + + if part == 1 { + ans := part1(input) + fmt.Println("Output:", ans) + } else { + ans := part2(input) + fmt.Println("Output:", ans) + } +} + +func part1(input string) int { + parsed := parseInput(input) + sum := 0 + for _, command := range parsed { + sum += command.Execute() + } + + return sum +} + +func part2(input string) int { + parsed := parseInput(input) + sum := 0 + enabled := true + for _, command := range parsed { + enabled = command.Enabled(enabled) + + if enabled { + sum += command.Execute() + } + } + + return sum +} + +type Command struct { + name string + args []string +} + +func (c Command) Execute() int { + switch c.name { + case "mul": + product, _ := strconv.Atoi(c.args[0]) + for _, multiplier := range c.args[1:] { + mVal, _ := strconv.Atoi(multiplier) + product *= mVal + } + + return product + } + + return 0 +} + +func (c Command) Enabled(current bool) bool { + if c.name == "do" { + return true + } else if c.name == "don't" { + return false + } else { + return current + } +} + +func parseInput(input string) []Command { + commands := []Command{} + + commandPattern := regexp.MustCompile(`(do(?:n't)?)\(\)|(mul)\((\d+)\,(\d+)\)`) + matches := commandPattern.FindAllStringSubmatch(input, -1) + for _, match := range matches { + if match[2] == "mul" { + commands = append(commands, Command{match[2], []string{match[3], match[4]}}) + } else { + commands = append(commands, Command{match[1], []string{}}) + } + } + + return commands +} diff --git a/day-3/main_test.go b/day-3/main_test.go new file mode 100644 index 0000000..8ab46b7 --- /dev/null +++ b/day-3/main_test.go @@ -0,0 +1,73 @@ +package main + +import ( + "testing" +) + +var example1 = `xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))` + +func Test_day3_part1(t *testing.T) { + tests := []struct { + name string + input string + want int + }{ + { + name: "example", + input: example1, + want: 161, + }, + { + name: "actual", + input: input, + want: 182780583, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := part1(tt.input); got != tt.want { + t.Errorf("part1() = %v, want %v", got, tt.want) + } + }) + } +} + +func Benchmark_day3_part1(b *testing.B) { + for i := 0; i < b.N; i++ { + part1(input) + } +} + +var example2 = `xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))` + +func Test_day3_part2(t *testing.T) { + tests := []struct { + name string + input string + want int + }{ + { + name: "example", + input: example2, + want: 48, + }, + { + name: "actual", + input: input, + want: 90772405, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := part2(tt.input); got != tt.want { + t.Errorf("part2() = %v, want %v", got, tt.want) + } + }) + } +} + +func Benchmark_day3_part2(b *testing.B) { + for i := 0; i < b.N; i++ { + part2(input) + } +}