From 9ce100f7a4177cd06bbb136a4d26db1ba58f4552 Mon Sep 17 00:00:00 2001 From: Emile Date: Tue, 3 Dec 2024 21:01:33 +0100 Subject: 2024 day three part 1: converting all the given mul() values to their infix notation and summing up the list part 2: removing everything between the don't() and do() as well as between don't() and the end of the line, the reset is the same as in the first part --- 2024/d03.example_input | 2 ++ 2024/d03.input | 6 ++++++ 2024/d03.lisp | 37 +++++++++++++++++++++++++++++++++++++ advent.asd | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 2024/d03.example_input create mode 100644 2024/d03.input create mode 100644 2024/d03.lisp diff --git a/2024/d03.example_input b/2024/d03.example_input new file mode 100644 index 0000000..6a7899d --- /dev/null +++ b/2024/d03.example_input @@ -0,0 +1,2 @@ +xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5)) + diff --git a/2024/d03.input b/2024/d03.input new file mode 100644 index 0000000..b90eb9c --- /dev/null +++ b/2024/d03.input @@ -0,0 +1,6 @@ +}why()'//mul(118,270)who(768,873)'mul(303,230)'{how()when()<@,}mul(512,183),']why()(who()&$(((]*mul(901,328),what()@<^])-mul(933,154)mul(560,337)$mul(173,233):why()when()*!+@?/how()mul(372,472){/how()-'){mul(851,778)who(667,458)^+]-/where()from()#why(593,555)mul(815,971)mul(358,457)?mul(69,599)^-)/!mul(464,350)why()who()what()where();mul(110,980);who()][how()~^who()^mul(288,178):%(@&,mul(30,469)*select(308,586)why(15,330)~@mul(446,558){{'why()?select()%~'$mul(845,144)#}}%-@;),#mul(111,87); <#mul(645,89) ~+mul(185,720)why()what()(&how()<'why()[select()do()!^'({!'>#[mul(112,567)*mul(554,555)-why()@<@from(983,810){$->mul(701,70)mul(850,508)where()[-@(how())'how(259,50)mul(600,526)select()}how()%?mul(374,167)who()@>where()(&/-(mul(908,717)/from()do(){:&(mul(438,764) ;how(){]]mul(755,362)how()when():~$mul(594,595)select()?{%#]mul(299,480)(],mul(310,106))(when()/#+&where()^mul(417,560)?,-,mul(974,911)^)(^where()@&$:{mul(363,316)where()how()>> (&do()-:-what()]}mul(791,291)(where()>where()mul(510,827)@mul(676,96)^what(677,473),@>~what()!(mul(307,685)from()!mul(503,867)who():$, &;mul(615,600)select()<+mul(337,796)from()who()/+mul(810,119)'/;'>[+from()mul(803,4)$mul(840,8);%from()( $#mul(451,85)[what()/mul(581,231)^(mul(388,767)# <}:(>#$mul(712,740)select()what()*'mul(991,610)from()&who()mul(350,378)?when()%@%mul(548,504)what()?from()select()when() select()(@mul:select()where(673,310)@]~##;+~mul(709,342)%/'select())<,-!how(998,965)mul(115,998)&$who()]^+mul(816}'mul(861,544)*mul(712,683)*where()*mul+who() mul(507,89)when(),where()why()}mul(142,592why()don't()what()select()]?~why()from()#mul(495,289)]don't()when()(how()select()*mul(965,272)#?]$who();*[where()}mul(40,185what()/{[%'-+mul(232,472)$,-;why()@;~%:mul(868,459)when()[!/mul(498,100)where() ]don't()>!why()+}}@mul(352,210)]where()]mul(871,480){;@where(570,531)>^>@why()mul(918how()[how()from()>-when()how():$do()from()when(686,735)what()mul(29,449))%,){from()<^mul(347,529)select()#@^'!mul(918,57)mul(452,298)who()<@@%mul(262,346)}mul}'[why()where(232,142)where()%@mul(315,783)select()why()+! '+mul(752,60)$,where()?from(562,430)from()+what();select()mul(613,622)>%(%?{/$,mul(324,777)@mul(822,618)$?!^+what()]*@mul(82,101)from():don't();'mul(401,508)%]:{do()+mul(684,164)&mul(842,202)?mul(537,560):]/#where())mul(252,281)mul(947,848),?-,why()]why()-(&-when(825,688)?!mul(135,114):#who():from()how()@from() mul(218,304)(how() mul(122,702)who()when()what()mul(205,492)%select()how()-$'how(981,279)/mul(566,410)!#'~+?*mul(424,391)!>~?]?who()$mul(358,17)select()from()*#(who(150,183))mul(321,517)what(){ };+mul(713,463)mul(204,996)?:{don't()from()]/:/where()mul(507,272)(why()+[mul(735,631)(>%^select()where()<;why()when(227,974)mul{{[^(what()$who()mul(604,486)}what()&^mul(663,982}:@'from()*@where()where()@mul(935,362)from()>,what())why()mul(623,825)?how()! what())mul(626,311)mul(139,132)what()][~mul(751,662)~+mul(438,610)@}(what()who()mul(767,302), ,,when()^?[-mul(471,308)mul(976,991)'mul(269,398)mul(173,284)don't()from()^who(),where(617,2)'~&~mul(315,31)[mul(712,183))when()why(422,253))~)mul(3,475)why(), />)mul(590,407)~ mul(17,899)({#;!]why(492,922)}*mul(378,281)/~select()$&mul(823,754)]who()what()*who()&]~$[mul(429,753)(?%mul(239,858))~)(select():why()!/mul(937,986+?%mul(693,566)@~$[?where()how()mul(884,538)$-#>}^where()mul(807,596)+[#)what()*mul(639,471)@^mul(696,49)when()!who(){/[mul(536,203),&/*what()}+from())mul(253,902)who():;>(&[! how()mul(864,941)$what()}%mul(667,63)why(937,909)mul(889,670)mul(714when()(-'?$mul(180,62)who()don't()-~%* (]&/mul(921,30)#<*mul(377,439)when()@#&) $;,mul(502,135)> %how()(mul(575,256)from(344,32)[)>*!#!from()mul(952,916)?what()-!from()~'~-mul(200,329)>~&mul(136,236)why()what()from(974,917)]%#'mul(334,430[how()mul(746,835)%,when()when()how())how(116,124)*~don't() [[mul(92,213)mul(311,118)mul%where()?,^mul(748,529)why()!%who(343,61)@'mul(107,422)-$what()mul(519,984)+mul(247,993)@how()mul(445,607)+when()select()>#]<:mul(712,489))]:!>-mul(309,814)}~{{mul(469,161)[ $&<, mul(333,699)select()how()~where()$>'why()'mul(120,359)<> ,who()mul(779,344)';where()select()where()where()mul(478,350)'mul(545,404)>^mul(119,935)mul(270,275)(>]<(@}{why()%mul(252,483)+^who()?:mul(799,687)mul(681,69){(>-({! how())mul(959,981){why()+#$#mul(847,571)>how()where()+#+;mul#what()##{)why(977,32)mul(775,241)*^$$mul(631,346)^mul(176,286)(}>mul(259,816)^what()/;where()mul(186,159)-mul(356%* mul(973,339)select(29,574)(mul(662,949)(,}]]:)@:$mul(414,624):what(744,710)$(where(845,81)(where():^-mul(393,602)%who()'what()%//mul(876,476):^from()}mul(25,827>where()+mul(645,484)!,from()select()how()when()?mul(611,534);@$#^where()^do()mul(740,610)what()),$select()+how(157,566)mul(799,230)why(),/)}mul(200,261)+[why()@'where()mul(789,694)[where()*mul(739,893)]select(240,411)#what()why(452,335)'!from()mul(693,670)mul })'{@mul(136,164)#what(697,123)mul(488,469)mul(699,486)when():!<{when()!;(-mul(250,187)mul(963,768) +&$where()mul(667,799);-?#[how()mul(76,673)&mul(655,832)mul(38,149){select()[]~what()~*-/mul(40,279)'&':)where()mul(41,642)~'{why()-;}do()mul(637,913)%from()what()why(843,492)who();where()mul(955,620),~^mul(65,246)[what()mul(371,783)mul(28,28)@&!;from()'$;$'mul(696,738)}*why()+{$what()}@[do()why() @mul(717,401)@mul(26,14)who()};mul(89,550)where()(/}:mul(933,395)/ where()]when()*}what()mul(438,50)@~why()where()mul(981,354)!/how()& {{'mul(993,32) when()#::)-%mul(463,369)&*/!what()mul(27,251):how()%what()who()mul(601,17)>%@}{)+%mul(885,36)?where()^]>#^!::mul!> mul(925,9)-?,}+mul(581,736how()-!:%:$when()?'mul(773,255)why()&!:@mul(845,444){{how()'?;what(517,790)mul(696,38)select()[what()}>!where()how()mul(811,22),^?;&when()$+do()!from())why() mul#mul(596,324)-)who()where()'why(){[*mul(970,725)mul(483,163){why()@-mul(252,847)mul(43,344)$select()[#>;-'/mul(601,165)}when()+)(do();,}:!mul(448,672) how()#who()%mul(190,349)who()?}>what(983,363)%~+when(310,649)do())select()where(),!{why(),+mul(753,969)&from()'from()-mul(104,450)}*when(954,601){[mul(921,416)[how()<@mul(7,763))&{'? *#+mul(779,726)&why()from()from()'mul(106,883)@#' -mul(611,347)(:?from(667,84),do()<%}~why()mul(185,68)why(){%+mul(337,293)+!*do();]&what()where()~<'mul(854,474)when()when(155,160)from()/mul(692${why()mul(861,971)mul(231,449)from(810,328)mul(601,111),why())&mul(729,424)&%how()from(){mul(644,983)mul(690,678)where()^?[when(42,440))^why()~/mul(479,640)+#)#!mul(866,747)select()why()%(when():when()~>!mul(642,24){,<'{@what()mul(611,467):[+when()'why()-how()mul(208,780)}:what()>when(),?${mul(984,967) });:-where()mul(7,25)-*#+mul(194,428)-:mul(759,215)>[how())select()%where();*mul(733,566)mul(973,795)!+#?who()}->/(mul(136,439)&(]when()from()from();mul(361,515)mul(358,692from(418,750)mul(622,248)^mul!^<[}{ $&~mul(87,202)*]*:{select()mul(436,301)-select(554,468)why():}select()!select(521,422)why(519,757)mul(463,564)}{@$^%^}mul(413,702)-who()what()mul(328,417):when())%%[why()where(139,261)'mul(185,197)#-%#who()!mul(424,502))*$mul(103,169)$:>*mul(35,491)^,?~$*when()})*mul(547,91) <{,@how()/{who())mul(726,110));{from()from()]mul(531,413)from()')when(171,646)$,!mul(543,983)!}%;mul(869,168)[mul(4,221)%what()*)//'*}#mul(419,518)^select(470,492)!<'];mul(732,29) ^#!/usr/bin/perl-<^^who()#%mul(416,256)-when()&[(mul(505,988)#mul(2,99)'mul(705,78))select()%%:why(961,835)do(){^how() ##];)mul(75,818)?mul(867,177when()who(){!when()#@?how(620,209)mul(719,215)>mul(425,95)#who()$,):!]when(807,62) mul(768,881),select()select()#;)what()>when(){mul(884,649)!($'mul(81,716)--mul(291,703)what()^*when()>what()>mul(984,216) mul(851,821)when()%*;]-[]where()mul(739,700)%mul(602,611)mul,(from()!@#;'mul(531,169)*!-/+}mul(381,684)&-[mul(81,918)*:~what()what()mul(790,653)mul(783,688)$why(842,893)why()}%^why()mul^,mul(384,215)[);{mulhow()select() 'why()~](how(401,376)mul(357,497)$&{%[{mul(756,803)do())who(976,660)&;how(){mul(145,93)++~why()(who()why()$mul(249,134)-@do()?!from()}:]#}mul(860,885)<@!select()~&~mul(298,587){mul(83,672)}where()select()mul-from()?how()when()[mul(446,654)'where(86,144)mul(756,482):$!when()mul(362,152)when(718,744)[$;*mul(175,942)how()#:^~mul(137,173)#/,mul(420,452)?mul(441,166)+'?~mul(791,603)]from()!<]select()mul(613,19)>(]:+[(^ mul(717,644)-*&]?^>when()how()mul(296,272)~select())$/where(522,54)~do(){~who()who()]mul(316,608)when())^*how()]mul(495,232)-+(why()@>mul(639,382)-who()& {/select()mul(291,99)!:#how(351,490):how()mul(377,33)how()mul(28,775)^})'!#mul(242,893)what()~<;}what()mul(924,588)mul(347,457)select():@%how(36,570)?%~+mul(711,346+when()>mul(905,158)@$@what(391,59)(*&'+mul(882,946)?]why()$[ ?-#mul(500,131)>;who()<,,#&mul(690,752),*mul(837,527what()+mul(295,646)mul(114,435)@mul(397,480)mul(61,601)>mul(182,569)?'%]]$where()mul(208,113)who()@;mul(304,729)?@!why()why()&[mul(229,620)]?$!&*>how()mul(631,756)[who()&$mul(780,130)select(839,694),select()why()mul(287,748)-,select()]{{when()^from()mul(734,124):who()&?why()from()do()?%when()#<#mul(264,205) -how()mul(779,117)&]when()select();~><;mul(251,268)how():&~mul(52,357)[>mul(412,943)select()[~<~:[mulwhy()what();''{},how(309,278)[mul(350,684)what()select()what()]*;when()+mul[}select()select()mul(213,834)[who()}+!from():when(354,344)'from(256,952)mul(434,306))<<;mul(551,895)how()%{%%'>mul(374,273) where(){:what()how()mul(159,521)^from()select()%select()~/who()mul(309,690)#@]mul(827,955)mul(120,163)@&)~what()+,+mul(187,497)$mul(822,633)from()/,when()mul(209,101)?^,mul(92,994)()(@/(@mul(289,361)]@%]/select()what() %mul(147,165)!:[{&{:mul(469,356)*([when()mul(815,209)(mul(739,644)?why()where()>mul(406,53)}&mul(849^,$how()mul(801,824)'[when()$!where() :who()mul(515,882)who()mul(746,75)mul(161,191)'when()$mul(244,293) ++!]'who(){^!mul(96,937)(*mul>:[>mul(669,292)!select()mul(554,803)!select()/mul(694,221):[;{when()!)$@select()mul(622,609)$'{'mul] ^/why()mul(688,97)mul(189,206)@)&from()$where()mul(649,932)mul(572,58)#',from(759,777)what()@+mul(790,678)!&+;*@~mul(958,28)select()mul(903,261)'])where()-where(),why()^+mul(797,429)(?mul(570/{~<:how(193,280)*mul(759,564)how()[^/>:)+mul(55,759)!} mul(329,715)-how() @mul(877,69)~mul(798,424)>:~,mul#'<$[?do()?$*mul(823,208)?#what();what()(%mul(93,613)*from()mul(969,827)when(478,829)?[+what()mul(405,736);how()>/{where(){?mul(821,18)select()when()>/,;where()mul(657,233)who()^when()$,:?<&))mul(582,114)+>#~mul(363^who()--where()?{&@?[mul(698,381)'[%]]do()?mul(238,833)what()<^)]]from()from()mul(145,475)who()who();from()select()+&~!'!why()')!> mul(194,70}when()}){mul(517,10)'mul(897,836)%mul(572,256)[[from() )mul(688,459)>,>mul(13,272)+{#what()when()why()mul(380,848)from()$mul(921,435)select()(where()~mul(963,945))<(&who()(mul(484,80)why(804,328)what(812,38)~[[who(811,912)(mul(934,750)[%!how():&where(159,568);^mul[from()mul(63,914))/*mul(248,994)from()[why()^< why())^where()mul(704,912)?why()@!&+&how()+mul(469,877)}*mul(408,450)!why()>+who()&% when(879,735)mul(248%when()~ mul(725,626)mul(109,867)^select(88,196))why()@who()~@(do(),#+!-%mul(948,363)what()@~?when()^/^how()mul(443,194)*why()[//where()don't()&/ mul(948,265)%)mul(4,412)}{where()%from()!from()(mul(722,734){!{:]how()mul(77,761&} mul(297,848)+what(382,752)from()mul(537,328)mul(607,330),#select()?-)why() mul(82,487)](select()mul(890,820){!^;select()(#-}mul(346,437$}&what())>~&:*mul(314,654)why(679,488)#where();[mul(177,941)'#where()mul(233,253) how())why()~mul(60,594)*']-)mul(273,795) +&*%do()#,-/>who()mul(667,162)}}mul(208,65)-^mul(144,350)~:what()mul(809,995)what()^>*^what()?/+mul(308,313)[~~'$don't()from()what()?what(){:,mul(739,608)#what()^*[mul(270,501)-who()from(383,34){-!how()where()mul(135,362)#^[what()from(269,68)-$}/mul(607,132)/+when();-;,mul(738,772)*what()mul%*#!why(433,88);(^]what()mul(795,132),-/<-!*:#why()mul(133,881)mul(388,587)what()}from()^why()~ 'where()@mul(735,387)mul(533,521)$,)?mul(63,763)(+how()what()from()(where()from()from()do(){~@: &who()why()mul(878,368)^&)$)#< mul(514,971)who()} /:*'';mul(731,555)where()mul(827,838)from()when(285,231)?&how()-(how()]mul(992,713) +?from()%#mulwhen()mul(998,507)what()why()mul(975,828)mul(472,279)#(mul(13,39)-do(),%mul(301,284)~why()>/mul(406,207)&]mul(685,749)who()[&what()#mul(958,213)mul(575,764)from()&mul(15,551)mul(220,215)-%mul(443,289)]from()when()^!?@select()select()%mul(812,779) %~$mul(383,994)?(-why()/<^where()&why()mul(33,693)where()mul(471,326)<#>@,))what()don't()~@from()mul(815,918)/select()%]select()]'~mul(681,852)mul(994,337)&mul(196,606)where(403,862)*]how()mul(698,788)when(642,540)-[-mul(7,705)where()when()}+mul(972,889)<<'}mul(510,565)select()+&,where()%-%mul(561,688))? mul(411,213)'where()&(^%!'(]don't()}{when(908,767)(who()(mul(434,326)*]$-;from()mul(115,32)how()#;who()+/where(){mul(280,916)'[&(#-who()'select()&mul(220,39))$)select()]('what()why()#mul(589,283)>#&mul(391,205), ]how()&}mul(569,87)who()mul(829,774)~<{from()don't()@mul(116,737)'<>why(235,898)(:select()~]>who()%{#$'do()mul(30,865)where()<[where()^'mul(227,579)^when()what()mul(675,333)^*why()/~>mul(17,908)$who()select() %*{/@]mul(496,909);]when()mul(178,692)(who()why()mul(660,702)$>;+when()do()#?*mul(683,836))when()when()when()')mul(52,757){<*^^who()who(787,663)why()?+mul(249,441)mul(129,93)'+mul(569,485) ^}what()mul(622,61)mul(508,94)/$mul(476,431)^{where() }>mul(46,9)when()from(),mul(771,512)>from()why():}{mul(559,664)[@who(252,904)^what()#mul(178,652)%mul(397,89))+where()mul(989,460)(-mul(369,648)don't(),when()what(332,922)/select()mul(681,823)@how()?#what()!&&:mul(705,445)^*:*select()&%'select(630,493)?mul(335,592)from()*]who()*mul(665,296)'@)^^:(!]why()mul(813,344)*mul(988,514)'how()@,,+:mul(412,278)do()}#;mul(679,583)*mul(241,420)#;-!$;%do()!mul(218,333)(^,>who()]:where()how()/mul(927,82)^#>$select()[^^mul(803,223)-^where()~select(956,23)~ diff --git a/2024/d03.lisp b/2024/d03.lisp new file mode 100644 index 0000000..c194f97 --- /dev/null +++ b/2024/d03.lisp @@ -0,0 +1,37 @@ +(in-package :aoc/2024) + +(defparameter *input/d3* + (asdf:system-relative-pathname :advent "2024/d03.input")) + +(print *input/d3*) + +(defun readfile (filename) + (let ((lines '())) + (with-open-file (stream filename :direction :input) + (loop for line = (read-line stream nil nil) + while line + do (push line lines))) + (nreverse lines))) + +(defun replace-with-prefix-expr (match) + (ppcre:regex-replace "mul\\(([0-9]+),([0-9]+)\\)" match "(* \\1 \\2)")) + +(print + (apply '+ + (mapcar 'eval + (mapcar #'read-from-string + (mapcar #'replace-with-prefix-expr + (ppcre:all-matches-as-strings "mul\\(([0-9]+),([0-9]+)\\)" + (format nil "~{~a~}" (readfile *input/d3*)))))))) +; 1795571322 + +(print + (apply '+ + (mapcar 'eval + (mapcar #'read-from-string + (mapcar #'replace-with-prefix-expr + (ppcre:all-matches-as-strings "mul\\(([0-9]+),([0-9]+)\\)" + (ppcre:regex-replace-all "don't\\(\\).*?(do\\(\\)|$)" + (format nil "~{~a~}" (readfile *input/d3*)) + ""))))))) +; 103811193 diff --git a/advent.asd b/advent.asd index d67098d..0c5a6e0 100644 --- a/advent.asd +++ b/advent.asd @@ -3,7 +3,7 @@ :description "Advent of Code" :author "Emile Hansmaennel " :license "MIT" - :depends-on (#:alexandria) + :depends-on (#:alexandria #:ppcre) :components ((:file "package") (:file "utils") (:module "2024" -- cgit 1.4.1