From 4f7f33cc750cade06d370379c92bee8e72b5d742 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Wed, 11 Dec 2024 02:27:54 -0500 Subject: [PATCH] 2024: Day 3 completed --- 2024/data/day3.txt | 6 +++ 2024/src/day3.zig | 109 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 2024/data/day3.txt create mode 100644 2024/src/day3.zig diff --git a/2024/data/day3.txt b/2024/data/day3.txt new file mode 100644 index 0000000..c97cbdb --- /dev/null +++ b/2024/data/day3.txt @@ -0,0 +1,6 @@ +-:-]what()(+/mul(957,396)?mul(550,844)%+why())-? #}from()mul(488,628)%} ~**mul(770,931)$~mul(791,733)<{mul(985,350)<#why()don't()what()select()$what())]what()who()mul(327,185))<^^mul(542,68)#?who()when()do()from()mul(51,291)[where()!{]/}'@?mul(233,511)@what()]mul(311,967))&who()how()mul(839,578)^who()]}mul(266,735){mul(176,670)mul(154,710)*select()](':^,mul(531,801)# *why()why()mul(30,325)~,where();select()select()}-/when()mul(512,729)+where();[mul(720,339)[~*when()mul(722,867)!);{+mul(582,286)^:)what()@mul(604,485) (who()why()who()from()[mul(128,295)how()?!%~~[~}{[&;mul(548,186))(%];mul(841,290)when()where()'?mul(646,803)mul(553,782)how()when()-mul(569,604)@ ++:/%why()]select()mul(257,598)#mul(897,819)how()what()from()how()]when()~/!}mul(856,271)+&why(){}why()>who()mul(373,408)-who()^&%>';,when()mul(54,88)what()!mul(663,711)$#(?;^from()mul(898,810)when()from()%@mul(776,102)why()mul(303,842)!/,%<^;mul(840,791){[@mul(909,714)don't()>who()why()from(545,686)%~mul(483,956)^'why()from()where()$>*:mul(931,649) mul(800,313)):mul(31,69)mul(549,670)$;mul(327,976)@who()^mul(627,907)/[@what(925,706) ;^who()!mul(629,813)when(){$&where(){#mul(504,147)?mul(222,429)#who()*/!select()?$ mul(439,336)?from()*select()*}when()]who()mul(148,356)(who()+mul(271,905)mul(564,172)@?(~mul(628,470)#} mul(301,170)?@,^don't();&:^&how(605,264))(what()'mul(896,108),$mul(413,431):<>where();how()>!}when()do()!}/&:when()>mul(754,737)~:#:* mul(962,620)}mul(26,490)!~,mul(450,234){/]who() <;{mul(938,932)?--#%};}mul(140,314)(-}/,[mul(202,839)^why()-!},mul(459,716),mul(600,932)}when()]who()}who())&mul(752,142$mul(174,573)mul(231,182)from()mul(308,661)what()} mul(178,99)&^*[(mul(858,730)~}from()^mul(17,545)what()~{~*^what(90,714)how(),mul(63,969)-]mul(364,49);mul(130,598<:&why()select(879,794)mul(46,169)>&how()%mul(564,506)/what(255,868)mul(415,375)':@who()mul(525,772)<$mul(277,787)[~mul(314,321)'&@$^%mul(741,325)?(%#;*mul(459,703)why()~what()mul(250,38)what()<-$)when()%(don't()mul(296 ',mul(673,933)?#<@who()from()^?mul(831,912)?/*mul(407,853)mul(119what()why()>mul(816,762) how()<}~from()how()/@:mul(792,799)()@?%:$:mul(289,264) +why(),'*),from()mul(767,350):>~mul(123,684)@from()>mul(722,338)<'mul(252,529)do()%)%^when()!mul(731,123)mul(582,378)-mul(934,355}where()what()how()@%<[>;:mul(5,63) who()!mul(946,479)+}select()$@mul(478,71)~<()-#mul(500,398)'from(612,869)select(98,846)!!<]:select()mul(785,98)',select()//:-mul(192,182):{ why(){;mul(910,471)&^+&who(424,579)/:select()[mul(217,829)where()how(423,674)$*mul(318,444)[!?~mul(254,793)who()select(521,861)how()mul(54,186)why()[:^;-mul(109,234)mul(465,266)+?([-mul(518,485)^mul(403,383)mul(726:how()when()#mul(344,785)/}+?mul(97,996)+@'mul(637,749)how()-%+mul(302,591)don't()%^]}!)]mul(524,902)$[]/*mul(839,651)}^)$when()'what()mul(270,805)#mul(566,750){ how()/mul(716,302)/&*>@-what()>when()what()mul(602,574)+where(619,83)mul(235,585)?where()[%select()+>where(){]mul(209,404)~where(),why()how()-/-mul(123,125)^'how()who()$}/;mul(851,629)how()who()'#;$ do():select()!when()[>+>mul(576,669)what()!,'?from()&mul(423,260) how()-mul(910,922)?<@'->(mul(274,173)why()}<~from(601,667)mul(282,816)from(953,125)~mul(98,837)&[how()[what()mul^%} '$from()^-;mul(439,801)mul(761,498))>$'-why()<who():mul(109,723)from()who()mul(391,416)& -how()>mul(496,170)^'${mul(657,96)why(611,959)why())from()%+mul(62,175)>}~,%from() >mul(92,927)mul(17,279)!why(){+where()}how()mul(939,286){;mul(744,904) from()?''who()&who()how()mul(170,192)@,mul(499,985)';from()})!{+who(){mul(572,653)#:why()mul(720,626who()from()(%:mul(676,779)!why() when(58,261)^ *mul +from(){)')@!*mul(802,646)how()(-+[;#when() {mul(742,576)]* ;mul(38,717)?what()}'how(184,130)mul(126,115)]@>mul(512,978)/where()+*why()mul(705,242)?{$how();when()mul(173,898)'(~who()mul(536,621)&^from()select()when()?@mul(52,680)] -%@;][mul(971,573)^mul(879,466) +mul[!-,why()(?mul(770,624)~:mul(197,580){{(%mul(678,337)what()mul(951,457)'<#mul(679,253)?do()who();& who()select()mul(105,231)+{&!when()who()how()!')mul(262,609)):,{'from()/?@}don't()*:mul(471,462):([(@;from()mul(734,965)/&/where()mul(885,324)why(){>/#<:mul(390,818)!mul(684,730)*>>{[!what()what()mul(824,893)mul(801,597/why()!when()how() '>from()%mul(165,825)who(837,795)?? why(187,949)mul(703,551) when()'mul(759,898)select()#$$ where()where()mul(694,292)%(who()%#}mul(884,767)^:$mul(945,214) where()how(837,748)(mul(537,489)(%{mul(594,245)who()from()from()%}!)])why()mul(832,704)^~mul(902,18)how()what()who()/#'-#mul(345}who()when()?]&^mul(873,161)^mul(81,518)]$mul(875,700)how()where()(mul(735,369)/-< why()@>mul(703,274)-from()when()**,)mul(204,896)]+mul(28,596);why()#select()'#]mul(774,171< why() !from()mul(29,711)mul(28,600)}when()!@(^why()~{mul(555,761)%}do()from()-mul(139,179){how()'?mul(294,354)}where()mul(317,957)]select()#;where() where()^@from()mul(461,831)~who(75,120)%who()@-&;,)mul(563,131)mul(607,401)select())from())&,mul(26,412)select(726,797)&)how()@select()mul(416,615)(what()select()!()<#;&mul(921,158)>- mul(245,598)select()what()*({mul(468,522)]^select(574,638)]@};do()from(799,930)%who()#:[how()mul(413,674)[how()*mul(327,432)%?@'mul(486,644)}~>-mul(637,16)how(254,818){%where()#where()who():who()mul(431,749)$$where(228,303),%+&mul(593,337)}#:where(){why()[+&!mul(520,180)^mul(723,959)mul(492,739){/?mul(327,463)?-select()-<,mul(102,950)!#do()@when()-when()},select()/mul(274,979/from())who()(~)!^$mul(78,739)why()@{~mul(819~?~+]>@mul(824,208)}mul(338,41)where() &*;;&what()mul(888,646)from(),$:-who(263,596)!!-from()mul(396,204)>{)>{?(%{mul(885,937);!what()&%!from()}mul(207,417)(<;what()mul(187,893)((&&}&why()*)-mul(589,985)^how(310,10)when(),]:mul(989,534)$where()mul(552,604;(!;select(){){where()#mul(152,511)+/$!;+/<+]mul@select()::when()who()how()!what()mul(446,994)from()<}what()select()'why(244,102)+)%}who()mul(693,903)?*/}select()mul(282,115)[];why(){mul(925,276)how()&{what()&$when()&-!mul(191,385)*)mul(446,703)[>what()?*}what()^who()*mul(997,718)!>$)@,^*)mul(788,724)from()#&]~/<,)how()mul(181,531)[(why()[mul(409,206)what(604,231) when()why(921,229)]>where()//mul(199,96)when()why()#!/usr/bin/perl~%>~ &:mul(239,884) +what())[$^+why()mul(118,89)mul(689,203)#,,what()what()mul(633,394)from();~from()!where()*?@mul(568,753)/[+when()?%:mul(828,475)what()don't()-;@ mul(509,544)[when()};<+'(mul(235,757)<+:%select():mul(241,373)$mulselect() (%where()where()]-)mul(306,62)from()what()mul(285,414)!*&&>who()#mul(543,866)/~select()[+don't()/>)where()!when(),'mul(701,189)/';!:]+how(902,507)-^mul(847,104)mul(883,112){'~}&mul(697,190)what()%![!(why()@^where()who()mul(843,4)%what()&-%mul(945,389)#<)select()mul(690,755):mul(774,780)}mul(940,623)%where() ?where()(}^!mul(34,627)mul(479,281)#}>what(157,964)select(){how()why()+who(640,716),mul(117,249)mul(395,14)-]( ~(how()-mul(220,860)+^mul(765,74)select(),$who(),@mul(639,551);(mul(26,80)why(480,988)^why():? <[mul(672,116@mul(316,879)}mul(498,582) @,:{'why(589,887)mul(39;]mul(855,31)^from()?mul(93,510)mulwho(){@-what()from();where()from()~:(mul(688,799)~when()>from()-select()who()~#+{ >mul(275,916)#?-mul(359,865)where(441,672)'}what()[from()when()<>who()mul(909,227)$:!'mul(330,478)!?[;(+#what(919,466)&/mul(73,181)[{how()mul(403,182);mul(249,968):!from()?!{#-mul(661,975)!-;}'mul(999,285)select(565,140)+>@,$:from(47,825)~!mul(599,436))+ [>%!mul(959,617)mul(5,150)where()@;&mul(630,775)<&-:;mul(114,820[don't()when()#how()mul(976,290;+-from()where()]mul(338,47)when()what()where()%]mul*who() #+what()mul(679,324)mul(859,321)%'mul(446,297),#select();';from()mul(206,301)why()-'mul(87,734)mul(735,118)] {/what()*@^what()where()mul(685,883)when()what()mul(91,84)}]-~where(){when(374,912)$do()>~,' how()mul(67,939),)&~@where()(mul(923,997)~,*$when()[from()from()mul(699,705)~/when()+}mul(214,775)'%mul(715,142)-;mul(290,853)from()$why()what()select()-@-mul(682,729)+^$}, !mul(197,39)mul(269,573)@^mul(819,945)/select()-do()%$~'#select() 'mul(64,956)[who()*who()@,)>+}mul(519,356);*/%>why()[[)mul(184,666)what()mul(892,160)+*&where(764,214)--]?(>mul(996,338)>when()what()]))&?mul(865,864))?@[::when()>what()>mul(218,296)&)%:[~why()how(416,393)mul(118,100)from()select()#: $mul(7,742)how()&~how()>who()^mul(667,218)?/mul(218,898)!:$from()>mul(746,995)(+select()] when()}mul(971,429), !,&mul(505,165):!-)?-how()from()%mul(921,456)@mul(491,404)#how()-mul(284,834)#?(mul(667,960)]where():how()what(963,920)% what()don't())mul(236,336) why()why()select()where()^mul(33,901)mul(253,866)<#>$]%-mul(216,512),)from()what()what(464,183)where()select()@'}mul(98,640)' :)what()$%~#/mul(283,893)(mul(520,959)#^?{>@*when()when()]mul(80,420)where()mul(751,106)when()when()! how()mul(148,813)@><^[mul(740,246) how()where()!!/mul(242,262) who()who()%,mul(308(#/when()$mul(359,332)from()why()from()~$$^where()@mul(270,445)why()}%mul(623,449)where()how()?& />mul(759,849)-} (mul(84,200),$;who()[!mul(934,76)(@^:where()why()/'mul(650,46)[mul(105,265):)when()+ &'what()^mul(334,290)] $what()/mul(930,226,>^!%don't()mul(243,460){'#/what()+/mul(437,684)mul(501,579)/mul(243,174)mul(988( +<#where(206,306)where()[,from()mul(331,170)(?^~}#mul(940,949)>(,*+mul(925,961)^*from()select()^--^)(mul(994,182)+'+mul(153,816)~&mul(260,998)~:],],who()why(348,109)why()who()when(290,863)why(735,89)!from()@ >#mul(205,831)'$ %'mul(981,644)!#,*>mul(910,535))[who()#mul(220,934)how(271,592)-,*$,+mul(11,63)mul(783,580)^&*}~(;from(){mul(21,444$what(274,202)how()mul(293,78)mul(189,814)#{}why(80,738)}from()mul(456,691)*@{(,[%mul(916,89)how())(]@mul(524,412)];:(mul(374,851)where()[mul(473,999)select()$what()}don't();];(}mul(327,69)%&+;:/what()don't()-%,'()mul(377,536)mul(31,322))@what()^select()mul(719,58)$why()~&what()']}mul(39,890)(+<#who(){how()!mul(299,824)(]](+mul(205,11) +{mul(602,646)!% ^mul(384,953)do()&&:]<mul(228,736){({}don't()-when()@*>-mul(278,494))/&?><(select()mul(916,219)select(),:{(<*mul(360,209)why();~}where()-(,mul~when()when()!where()@:;:#/do()select()select()!,how(972,480)~-how()who()mul(726,867):>mul(549,954)](how(802,821)select()how()[+^mul(535#select()}why()[what()]why()*{#mul(72,525)mul(809,41who()!~where(82,230)}mul(961,563)}who()what(417,588)&*mul}{,+?%^[when(34,108)who()mul(71,111)$+,}#~-^]@ when(){:@mul(545,335) &how()from()<:mul(958,59)$ (what()mul(886,155)how()&+mul(525,132)<&}who(502,340)select()when()#^mul(339,398)who(),(how())@@how()$$mul(831,852)when()don't()>mul(935,45) select(930,598)!:select()mul(693,62)(mul(681,508)how()^@*;)mul(235,731)who(468,32)#~>don't()#:what()where()when()~~^>@#{mul(2,62)mul(866,617),>% mul(806,586)how():{/mul(669,407)!/mul(457,522)mul(40,474)>)]select()who()}mul(451,794)]#mul(115,471)~mul(331,456)@^who(){#when()mul(672,70)where()who())(#how()what()!mul(438,748)-/mul(605,224)mul(46,34)~?'mul(650,523)?mul(871,731)?%from(966,980)>when()mul(790,779) from()#$:,'mul(428,763)@# why()mul(724,6)select() ,mul(208,11)why()how()mul(287,562)$[:select()},?mul(531,36)/mul(12,351)#$+,:#:$when():mul(941,380)-[from()!)?-select()mul(102,544)when();~{select()~^;-do() ]who()from(),mul(959,599)>why()/,<%-,!mul(517,558)%])$mul(945,968)mul(854,265)? { + if (mul.status == .multiply) { + mul.multiplier = mul.multiplier * 10 + try std.fmt.parseUnsigned(u32, &[_]u8{c}, 10); + } else { + mul.multiplicand = mul.multiplicand * 10 + try std.fmt.parseUnsigned(u32, &[_]u8{c}, 10); + } + }, + ',' => { + if (mul.status == .multiply) { + mul.reset(); + continue :outer; + } + mul.status = .multiply; + }, + ')' => { + sum += try mul.multiply(); + mul.reset(); + continue :outer; + }, + else => { + mul.reset(); + continue :outer; + }, + } + } + } + return sum; +} + +// PART 2 +pub fn maybeScan(comptime T: type, window: *std.mem.WindowIterator(T)) !u32 { + var sum: u32 = 0; + var mul = MulOp.init(); + while (window.next()) |win| { + if (std.mem.startsWith(u8, win, "do()")) + mul.status = .scan; + + if (std.mem.startsWith(u8, win, "don't()")) + mul.status = .disabled; + + if (mul.status == .scan) { + sum += try scanForUncorrupted(u8, window, &mul, 2); + } + } + return sum; +} + +pub fn main() !void { + const input = try util.readAllInput(3, allocator); + + var mul = MulOp.init(); + var window = std.mem.window(u8, input, 12, 1); + const p1 = try scanForUncorrupted(u8, &window, &mul, 1); + + window.reset(); + const p2 = try maybeScan(u8, &window); + + log.info("PART 1: {d}\n", .{p1}); + log.info("PART 2: {d}\n", .{p2}); +}