From a0f3f77519cae9d3379a2415931d1f0ac5e92b6b Mon Sep 17 00:00:00 2001 From: h7x4 Date: Tue, 3 Dec 2024 08:31:04 +0100 Subject: [PATCH] 2024/day03 --- 2024/day03/default.nix | 47 ++++++++++++++++++++++++++++++++++++++++++ 2024/day03/input.txt | 6 ++++++ 2024/flake.nix | 1 + 3 files changed, 54 insertions(+) create mode 100644 2024/day03/default.nix create mode 100644 2024/day03/input.txt diff --git a/2024/day03/default.nix b/2024/day03/default.nix new file mode 100644 index 0000000..da674c0 --- /dev/null +++ b/2024/day03/default.nix @@ -0,0 +1,47 @@ +{ pkgs, lib }: + +with lib; + +let + input = fileContents ./input.txt; + + answer1 = lib.pipe input [ + (split "mul\\(([[:digit:]]{1,3}),([[:digit:]]{1,3})\\)") + (lib.filter isList) + (map (map toInt)) + (map (xs: (head xs) * (last xs))) + (foldl add 0) + toString + ]; + + answer2 = lib.pipe input [ + (split "mul\\(([[:digit:]]{1,3}),([[:digit:]]{1,3})\\)|(do\\(\\))|(don't\\(\\))") + (lib.filter isList) + (map (xs: + if elemAt xs 0 != null + then (toInt (elemAt xs 0)) * (toInt (elemAt xs 1)) + else if elemAt xs 2 != null + then "do" + else if elemAt xs 3 != null + then "dont" + else null + )) + (foldl ({ toggle, sum }: x: { + toggle = if x == "do" then true + else if x == "dont" then false + else toggle; + sum = sum + (if toggle && isInt x then x else 0); + }) { + toggle = true; + sum = 0; + }) + (x: toString x.sum) + ]; +in + pkgs.writeText "answers" '' + Task1: + ${answer1} + + Task2: + ${answer2} +'' diff --git a/2024/day03/input.txt b/2024/day03/input.txt new file mode 100644 index 0000000..9c2c542 --- /dev/null +++ b/2024/day03/input.txt @@ -0,0 +1,6 @@ +what(){mul(697,542)/>why(479,94)mul(995,893)why()]%?:]select()%}mul(408,907),{from()$&&/mul(893,282)[#%@(who()what()!~mul(313,566)@@how()$mul(964,183)]how()where():?what()>%mul(743,40)*']~+/!mul(241,491)<{]<)]from()how()'from()don't()&where()%how(216,229)how()where()!mul(35,991)when()why(610,462)> select(594,57)$}&^mul(699,136)}]?who()when(){mul(970,603) ?mul(200,732)/[:select()(mul(967,199)+select(),/!how()when()mul(521,824)#;]:+&->)}mul(473,278):$&mul(347,457)}&*why()~ when()mul(324,773)-$ mul(460,152)#-;~,when()@mul(331,186)%don't()]-mul(197,390)how()mul(774,494)/from()))how()),mul(758,549) >why()mul(485,656)where()~-mul(938,190)&mul(326,51) mul(304,567)mul(165,576)+'-]when()'+why()/mul(906,352)from(618,898)where() how()#~mul(508,347)what()when()/&^why()why()mul(847,535)~ #)from()what()$)/do()//)where()what();where(200,117)how();+mul(242,61)?:-?mul(371,193)%%mul(173,850)*from()why()# ,#)mul(566,907)&don't()/how()&mul(412,399)}^why()from()mul(905,46)^from(169,718)!(when()mul(920,500)*don't()who()how()what()}why()-]who()who()(mul(927,865)@select()mul(371,913)mul(254,979)-select()mul(614,684)$;,{mul(841,422)!when()^mul(292,172)/]what(),&]mul(668,298)what() mul(788,698))&mul(241,230),*mul(513,152)}*:[/mul(762,255)*/mul(199,330)how()')^mul(716,272)}#-select(196,254)-&how()*mul(181,411)@){]#%:,mul(830,669):-[>!select()who()mul(490,309):mul(597,806)who()mul(911,931)when()]:mul(749,304)select()$who()*&$:!}mul(499,106)why()select())when(453,833)~%^don't()who()<]]>}{(mul(666,746)@&where(){do()from());why()where()#mul(436,226); what()^from()~when()*mul(333,877)&[mul(849,387)mul(846,509)$mul(690,845)where()what()-~where())mul(120,516+'[;where()- mul(671,693)]who()#/mul(151,226)'what()mul(662,390)when():don't()how()mul(586,859){who()+}*?select()*}[mul(162,392)##who()!don't()^from();select(183,354)+@#+how()mul(235,965);<['*@*&mul(836,254)#who()^,{~*&from(912,964)mul(81,63)('who()+]who()who(616,562)&[don't()-%select()>why()&:*mul(148,501)<'?don't()/'%$when()+#mul(565,716)how(551,943)~>':)mul(812,235)(who()@what()do()mul(933,530)mul(516+when(95,848):what()/~mul(685,485)why(){[<^,from()-why():mul(372,990)^mul(780,194)~(when()-$> mul(158,500)where(213,721)where()-+mul(783,720)]select()mul(830,674)-*,;^)mul(542,769)<>;@;mul(340,494)~,mul(972,343)-*{<}*why()'&@mul(995,93)}/}^&mul(632,3)~mul(151,607)'~who()~+ why()select(970,692)mul(253,471)what()}select(450,660){mul(186,635)!'from():>;@+mul(109,407)mul(231,530)who()'mul(721,360)(#{what()?mul(764,403) mul(974>mul(700,804)>:>select(108,396)-where()where()~#from()mul(618,688),?*mul(786,325)']who()-([mul(312select()do()from()@%mul(647,88)+!mul(920,442)where(){$mul(876,103)select()select()&<-~';#mul(658,434) +what(203,778)-)]mul(25,629)why()^$~)?why()mul(207,846)(from(560,549)select()&-]?>what()mul(782,867}(^}^mul(48,779)<$where()how(396,689)mul(623,278)}select(34,689)when(),how()%({;$mul(494,74)*from()when()mul(35,522):> &&when()mul(328?}mul(186,822)]when()how())why()mul(775,741){->%mul(812'{~;mul(202,822)-mul(282,383)what()from(340,89){mul(729,896),^-what(313,84)mul(172,196#mul(447,361)why()&*?/who()(+mul(395,872)#^^{@,-mul(394,873from()%mul(988,272)(%select()!~mul(101,388)what(),how()how()$#how()*mul(551,577)%what()mul(191,793)''don't()mul(744,26)!select(){'>,mul(140,452)mul(887,632)#>}{;@^+-mul(835,39) how()+/-}*},@mul(66,401)what();why()]] %+&do(),when();:who()[select():mul(474,260)who(),{,)}why()%who()mul(126,874)}where(746,668)>mul(60,400)~#select()select()@:mul-@*%when(134,304)?how()mul(18,684)what())'&/ ,{^mul(770,406){{@* {who()who()-mul(312,245)/>{when()why()from()^&mul(936,201)&from()-#$(mul(970,306){%from(193,334)mul(770,300)how()don't()mul(17,145)(%mul(204,15)]#!mul(592,786)+?what()*^mul(903,387);}($mul(977,422)where(136,281)mul(412,540)select()@&,mul(331,930)where()!;%why())!mul(647,169):!mul(624,260)>,^^!where()#+mul(364,706) why()[when()(?from(361,489)~?/mul(572,99){mul(162,620)select()#?'$)mul(963,810)(<'^mul(381,182)mul(154,418)(mul(307,576){;select()mul(872,424)[,{&){&/mul(542,342)&*(when()+#/>mul(29,665)$don't()?where()mul(903,998)%?select()])#;mul(660,171)who() why()>what(), mul(956,616);,$,}mul(982,695)-:where()why()mul(585,888)why()where()]!&{mul(422,906)select()where(721,370)mul(673,348)from() mulwhen()~don't()',@&+]]where()$ mul(813,553)+'who()-where()select(){{,:mul(535,550)how();&;what(992,219)mul(564,279 mul(551,875)?how(920,226)(+;+?;^mul(383,579)?##%{ [*mul(576,484)>:}<,+when()do()>who()&#how())]what()mul(272,737)-/,who():;#+~]mul(580,211) :from()[&/what()}mul(893,368){*&+mul(393,508)}-!^when(962,123)]@/mul(184,205)when()]]when()'who()mul(249,915)when()from()-@/ how()~mul(495,101))<(}+%,:?,mul(356,636when()(why()^]]mul(662,103)#mul(118,597)mul(968,629):why()@]mul(676,360)select(),'select()-,mul(579,23)@why()@$:what()mul(370,656) +from()'/,what()/<,%how()mul(748,154)>[select();,who()>select():'mul(663,830)%@(mul(417,364)-why()'mul(947,551);!/)!++mul(385,221),>%#mul(410,27)}from(669,909)&who()~:'<)how()mul(203,50)why():$who()from()^{^(mul(425,96)why())from()#*&[}mul(657,805)why(){$&mul(764,125)what()select()mul(118:%;do()where()@why()@{'mul(3,361),/mul(9,725)who()from()'from()}>@*!mul(258,517)@! !}[mul(734,173),>~mul(567,929)>^$%}?mul(458,106),-mul(904,99)#where():!mul(304,344)('] )mul(474,433){]why(552,617)[*>*[?mul(292,452)@/when():mul(671,8)what();mul/*&mul(157,964)):+$^:select()mul(577:@(mul(481,28)mul(120,742):+&@mul(932,682)don't()#~,]{mul(584,430)don't()!who()]]/$when():mul(447,144);)~#mul{select(899,436)}:when()mul(18,3)$'why()/ select()*(~from(848,249) mul(402,212#(when()what(526,893)(when()who()!select(855,813)mul(267,568)?when()~?mul(790,400)how();:%mul(565,976)*}how()what()>+from()from()#don't()>what(465,504)+,+/@^mul(702,607)/%mul(775,709)from()what()$(where()^what()why()when()}mul(728,176)&$~mul(732,727)^'&mul(999,652)']~mul(780,700)-~&{-{<*select()when()mul(729,462) mul(105,648)@;,?^#!how(963,469))mul(906,654)&]who()from()&mul(881,852)how(),how()where()where()@(<(from()mul(822,522)mul(874,978)mul(233,399)select()from()>/;where()when()^[why()mul(474,473)where(896,324)^mul(638,197)}how())-{>how()why()}>mul(611,521)mul(364,693)why(),-&where()+># how()mul(53,996)/<[where(204,56)<-;}~(mul(547,235)+where()~%why()'select()mul(407?%%]/how()~>^mul(749,65)mul(171,190 why()%+?when()when()&how()]!@<+%don't():-@{who()#mul(104,125)when()>{<-%mul(627,539)when()]how()-select()]mul(983,406)+where()]-when()when()mul(537,478)from()#~)how()mul(305,547)/&?)%+who(){do()^who()why()+*select()@#^mul*+!mul(324,352)*{why()select()when()where()how()++@mul(758,823)>from()(how()mul(155,143)how()$[] +-mul(220,494)<#how():&@what()mul(996,77)],<}^where()%mul(153,549)/$&}[[#):!mul(974,546)!where()mul(406,100)mul(684,435)mul(36,14)*,$@~,don't()<{@*&mul(302,244)mul(934,996)}-when(),;where()->mul(184,150)<~/!){mul(457,435)/select()mul(692,366)mul(294,439)(*where()who()why(124,291)$how():don't())mul(238,489)[;(^&/}select()>@mul(199,347)(<(#mul(135,803),what()where() !):!mul(119,226)-)],who()mul(443,526))how();where()mul(652,762)from()$)'$^[!mul(915,54)%'what()where()who()mul(685,223)^how()$]/'mul(660,757))mul(401,390)!) ;what()what()@{:mulselect()#( ?where()[+when()mul(677,473)~@:select()]*mul(368,274)#%{where()mul(387,806)!@why()select()''+mul(673,924)}?%mul(544,205)%? when()+mul(990,513)@'&:(]mul(115,860)?-<*>how()mul(452,49)>mul(672,248)why()~where()^+[mul(15,506)>}don't()}~,~when()mul(732,173)mul(26,691):where() where()who();when()}mul(483,470)+/ select()mul(693,863^/&mul(999,441)what()&select()?, ?*why()when() *mul(114,59*[>{-{#!/usr/bin/perlwhy()mul(247,67)?what()when()%what()@'{+mul(453,52) +where()mul(231,244)>>/where()mul(216,829)who(){%mul(552,537)when()]$mul(185,377);}>where()::why()mul(300,903)]#!mul(61,613)/mul(106,584)^,'?; &'select()~mul(145,411))?what()+&how():&mul(139,18)/where()< ,from()+&don't()#% ,*mul(158,236)^,(what()!?mul(861,544)]:who()how()-*how(),mul(103,378)+):what(712,256)-+$:from()(mul(172,254);?;how(){{}@mul(812,458)how()(,:)))~mul(256,397)#]from() >?where()[~mul(132,458)/<[mul(441,730),&+mul(410,879)@@select()@$from(424,812)-mul(80,361);(select()$!:?mul(3,489)(mul(692,445)-?:[;/@mul(630,252)-<:~how()%:mul(755,275);}why()*]who()$'what()mul(404,857))}when()}:mul(795,571)}?'?what()&>who(709,757),[mul(85,479)[^ /mul(12,677)mulwho();@]why()mul(507,433)how()%;{mul(703,269)@'from()&}mul(195,324%where()mul(333,588)who(210,905)@{how()-why()don't()',~^who()mul(976,376) ;mul(617,616)+don't()~how()^/},#&how()~mul(464,668)>(%$from()>what()mul(330,462)don't(),$]~mul(47,160)select()'-<}^what()mul(813,866)@mul(932,649)from()how()when(){]^^$where()mul(298,181) ^ '!*:mul(395,824);>>@->!%mul(169,544)when()what(165,141)]$',>?$mul(677,950)+<#[select(680,459)mul(104,437)how(){mul(238,478))+#:(~where()~mul(990,466)<~#mul(67,165)where(103,910)@(when()^*~,when()'mul(820,708)]}&when()?%#/mul(489,883)[{ {^where()mul(278,843[mul(865,505)+'why())mul(545,55)(:{+mul(248,445)?mul(391,995>#-,*%^ mul(354,732)!/mul(619who()^*[,~[~>$why()mul(723,806)who()from()[why()?$>&mul(721,363)>what()how()]^+mul(301,140)^~:~who()mul(469,571)~mulwhy()from()+'<'don't()&<~mul(219,408))^mul(215,767)-]mul(519,445)mul(907,35)what()-!^why()what()-how()select()mul(742,645)mul(213,651)&+when()mul(942,859)^*from()mul(871,479)<^mul(88,805)mul(397,727-([*select()what()what()select()$/+mul(24,343),@from()mul(594,62)+['from()#mul(807,849)~%+*}mul(552,461)]from()@!@#select()who()^~don't()?;]mul(201,836)&+&>mul(741,810) +mul(695,640)[mul(908,779)+/mul(78,761)[+?};*{mul(105,818) [from()-mul(451,768)what()]!what()from()what()when()~^mul(619,244)[from();,&from()where()from()^?mul(899,374)when()#^:/mul(541,467)/mul(692,925)why()how()what()>/:^mul(463,858)how()where()^:[~mul(31,347)?<})*>!/mul(627,404)do(),?^$when() mul(24,930)mul(873,35)select()what()where()/don't()&& [mul(248,460)&where()from(45,338)*?mul(16,424)'}mul(9,674)<}select()$@mul(985[mul(441,498)]what()@'/{mul(626,540)[;/%,mul(764,748)mul(867,602)why()who()what()mul(885,438)who() ]-{'~/>mul(668,937)&(mul(973,416)when()mul(647,557)~how() {+?@mul(485,856)how()select()when()/select()mul(33,198){!mul(382,685))why()!*mul(711,362)<*what()mul(645,252)from(479,19)where()who()mul(561,165)?>$*?:mul:#mul(877,920)#:-mul(440,17)how()>![,@+]mul(151,701)}^[$*mul(353,641){^$+>~%{;}mul(39,274)*mul(657,123)how()*where(){mul(346,442)mul(790,227)?when()>when()(!%mul(60,33)&/$where()}$-<:{mul(930,295)%from()how()@$from();who();mul(494,10 #mul(700,474){^mul(552,224)~'how()select()%}mul(5,285)mul(833,131?%>/from()mul(457,368)^'>%>mul(233,98)[' <^mul(312,497)mul(933,575)who(){mul(859,323)-mul(484,721){where(445,310)),>}!;,?mul +)*:%?mul(122,560)what()select():+mul(749,209)mul(478,283)&#mul(67,742)@^mul(494,481)&%from()':!/&:why()mul(768,612)where(),:]$mul(512,595)mul(658,426)what()+>)where()%&mul(213,517)++what())what():who()mul(891,196)@when()why()mul(46,798)@)select()[how()mul+from()select()mul(128,259)when()/select()when()-*):}mul(115,723)select()@where() mul(235,95)mul(507,424)why()] !mul(680,738)/<&$)>mul(349%]how()mul(719,909)when()%*mul(27,357)mul(734,373)/{>%;[$!mul(733)why()&mul(938,12) +from()#,why()~& ;#:mul(731,521)*how()} do()mul(399,167)from()mul(71,499)how()from()%!who():;mul(730,287)why()mul(422,401)select();@+[-mul(742,851)< ^$why()mul(153,315)+%mul(206,613): ,from()[~select()mul(971,155)[%*:&{mul(239,834)'#:{'~$;mul(224; mul(163,711)$$/!select()^%do()&where()>@*from()select(719,23)#:,how()>from()mul(874,522)'what()!from()*select()mul(950,277),<@-!*mul(35,822)>)~*mul(934,771) #mul(752,754)how()-from()+who());]:where()/select(297,243)!%+mul(603,67)#]}what()mul(486,614)mul(761,335)! %:[;from()^when()mul(162,639)(({;%) mul(410,831)mul(74,9) [),}!!+?&mul(365,386)?do()&from()who(486,875)why()mul(545,922)*mul(333,104)where()do()~$^who(),[;mul(357,374)$}what()/from()^when()}/mul(828,346)mul(128,556))*{:from()@mul(277,303)#[^-%]how() /mul(817,849):mul(477,520)&$what()}<{]#]^mul(263,446):%when()-&how()from()[&>mul(307,210)]!+mul(293,549){when()~mul(478,825)&what()')%mul(233,939)%]>;>}]mul(680,156);}~mul(66,418)when()/]'? select()mul(506,752) ?select()select()%,}mul(685,266)(from()mul(354,792)~+;when()~#where(){mul(745,146)mul(926,660)%mul(721,86)~?&#?mul(964,815){when()-why()mul(333,175)mul(490,526)when()^mul(370,894)>&who()'^mul(686,63)~[?!%'select(){mul(543,91)@#mul(43,96)where()mul(278,584)~%)where()%mul(163,853)&#when()'mul(561,872)#when()where()'~don't()mul(896,297)<'>@mul(919,548) who()how()?@+when()]%(mul(691,41)$;+]&who()-**mul(272,776)}what()#why() what()who() when();mul(824,393)-@ %[^,why()do()/mul(891,874)$'<!&@** )mul(437,39):]'mul(255,961)!what()!mul(22,237)~mul(287,360)select()how()what()}^mul(153,348){when()&)}{/{mul(8,764)how()@}mul(231,703)why()>%~!when() ^mul(418,457)select()how():?who()$when()when()mul(957,951){'where()'mul(6,320)~mul(168,639)^!mul(715,855)~select()^mul(44,209)&mul(767,449)mul(503,357)^where(),]select();mul(571,436)]-select()select()& diff --git a/2024/flake.nix b/2024/flake.nix index 7eebd92..2b86c2a 100644 --- a/2024/flake.nix +++ b/2024/flake.nix @@ -10,6 +10,7 @@ packages.${system} = { day01 = pkgs.callPackage ./day01 { }; day02 = pkgs.callPackage ./day02 { }; + day03 = pkgs.callPackage ./day03 { }; }; }; }