From 735b9fdf4535be1d721c59077e66def8b115d2ae Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Tue, 3 Dec 2024 00:12:57 -0500 Subject: 2024.3 --- 2024/tcl/03.tcl | 36 ++++++++++++++++++++++++++++++++++++ 2024/tcl/input.03.txt | 6 ++++++ 2024/tcl/templ.tcl | 18 ++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100755 2024/tcl/03.tcl create mode 100644 2024/tcl/input.03.txt create mode 100755 2024/tcl/templ.tcl diff --git a/2024/tcl/03.tcl b/2024/tcl/03.tcl new file mode 100755 index 0000000..d1ff7c9 --- /dev/null +++ b/2024/tcl/03.tcl @@ -0,0 +1,36 @@ +#!/bin/env tclsh + +source lib.tcl +setup 3 + +puts {Part 1: Sum of mul(x,y) calls...} + +set mulsum 0 +set mulsum_cf 0 +set cf 1 +foreach {inst a b} [regexp -all -inline {do\(\)|don't\(\)|mul\((\d+),(\d+)\)} [read $input]] { + switch -- [string range $inst 0 2] { + mul { + set inc [expr {$a * $b}] + incr mulsum $inc + if $cf { + incr mulsum_cf $inc + } + } + do( { + set cf 1 + } + don { + set cf 0 + } + } +} + +close $input + +puts "Sum: $mulsum" + +puts "" +puts {Part 2: ...with control flow.} + +puts "Sum: $mulsum_cf" diff --git a/2024/tcl/input.03.txt b/2024/tcl/input.03.txt new file mode 100644 index 0000000..1da07fc --- /dev/null +++ b/2024/tcl/input.03.txt @@ -0,0 +1,6 @@ +from()]mul(317,745)-+?;what()&{mul(67,323)select()~(+/}what()+when()[who()@))why()mul(41,576)?!*why()}{who()@%;mul(335,137)how(){mul(729,375)?mul(714,984)mul(86,727)[mul(148,442))@,) mul(659,930)why())/@'-select()$don't(){from()/mul(606,455)from()#select()(,when(560,861)from()mul(661,278)@@where(714,248)-) ;how()don't()+#}mul(511,224)[ <,*!,how()[mul(741,103)@ ,-;don't()?mul(405,226)~;mul(690,221)>when();~*][($mul(743,671)$,,!mul(904,48){?{,[<,when()how()mul(214,669){<*<%mul(313,778)<*>%]:~)&mul(328,558)from()why()^:][^)don't()/%/ mul(16,534)where(62,792)^}',do()$ ~&mul(591,671)why()?how()what()mul(158,309):!mul(305,375)+{from()#from()~mul(395,733){$]#,)how()/~who()mul(764,920)+mul(787,366)(&what()>who()~mul(260,940)$why()/,mul(904,953) >$mul(803,943)#@+how()what()mul(97,179)$ )[!:^::&mul(757,133) mul(949,638)/]: /when()mul(533,324)mul(177,653)[&mul(361,108)(,[mul(912,339)[#what()from()why()#don't()mul(130,4)<&what()^when()^-@]!mul(501,376)!(#~when()*'~mul(166,904)how()~mul(229,929)mul(481,574)select(),- {?@how() ?mul(989,487)where()who(),don't()/:@-[mul(398,359)when()what(440,393)}mul(110,756)who()how()!select()%[what()mul(300,194)}don't()-%who()>$^mul(598,480):'how()()#[/~;mul(644,80)%<@(select();mul(254,510)!~]{-!mul(432,50)&@;&from(442,218)mul(128,797)&where()}#mul(210,512)select())mul(22,316)~where()/#mul(228,533)@@?who(),])mul(444,403)why())why(161,374)@:mul(420,83))when()* :>]]%[mul(738,977)/)when()<;do()how()%why()]},}mul(739,424)mul(21,79)(how(964,229)$-mul(886,756)^mul(959]+mul(510,621){/$ %from(535,780)mul(942,849)#;who()select()(mul(884,418)?#}from()}-do()-mul(765,279)!how()~ select()how()mul(230,66)+#>+]}/[why()mul(830,643)]why(),@-+mul(549,381)+-}>)}[,>[mul(384,650)select())+:mul(156,98)?select(265,152)$mul(848,696)(*(}>-what()mul(916,489)<:*~when()why()[>mul(795,164)when():?mul(681,258)#mul(548,602)why()how()({from(791,741)<(]why()@<^,where()(mul(325,852)$from()$~when())mul(354,858)}/[@mul(452,532)mulwhen()&[mul(496,103)mul(670,785)how(776,494)-{&!select()~who()?%>&mul(59,896),mul(323,734)~:-:<,mul(930,720)>{~mul(55,98)how()from()@where()<>where():-;]?>do()>(when()select()&(:'select()-mul(519,249)when()where():*,#what()when()mul(433,688)$'{/&-;^;mul(487,902)?' 'mul(851,22)mul(571,264)[)mul(625,196why(),/%]mul(177,329)when()(what()]select()>%&mul(392,746)?!when(855,314)&-+}[^mul(244,411)~ what()*from()mul(27,419)from() &}mul(783,31)!mul(609,220)>#^!mul(835'*mul(26,372)-mul(968,770)who()why()]%from()}what() >mul(258,240)$mul(767&]mul(255,639)-&why()mul(682,513)][+!@@,{mul(267,914)#'who()+what()do()~)~%];mul(328,10)[$how()}+!<>-mul(286,443,; ;!(how()! do()what()+<(:mul(734,165)how(){:{]#]from(543,898)-mul(311:when()%mul(955,663)&*~>~;{mul(87,123)***mul(273,650)[mul(288,699)how()'& {'%from(){why()mul(677,973)({{>$!mul(962,447)~why()where();mul(193,727)^} '#;))select()mul(332,420)where()who()}%what()?mul(946,222)#)~/where()how()who() mul(784,547) }select()mul(868,939)how()-) when()/mul(766,690)$/(how():mul(289,854){what(){:-from()%{'$mul(616,797);!how()'mul(607,52),mul(634,542)/ ){how()])select(269,907)mul(746,163)])+&& >:where()mul(933,745)<])*select()#;do():+from()/';@:mul(549,673):where()!where(),*[who() *mul(182,300)++&how(14,499)from()[]&mul(674,397)why()from()mul(274,670)/-^/how()%-why()mul(631,257);~}$don't()$where()}#%select()(mul(222,921)select(875,756)+-why()[)+}why())mul(527,536)^*#@*mul(526,226)!mul(509,930)$who()when()/+)when(342,782)~mul(806,222)(],why()where()^mul(528,285)^#?#what()mul(875,506)from()^mul(537,399)/&?{mul(457,240)%^mul(16,257),}%%+?#>mul(780,949)}mul(570,933)when(749,935){mul(708,407)/mul(475,875)mul(124,766)'?where(308,370); '&mul(397,320){>'where()how()mul(558,514)}>#},mul(164who()why():;when()select()(mul(553,336)how()what()]who()why()select()mul(295,32)&from():^?mul(233,116)~]mul(429,202)when()what()select()mul(741,965)*{&#;#$,/how()mul(367,887) +mul(681,506) -^mul(484,363)@:when();where()from()select();mul(186,965)who()from()~who(442,513)who()-&*];mul(116,362)[~where()(where()!/^:mul(733,863):}'when()]^+;mul(75,849)mul(115,784#:@why()%from()'$@mul(592,93)select(773,179){[['>from()}mul(131,959)@who()]mul(394,818)$-(+'^^mul(996,181)select()<> #~*+*mul(53,343) where()when()!mul(954,569)**[don't()+what():%)$-why()#mul(452,447)*{mul(264,795)}how()#when()#from()why()when(745,720)mul(248,687): ^^,<+[when(889,956):mul(937,8)how(235,664)?]?{mul(137,328)?mul(503,926%mul(13,847))mul?why()?select()()mul(460,750)]%;mul(651,280)why()>>,how()when()$? mul(133,236)!<(what()^>'?^mul(748,823)who()where()mul(43,496)select()when()++why()';?mul(875,70)-when(402,701)&)why()'mul(982,841)>^do()>who()where()/]:mul(647,595);select(), ::mul how()where()select()from()&(/+mul(468,107)what()how()#what()>;]mul(957,478)where():?mul>when()%{where()?%mul(592,367)mul,why()mul(72,238)who()?:+<(mul(222,516)%]%#~mul(193,251)when()when())/why()@)@/mul(340,791)&/?who()why(){&,?mul(55,804)']{&%$/mul(316,546)when()who()mul(971,888)[mul(103,609)]*>)<[;~/what()mul(490,677)why(898,282)mul(170,318)*how():>&^)-where()from()#,when()mul(372,78)>?*select()from()!&]why()mul(449,613)'select()!'do()'<*mul(761,836)what(){!(who()why(634,576)mul(802,819)]/+who(){} select()$mul(203,130)<'mul(400,590)'mul(951,874)where()mul(186,662)who()[who():;@;mul(192,643)$'why()[:?don't()&(-select()!;*?mul(517where()#mul(484,952)/&[};<,mul(191,767who()'{:why()how()from()}mul(391,241)]mul(564,815)!@,~mul(327,855)mul(515,532)*([>{:don't()when()% mul(399,207)@->mul(176,348)why()what()mul(517,732)]:,mul(832,279)what()?*-<+>mul(158,912):@!^-!mul(630,685)(/*what()}from()@#!mul(737,751)'/$how()from()mul(952,556)what()~~},:,don't()[(how())^/why()why()when()mul(464,363)@select()? when()where()mul(380,587)mul(935@<;mul(311,283)-,+{>;&;~mul(217,900)from()when()){%@{+<~mul(861,412){mul(649,279)when()!->{mul(53,704)}>mul(124,780)(}^@]from(){where()#mul(323,768)]what():/'':select()mul(42,323)!select(),$mul(833,631)where(920,91));?select()mul(274,3)-]^^*~{/mul(195,31)~}#select()+[ why()mul(437,871)how()#where()$? what(265,149)[mul(53,447)@<-mul(182,3)}>#!/usr/bin/perlmul(836,288) +&/where(234,114)mul(230,255)(;{~*where()/+from())do()how(174,635)where()(>~(mul(547,383)how()(]( mul(394#when(217,999)[mul(520,655)@/} mul(883,280)(from()+#mul(993,6)@%,@}'*-mul(469,993)*})mul(329,69);<}}mul(94,7):{'mul(299,57)->where()who()><<@}mul(192,320);-< (mul(348,932)(+mul(565,629)/how(792,174)mul(994,456),&from()when()from()from()$select(){+mul(518,910)where()$mul(42,710)mul(447,192)what(); &mul(535,494)@&mul(39,121~where()>]@who()$mul(238,165)}{&how():)mul(293,498)@^ why(231,662)mul(91,213))@who()*when()mul(547,308):~~^how(179,495)(where()mul(334,412),!}}?,*what()mul(704,941)}:]^mul(215,465){~&!*@{where(719,643):[mul(653,594)who(){;-{}mul(307,823)^(?{><}+@mul^<]?,who()?mul(989,866)}when(881,287){)-who()::who()mul(642,431)@-mul(817,550)from()>'(when();!%&mul(315,78)%select()mulwhen()~(why()]mul(636,929)when()%->mul(53,720'](;!$mul(931,769)(---+[*>don't()+&when(88,906)*$where(),@mul(223,251)#]'<+,%mul(146,115)how()]mul(136,688),mul(222,174)#]mul(75,636)^who()mul(76,992]mul(280,202)]select()!>,when()when()#mul(68,678),:$$select()?why(302,488)>#what()mul(923,779)who())]>]mul(525,656)'%#mul(110,925)from()]$?>why()what()mul(485,123)?where()'!(@)/?%mul(62,61)#who()don't()'from()who()mul(863,433)])what()<{'[>{where()mul(955,358)+select()what()*from()from()how()mul(674,255)how():who()/[when()+mul(672,815)/{}mul(814,989)mul(522,617)][why();mul(938,866)?'mul(721,230),!how() %$^{^'mul(89,252)@how()!--what()@what()mul(66,916,;select()@from()>[mul(908,102)$how()[how()}/:mul(352,260):?where()how(418,410)<@*~why(){mul(288,873)^'}${+{when()select()mul(577,817);!<+)%#mul(398,599)?mul(410,933)![;~[(mul(372,736)-{^who(284,999);>$don't()~where()mul(946,342)',* >when()'from()~don't()>mul(48,678),-how()where()mul(521,176)*]mul(653,286)[what()';mul(527,517) :'%do()'how()when()why(638,246)~*&'mul(817,515)when():)^&;mul(902,760)when()who()+from() !&)/;mul(490,93)when()mul(999,859)?'mul(23,41) !where():>--']mul(529^who(824,944))/where(){mul(730,713)}~&**where()mul(783,314)when()![%@mul(192,618)mul(639,668)+from())&who()%*~ 'don't()*$from()-!when()]from()mul(176,706)< -#mul(985,33)$/,']mul(166,740)mul$)>!%]^-[mul(741,253),select()*mul(994,973){+$%%what(970,247)%#mul(569,793),where()$][-?&#:,mul(795,367)from()/~)mul(184,867)}where()when()^(mul(11,847)&mul(252,382)&how()what()*where()mul(42,377))select(451,494):^}*mul(519,853(]mul(645,935)[*,]-&]select()mul(205,327) ]),*)mul(411,698);^[[who(212,491)& -,mul(83,917):how()select()%((+&@mul(86,812)!%how()mul(555,734)(!#select()*'where()from()how()mul(815,589);~-^where()-select()mul(981,251)why()@what()]@*do(){what(874,233)mul(74<)'%[ )mul(461,683);]why()who()(when()*%-{mul(927,403)@/@~where(584,953)--mul(766,900)select()@['+:{)when()mul(919,825)mul(762,132),>%~from(364,888){who() )mul(783,336)where()~$?; ?!don't()mul(275,278)}what()mul(167,505)*^',;^from()mul(692,244)#'^>mul(835,721)!~what()',@mul(447,777){[from(133,514)what()mul(642,217)'(from()@/'how()<^{mul(831,368)@! what()why(434,98)@ don't() who()$]mul(40,963)mul(130,643))what()/select()mul(211,425)${mul(443,261)select()-<^ select()]where()!don't()}#!,where()how()mul(862,985) ,^!how()@don't()!:(what()mul(981,127)~'from()-mul(871,89) :]when()mul(467,236)mul(606,18)+!$:(mul(753<]who(){[how()from()#mul(986,891)#:when()mul(519,399)who()))#*mul(545,827)mul(638,830){select()mul(466,624) :)when() #mul(254,927)&what()where()why()}}#mul(827,465)};]what()>why()mul(242,606):';-/mul(404,75)mul(221,314)who()@who()*[select()>%mul(414,100)!what();why()~what():$ why()mul(315,402)]don't()!where()},from()#how():mul(286,647)+what()+why()%*!^when()-mul(902,822)when()>why()mul(7,343)select()where();},>&why()?&mul(564,706)()!*how(),why()>{mul(369,110)>,#mul(663,681*~@,@how()$mul(340,519)&)when()from()mul(590,642)*(/>'%$'where())mul(992,803)how()when()mul(863,400)@~from()>mul(708,294)>?@what())#$&mul(235,189)/~%-+)+&!~don't()>where()when())?mul(289,183)+$select()how()mul(597,749)why()mul(891,949)?mul(114,531) %+/,$from(493,501)-&^mul(591,30)}<@<[?;mul(91,804) +^%mul(449,407))mul(731,490)#+)(why()?:when()mul(666,844)mul* select()who()mul(930,953)+~@^-mul(739,539)@who()]?& when() mul(989,203)(:)?];where()$mul(862,477)mul(861,661)%~%~/!mul(224,714)[ mul(737,853,^from() mul(212,888)>mul(185,546);#'}%why(292,59)mul(428,503)where()#>from()>;mul(47,787)/,select()<;>?]where()mul(781,376){select()-}>mul(193,943)how(),how()-)from()$+-mul^^%#$from()>how()*why()%mul(760,582)mul(702,579)+:mul(640,791)what(47,178) &!^who()how()mul(649,839)/!^/why()mul(590,380)select()why()< >where()< mul(59,685)<+'when()#/select()!:mul(926,631)who()>how()}?}how()mul(766,724)*+]don't()/ >,~{who()[)mul(562,645)from()select()~where()why():mul(921,271)^where()where())mul(5,76)+;]select()+^>select()(^mul(327,476)-?<[who(665,286)where()mul(17,787)$/where()who()mul(797,991)*@when()]mul(288,945)!;%select()select(221,67)?where()(select()mul(103,613)>*$:#(<#mul(897,461),++'{:^mul(399,45)/[[$)what()?'mul(884,145)-<@ mul(907,419)$how()!mul(746,659)*%>why()}!do()-*why()where()mul(836,181@&>/@/)>#!;mul(511,857)what()^when(839,625)}why(642,188)mul(871,977)where()%where()select()#((when();,mul(996,95)<-from()}+mul(489,882)how()-]]&select()%~@select()mul(526,213)+where(){mul(196,64)>:#who()*(^why()(where()mul(305,841)^~&why(),@ )mul(33,152)%:+mul(276,813)?!how()-where()(>mul(166,466)mul(120,970)){+, #how()don't()<(select()/$from()!?mul(528,858),%%when()+#mul(582,880)[*how()what()-mul(880,694)why()-)how()mul(765,222)''how()'mul(568,629)'%mul(995,665)? ,};'[+mul(613,221)*)mul(90,933)how(){mul(873,519)#+how():*}#?^mul(568,189))mul(64,852)}from(101,629)!where()mul(883,789)mul(787,121)(who()'from()mul(904,116)(];[,?^mul(58,874)mul(825,942)-mul(966,765)mul(288,95)select()?where()%mul(362,992)]select()how()/select(){mul(731,806)&how(305,337)who()]when()}{why()where()mul(761,298)who()+{@;^?mul(261,9)who()mul(911,882)<;)who()/ mul(627,335)<+~-mul(975,402)what()]mul(952,216) why(),;:@when()how()mul(592,925)(!mul(12,402) mul(487,955)select():!~+>:who()@mul(777,428)^+what(385,392)'(:select()<'mul(492,807)@,mul(613,475): mul(787,127)&!,mul(289,109)?)*mul(863,691)!-/@$!mul(357,967)#:?' {?what()mul(824,697){&from()+how()mul(600,525)@mul(783,413):&*$>select()&mul(192,535)?select()who()when()@ diff --git a/2024/tcl/templ.tcl b/2024/tcl/templ.tcl new file mode 100755 index 0000000..e040b2f --- /dev/null +++ b/2024/tcl/templ.tcl @@ -0,0 +1,18 @@ +#!/bin/env tclsh + +source lib.tcl +setup ? + +puts {Part 1: } + +while {[gets $input line] != -1} { +} + +close $input + +puts "1: $" + +puts "" +puts {Part 2: } + +puts "2: $" -- cgit v1.2.3-70-g09d2