From e121e532581ee1574e3ec8909852f61faf8d89aa Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Tue, 3 Dec 2024 22:16:20 -0500 Subject: [PATCH] Solve day 3 --- 2024/Cargo.lock | 47 +++++++++++++++++ 2024/Cargo.toml | 1 + 2024/data/day3.txt | 6 +++ 2024/src/day3.rs | 127 +++++++++++++++++++++++++++++++++++++++++++++ 2024/src/main.rs | 3 ++ 5 files changed, 184 insertions(+) create mode 100644 2024/data/day3.txt create mode 100644 2024/src/day3.rs diff --git a/2024/Cargo.lock b/2024/Cargo.lock index 45e8feb..7b396aa 100644 --- a/2024/Cargo.lock +++ b/2024/Cargo.lock @@ -2,6 +2,53 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "aoc-2024" version = "0.1.0" +dependencies = [ + "regex", +] + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" diff --git a/2024/Cargo.toml b/2024/Cargo.toml index d7b7677..3f40e65 100644 --- a/2024/Cargo.toml +++ b/2024/Cargo.toml @@ -4,3 +4,4 @@ version = "0.1.0" edition = "2021" [dependencies] +regex = "1.11.1" diff --git a/2024/data/day3.txt b/2024/data/day3.txt new file mode 100644 index 0000000..562d47f --- /dev/null +++ b/2024/data/day3.txt @@ -0,0 +1,6 @@ +$ mul(402,190))&who(),where(376,378)why();$mul(394,346)%:]^from()>:mul(130,944)who()>where()select()}:mul(952,439)?/how()from()^$why()do()@*{mul(557,916)&(who()mul(445,933):(,;>?mul(108,268)don't()select(574,441)-mul(132,870)from(){mul(441,660)why(),from();mul(919,820):#/%)why()*mul(194,790);#/^#select()?mul(981,514)$what(796,873)when() %from()mul(164,772):&:select()@mul(396,80)select()what()%),) mul(213,928){?who();@@mul(320,229)where(348,623)*when()when(180,565)mul(214,912)!mul(848,738)from()+):^how()-&[mul(378,433)select():%~mul(696,421)mul(364,341)?^don't()*&mul(89,441)how()select()what(),select()mul(423,822),?&(how()']what())$mul(21,844)&,select()/>^)'mul(469,230))when()where()*,#mul(569,594)why()what():{ select(200,250){())mul(661,628)#)why()from(325,19)who() mul(758,985){%&where()!how(213,616)*mul(394,768)mul(831,12)*where()>who(986,151)mul(962,504)$:^[>;mul(948,363)$@;]mul(857,273) how() ,:!select(),[mul(31,766)} *mul(372,138)+,#!~(>;%mul(774,958)#}&+why()*when()mul(560,137)}mul(72,718)when()^{]':{how()/mul(985,120)@*[do()$how()mul(891,69)select()mul(546,834)@$mul(767,879)$$!/&why()?mul(876,495){^/&)who()<~]mul(911,71){?#mul(116,462);:%<^'?}~why()mul(258,286)from()^#^?how()&who()mul(97,540)select()who()do(){^~~ )'mul(57,589)when()**mul(554,575)*+^mul(856,360)mul(530,200)@/&}*where()mul(588,2)who()$]mul(604,72)who()}from(524,212)mul(250,680)<;@;@how()?#mul(555,956)%(;:+<{(who()select()mul(377,822)+when()@[&{&from();*mul(457,538)mul(52,298)who()%when()%who()how()from(9,264)mul(452,941)where()+?,-don't()when()select()$''mul(229,512){{from()what()?!'^select()mul(185,787)<*mul(688,834) @@what(),}select()>mul(825,27))~&!;mul(796,378)*+(-select(); mul!):{!;who()$how()why()don't()select()how(451,129)]#*^mul(852,354)[mul(596,889)mul(476,207):#what()-+mul(467,323) from()why()}(}^&:mul(955,498)]{;mul(797,177)mul(321,350):mul(784,667)mul(707,927)~%#why()why()what();mul(515,511)from(589,691)mul*&[mul(884,558)/mul(824,926))+from(331,316)where()!*!:mul(938,881)]mul(287,358what()@from(226,364)+:^)-when(361,935)select()mul(324,887)@where()select())(mul(430>&][mul(381,417)}*why()why()!*#~mul(729,14)>%what()'where(){}mul(483,820)when(206,921)&when()@how()mul(608,185)how(5,376)%mul(150,182)>]/!( (+mul(78,588)what()@ why()when()*+from();;mul(837,417)who()mul(786,516)'how()%:~;%]who():;-mul(917,130) +why();[what()(,]mul(177,501)mul(346,27)when(428,856)who(){how()mul(513,432)what()']&where(),>?select(),do()+how()![where()mul(399,972)mul(862,828)when()?^&)mul(200,579)how()who()mul(79,535) {select(684,626)){where()?)mul(52,852)&< @what()^what()]mul(807,491)&#@mul(130,14)mul(884,328)when()%who(255,459)mul(434,697)?how(),,*)#mul(522,208) !&/mul(296,945)-~!what()when(),,%mul(127[mul(637,905)~from()/where()/where()mul(375,117)(<;select()how():!^{mul(856from()][from()}&when(331,921)mul(873,410)'@/mul(777,739>when()!^!)mul(460,138)!'{why()<~/when()when()+:(what()@)mul(97,8)mul(324,169)select()mul(396,755)!#select()^&#];when()don't()$where()/^{~{how()mul(856,118)$*who()who()#when()mul(683,431)/mul(946,398)mul(902,742)(mul(448,592)'mul(750,527)]/mul(98,232*,select()(!~/<{mul(104,754)^mul(959,509) '$~@/do()when(642,16);what() <#(+!mul(564,313)$]'mul(945from()*]!who()[%who()'*#don't()mul(410,907)@what()select()select()?mul(21,969)mul(942,472)' what() ?select()why()^do() /$-who()::mul(36,303)~mul(783,530)'$what()$:%?mul(74,743);~^;>do()who()who()>}mul(391@^mul(681,793)where()%!-,mul(171,461)![<<&don't()+mul(707,127)^?mul(641,578)where()how()what()what(89,960)}(]mul(431,871)mul,+mul(610,323)why()why()mul(662,436)'&[^mul(397%from()>*why()%-mul(186,254)?*]!who()!select(839,279)]+select()mul(84,228)[mul(536,784)where()+*how()mul(893,249;what()(mul(917,825)mul&mul(891,755))${,#@@mul(511,464)what()where()'when()mul:who()mul(730,485)][,mul(592,512)[why(52,524),*]@select()(mul(829})' *~- [)mul(111,611)how(838,283)+#{>when()?who(764,939)from()mul(925,978)[*#who(182,485)how()select()mul(538,803)>&where()how()$what() }{mul(671,684)/why(106,337)+<#(mul(453,150)++[--from(475,981)where()&{mul(197,568) &;/mulwhy()~(@*who()/!#mul(466,89)'why(594,849)(select()( mul(30,648)what()from()(select()mul(829,947)mul(903,174),-,@select()from()select()mul(462,421)&when()!when()^%;),mul(631,703)mul(917,971)mul(473,892) don't(){/~>,why()[*mul(800,49)when()why()>%)*who())]mul(571,734)<(mul(283,803)~mul(752,111)why(); %<,(where()'&mul(393,613)mul(257,15)&mul(14,159)]mul(502,324)what()how()when(294,303)-%:when()mul(542,760)>}why(),how()mul(726,492)mul(169,827)^: ^~[ mul(859how()#how()))%@mul(564,652) mul(403,8)~mul(507,846) +!!{[){mul(470,989)#mul(58,989+who()?*{! [mul(498,119)%~{mul(206,173)who()from()how()}%^*;how()@mul(154,721){~mul(451,125)<-mul(386,969)!<:mul(890,369)!*{+]-,where()when()when()mul(657,994)]why():mul(898,340) how()(#who()where()mul(502,23) mul(681,55$( ,mul(807,634)&${what()~what()mul(176,10)'(what()why()@~]mul(564,162)!%select()mul(526,996)!-mul(993,991)/'!?mul(118,854)?~-?mul(74,965)who())-({when()select()]mul(913,115)/[who()where()when()<%!mul, ]~#/ mul(990,573)&from()^}%$mul(226,132)mul(431,657)[who())where(690,880)',- ,mul(21,346)what()how(298,600)-mul(174,190)mul(755,197)who(){>&$what()from(853,522)mul(560,222)what()$when()[mul(933)from(881,714)[when()#~(]{mul(67,261)!mul(775,385)don't()[who()how() where()/mul(381,343)do()<}$%;<>how()'mul(460,761)(mul(83,660)[where()mul(539,808'&select()*don't()(mul(274,997)mul(274,981)}/#who()[]mul(414,738){$do()& mul(672,195)'}<@[&;select()mul(90,631) $*mul(869,108)^$+:([&#!mul(801when()~}mul(827,339)who(851,624)%&why()'when()'mul(586,599)+:'/>when()[!mul(139,133)*'!$){#~?mul(565,566)mul(618,83)+mul(765,263)why()/+how()#'{how(521,404) !mul(344,377)/select(536,767)@why()-why()'where()why(468,917)mul(302,909){:mul(632,525)from()>who()(@who()mul(383,809)<>select();when();select()who()?'>where()select()mul(142,6)*:(>'mul(963,13),don't() how()when()/'*mul(18,872)'mul(465,102)(#+mul(590,510! from()mul(133,919)}[,from()from() (mul(820,448)[mul(442,548)mul(977,871)}who()+select()who()mul(606,74)^:)mul>!mul(129,889)/+mul(310,726)who()from()*what()mul(49,487)/)where()]:mul(615,825)}}don't()mul(266,421)}don't()(how();select(908,869)+how()where()mul(56,163)mul(288,896)mul(872^mul(391,531)$mul(152,112)'^,from()mul(889,862)mul(562,569)^ *{';when()!(mul(236,30)>]-why()]what(83,46)when()/>how()mul(634,71)?,?{^?mul(438,21)what()mul(993,470){<[when()where()from()mul(190,720)/%where()@mul(339,904why()where()mul(123,502);) /mul(178,842)how()mul(737,234) !mul(985,241)**?~-mul(349,197)<[mul(22,535)&(&why()mul(460,416)when()&do()[how()when(), mul(250,415how()@-%*:who()*mul(181,581):@mul(353,992)*when()what()mul(247,102)where()?why(607,695)#don't()?when()from()%@)from()where()mul(738,410)!where(808,172),;:*'mul/^(#mul(545,174)^:when()-$^'mul(670,694(why(117,443):mul(12,180);'@what()mul(314,309)mul(790,161)&what()where(620,466)&who()[-]*where()mul(147,178)why()^][}'~$mul(441,381){ mul(138,111)<+) what()[mul(842,241):(from()how()$:mul(329,926)don't()-@$-from(245,221)]+mul(161,472):/how()mul(178,909)mul(729,950)>]mul(310,170)mul(868,180)}mul(685,89)}what(690,794)!who()!mul(670,698']>~mul(464,132)-when(827,257)?)when()#/?when()#!/usr/bin/perlfrom()--{where())what()(mul(54,26) +@)+mul(601,827)from()how()]'how()[where()how()]]mul(943,407)what()/why()}}mul(516,728)<-+ why() ?'mul(651,195)who(472,480)select()^{}/]mul(159,449)#{select()]>why(457,182)mul(889,383)mul(717,768)~>{select()from()~@{>'mul(25,532#}who())mul(582,481)where()>$?) !mul(232,573)mul(27,868)^~from()#where()do()how()>mul(24,375)'!;,,mul(34,942)?-mul(511,814)<:{{how()}{what()mul(369,392)mul(643,828)mul(12,913)from()~select(){ +$$mul(384,257){who()!{$ )#/!mul(607,455)how()*(( /-+::mul(747,552)mul(333,364)how()*?select(914,438)% ~,mul(257,957)do()where(){+#mul(85,930)when()^'<~^/ mul(538,737)?,%what()*-^ where()mul(959,252)mul(435,422)#where()mulwhere()mul(634,612),}{select(863,784){[do()who()}*+mul(842,759),#what());[}why(616,35)%mul(631,814);where()/)mul(768,481)>{!)>who()who()select()how()mul(432,507)&)!>{%>(mul:$?(?~@ }mul(60,211)what()what()*what()when()+];mul(960,9)- ~'mul(678]+&!mul(252,399)what()?:?} !@>[mul(510,368)mul(674,905)how()/why()^mul(763,579)mul(771,675)mul(565,944)'who(345,580)#~!who()mul(349,192)[mul(673@#+/mul(623,920)&^where()}#who()mul(331from()$'+from()mul(906,455)select()mul(969,326)where()[$(how()[/;/-mul(342,396)>how()[*mul(319,806)~#mul(374,571)who()mul(767,564)%:-[-;@)mul(724,513)%{[$~mul(559,103)mul(495,144)who()<mul(485,851)(mul(935,69)from()mul(745,465)select();/^mul(788,539)}:/+from()select()^/~mul(385,82)mul(939,676)#!%how(){who()?mul(481,330)+[ mul(542,441)%when()!^?select()when()select()$-mul(385,342)?who()how(),who()mul(394,223)@<$@-%%&:#mul(197,885){select()when()+)when():select()[mul(753,360)why()(>;!(mul(91,833*$#mul(979,895)where()@>mul(372,24)%*mul(189,679)mul(97,308)who()>mul(657,601)->*; #&)-mul(906,401) from()(what()mul(808,51)[<{when()mul(723,974)!'@)$^who():mul(947,448)mul(440,545)'who()]mul(319,32)<#select(232,786)select(91,643)what()where()mul(728,960){do())^ })mul(525,770))who(),;why() #&{why()mul(695,142)@]+ )[$&*mul(558,127)how()why(),<,&how()^>!mul(126,171):)}]&don't()^'how()+*^where()where()@mul(331,359) */do()what()):why();where()>mul(715,122)when()(when()from();,)}^$don't()/where()/^mul(242,204)how()mul(910when()what()[,]/&don't()-!how()who()who();from()}where()mul(353,405)where()from()what()who()mul(562,824)mul(333,11)mul(842,629)#}+$^mul(778,805)>mul(806,747)when()!^mul(741,908)why()where()mul(110,482)>&$?mul(579,772)@}select()-mul(636,907)(mul(526,945)-(from()(*what()how():mul(166,764)?'?#mul(246how()#{mul(476,49)*:who()who():,what()-+mul(477,38)&?{;>/mul(544,656),select()*what();what(394,396)[ ?&mul(514,32){^select()@select():#]%mul(964,815)mul(562,410);when();*mul(944,789)~/^$~$-mul(750,209)* ;;how()mul(487,591);?mul(245,365)[[!@),{@mul(651,974)} /]%why()&mul(809,5~*/&&why()>mul(571,244)where()#why()}what()mul(518,122)+mul(579,300)'/select(898,768)>%][$(don't(){[mul(361,809)>[>&];why()why();mul(294,704)mul(331,74)}mul(694,47)]/-mul(399,272)when()mul(104,924)when()what(347,469)>from()~^mul(642,304)when()?why()?mul(429,733)select()#&(}&mul(125,283)select()][who():[ mul(136,666)? when()where()%what()>/how()mul(570,389):]~who()+@!}mul(713,887)?{}select()'mul(98,67)&when()do()when()>mul(536,7)*when()) !'mul(884,110)@#')mul(201,681)from()^,do()'why()#]from()! don't()when()how()mul(420,456)%?,'mul(385?select()mul(916,632)]mul)mul(908,719)$*@ ({/{^how()?!mul(980,215)>what()where()@?why()-?mul(614,656)mul(220,163)?why()how()mul(355,585)%;mul(419,411)mul(184,742)$what()>;don't()],'$(select()mul(736}when(),mul(626,880)who()*,;mul(765,856)<<>why()mul(553,221)^!>$who();mul(813,625)>]* how()do()]<;$<@where()select(774,55);!mul(496,557)#<>,!>)what()mul(222,55)from()who()]',what()/;where()where()mul(136,746)>(don't()]mul(970,908)select()^@)'%mul(237,672):+<@<%%-}mul(498,420)who(839,971)&select()mul(937,73)$&&from()do()mul(996,665)&where()where()%,#mul(143,849)?from(913,546)*{?([&mul(134,708)why()[,'how(166,502)select()#&mul[-mul(205,222)}select()]}( why()@(+mul(898,124?*how()@select()mul(616,898)where(705,139)]@mul(155,570)who() -$,{&mul(89,802)!+who()$do()&~]%>?{ >mul(676,57)< mul(738,600):mul(918,629)['when()~where()from()!;:>mul(161,824)what())from()mul(600,436)~{]what()select()!+&%/mul(996,979)}}who()] $+$mul(206,328)$^)@@/,when()}%mul(130,592)when()select()%mul(50,834)';*@when()mul(73,823)mul(865,121) +,^:mul(71,583)mul(316,791)from()when(){&->why()mul(495,908)@}*where(),how()%mul(645,82how(830,734)who()[mul(398,188)(%where()&do(){)from()from()who()mul(221,419)<:]$^'^)from()mul)mul(693,760)#how()>^why()why()[,'why(370,828)mul(516,571)where(425,351)<,>)mul(661,792{))$~-what())who()#[mul(325,165)[$where()%^*]who()+/mul(346,3)do()-@when() when()>+#*mul(698~ mul(248,163)/~]#{from()*mul(57,514)mul(871,508)[mul(498,284)from()who()select()when(277,99)*select()*mul(840,612)%mul(897,30)#/mul(346,138)select()how()?)mul(354,691)?]what()don't();?;when(244,299)who();when()>mul(224,179)%]mul(50,319):mul(34,718)when()^:+where()from()'from()}mul(943,652)+/why()*why()#%don't() when()#'>+*>mul(231,697%how(175,144)mul(507,740)+~where() :from()mul(755,156)/%$)*+(who(212,81)>mul(927,385)#()do()mul(80,489):*,select()%&%where() mul(911,455who()}mul(651,799)~-why()+*mul(202,247);+%^:mul(940,746),#from()when()mulwho()mul(701,602)mul(183,908)how()mul(12,827)][})how(){~when()$mul(332,704)^)when()when()mul(936,771)#where()/who()who();from()$# do()%where(){^ mul(953,541)mul(207,683),how()~%mul(336,694)why()>@ *!?[from()@mul(924,686)*)%! / )why()[mul(493,198)when()>;<$how()$(]>do()(?~(!&^select()%mul(355,72)}how()~why()why()what()~'mul(936,935)&{what(803,472)from()]@ ,do()@why()*why()[mul(149,595)}]mul(867,291)~&)'%@where()>from(455,831)%mul(646,518)% mul(522,755)];'who()from()select();what()'%mul(555,59)(how()'?[!@do():@{mul(729,27)when()]'*,/,why()where()mul(949,316)how()^who(84,611)[?:#mul(931,532)<% [where()select()@%%mul(383,846)$why()~{/+(@mul(325,437)who()>],select()#;when()%mul(601,128)?mul(10,499)%mul(704,145) >mul(811,825);*{mul(539,875)mul(920,111)mul(509,272)mul(657,901)>mul(464,17)why()what()!why()*])}!mul(736,189)mul(299,45)when()select(169,279)><>[,mul(532,593){mul(627,971)how()who()how()where(291,392)/[): do()!mul(770,718)$&;!what()]?#^%mul(938,624)what():<#how()@!~mul(279,222)from()^++);:?why()$mul(98,818)$(]#{%-mul(891,49)+who(251,742)> what()where()<(mul(526,69)}%when()]/(~#do()select()**+^-from()mul(119,943)what()?from()when()*}( don't()mul(370,463)!why()>who()mul(326,383)!~how(59,628)!; %do()mul(671,969)!mul(747,375)mul(257,559)!?#!/*mul(353,892)select()why()(mul(648,3)how()don't()<~{mul(771,164)mul(576,453)$why()}-@'mul(967,581)* %{:when()where(){*< diff --git a/2024/src/day3.rs b/2024/src/day3.rs new file mode 100644 index 0000000..5f37be5 --- /dev/null +++ b/2024/src/day3.rs @@ -0,0 +1,127 @@ +use regex::Regex; + +const INPUT: &'static str = include_str!("../data/day3.txt"); + +pub fn day3a() -> String { + format!("{}", calculate_part(parse_input_a(INPUT))) +} + +pub fn day3b() -> String { + format!("{}", calculate_part(parse_input_b(INPUT))) +} + +struct State { + mult_enabled: bool, + value: i32, +} + +impl Default for State { + fn default() -> Self { + Self{ mult_enabled: true, value: 0 } + } +} + +#[derive(Clone, Debug, PartialEq)] +enum Operation { + Do, + Dont, + Mult(Multiplication) +} + +impl Operation { + fn run(&self, mut state: State) -> State { + match self { + Operation::Do => { + state.mult_enabled = true; + state + } + Operation::Dont => { + state.mult_enabled = false; + state + } + Operation::Mult(mul) => mul.run(state) + } + } +} + +#[derive(Clone, Debug, PartialEq)] +struct Multiplication { + x: i32, + y: i32, +} + +impl Multiplication { + fn run(&self, mut state: State) -> State { + if state.mult_enabled { + state.value += self.x * self.y; + } + state + } +} + +fn parse_input_a(input: &str) -> Vec { + let re = Regex::new(r"mul\(([0-9]{1,3}),([0-9]{1,3})\)").unwrap(); + re.captures_iter(input).map(|capture| { + let x = capture.get(1).unwrap().as_str().parse::().unwrap(); + let y = capture.get(2).unwrap().as_str().parse::().unwrap(); + Operation::Mult(Multiplication{ x, y }) + }).collect::>() +} + +fn parse_input_b(input: &str) -> Vec { + let operation_re = Regex::new(r"do\(\)|don't\(\)|mul\(([0-9]{1,3}),([0-9]{1,3})\)").unwrap(); + + operation_re.captures_iter(input).map(|capture| { + match capture.get(0).unwrap().as_str()[0..4].as_ref() { + "do()" => Operation::Do, + "don'" => Operation::Dont, + "mul(" => { + let x = capture.get(1).unwrap().as_str().parse::().unwrap(); + let y = capture.get(2).unwrap().as_str().parse::().unwrap(); + Operation::Mult(Multiplication{ x, y }) + } + _ => unimplemented!() + } + }).collect::>() +} + +fn calculate_part(lst: Vec) -> i32 { + let mut state = State::default(); + + for operation in lst { + state = operation.run(state) + } + + state.value +} + +#[cfg(test)] +mod test { + use super::*; + + const TEST_INPUT_A: &'static str = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))"; + const TEST_INPUT_B: &'static str = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))"; + + #[test] + fn it_solves_parta() { + assert_eq!(calculate_part(parse_input_a(TEST_INPUT_A)), 161); + assert_eq!(calculate_part(parse_input_a(INPUT)), 183788984); + } + + #[test] + fn it_solves_partb() { + assert_eq!(calculate_part(parse_input_b(TEST_INPUT_B)), 48); + assert_eq!(calculate_part(parse_input_b(INPUT)), 62098619); + } + + #[test] + fn it_finds_multiplications() { + let muls = parse_input_a(TEST_INPUT_A); + + assert_eq!(muls.len(), 4); + assert_eq!(muls[0], Operation::Mult(Multiplication{ x: 2, y: 4 })); + assert_eq!(muls[1], Operation::Mult(Multiplication{ x: 5, y: 5 })); + assert_eq!(muls[2], Operation::Mult(Multiplication{ x: 11, y: 8 })); + assert_eq!(muls[3], Operation::Mult(Multiplication{ x: 8, y: 5 })); + } +} diff --git a/2024/src/main.rs b/2024/src/main.rs index 0dd1945..4067764 100644 --- a/2024/src/main.rs +++ b/2024/src/main.rs @@ -1,5 +1,6 @@ mod day1; mod day2; +mod day3; fn main() { let day = std::env::args().skip(1).next(); @@ -9,6 +10,8 @@ fn main() { Some("1b") => day1::day1b(), Some("2a") => day2::day2a(), Some("2b") => day2::day2b(), + Some("3a") => day3::day3a(), + Some("3b") => day3::day3b(), _ => panic!("unrecognized day"), };