Compare commits

...

71 commits

Author SHA1 Message Date
Bruno BELANYI 080e4e74ec 2024: d19: ex2: add solution 2024-12-19 00:11:14 -05:00
Bruno BELANYI a05e17d50c 2024: d19: ex2: add input 2024-12-19 00:11:08 -05:00
Bruno BELANYI d38c370f4f 2024: d19: ex1: add solution 2024-12-19 00:11:03 -05:00
Bruno BELANYI a49aa0cbca 2024: d19: ex1: add input 2024-12-19 00:10:57 -05:00
Bruno BELANYI d9e3dba3ce 2024: d18: ex2: add solution 2024-12-18 00:25:04 -05:00
Bruno BELANYI 9306c7c462 2024: d18: ex2: add input 2024-12-18 00:24:53 -05:00
Bruno BELANYI bb3386c083 2024: d18: ex1: add solution 2024-12-18 00:24:47 -05:00
Bruno BELANYI 531991c6c5 2024: d18: ex1: add input 2024-12-18 00:24:40 -05:00
Bruno BELANYI bc200592c4 2024: d17: ex2: add solution 2024-12-17 13:11:08 -05:00
Bruno BELANYI de285154cf 2024: d17: ex2: add input 2024-12-17 13:10:57 -05:00
Bruno BELANYI bd44f8abc8 2024: d17: ex1: add solution 2024-12-17 13:10:51 -05:00
Bruno BELANYI c5cbd8d499 2024: d17: ex1: add input 2024-12-17 13:10:44 -05:00
Bruno BELANYI 5176ba5723 2024: d16: ex2: add solution 2024-12-16 14:54:20 -05:00
Bruno BELANYI 8e747b503f 2024: d16: ex2: add input 2024-12-16 14:54:15 -05:00
Bruno BELANYI 5e240ff71d 2024: d16: ex1: add solution 2024-12-16 14:54:09 -05:00
Bruno BELANYI cd139b14b1 2024: d16: ex1: add input 2024-12-16 14:54:04 -05:00
Bruno BELANYI fa1ac05b77 2024: d15: ex2: add solution 2024-12-15 11:01:06 -05:00
Bruno BELANYI 995f60fdb0 2024: d15: ex2: add input 2024-12-15 11:01:01 -05:00
Bruno BELANYI fe6ae49833 2024: d15: ex1: add solution 2024-12-15 11:00:54 -05:00
Bruno BELANYI ed9d601284 2024: d15: ex1: add input 2024-12-15 11:00:49 -05:00
Bruno BELANYI dcd885f641 2024: d14: ex2: add solution 2024-12-14 11:22:58 -05:00
Bruno BELANYI 8d73ecea78 2024: d14: ex2: add input 2024-12-14 11:22:54 -05:00
Bruno BELANYI 7e54035bef 2024: d14: ex1: add solution 2024-12-14 11:22:46 -05:00
Bruno BELANYI c8a9d25770 2024: d14: ex1: add input 2024-12-14 11:22:39 -05:00
Bruno BELANYI 681c85169b 2024: d13: ex2: add solution 2024-12-13 01:51:43 -05:00
Bruno BELANYI b6cac39da0 2024: d13: ex2: add input 2024-12-13 01:51:38 -05:00
Bruno BELANYI 6aa81cdb13 2024: d13: ex1: add solution 2024-12-13 01:51:32 -05:00
Bruno BELANYI bd73041e6d 2024: d13: ex1: add input 2024-12-13 01:51:28 -05:00
Bruno BELANYI a5efe0f7ec 2024: d12: ex2: add solution 2024-12-12 10:01:22 -05:00
Bruno BELANYI f56392b78f 2024: d12: ex2: add input 2024-12-12 10:01:03 -05:00
Bruno BELANYI 94ee0dc642 2024: d12: ex1: add solution 2024-12-12 10:00:57 -05:00
Bruno BELANYI 6a4b8a1a67 2024: d12: ex1: add input 2024-12-12 10:00:51 -05:00
Bruno BELANYI d4bca4bbad 2024: d11: ex2: add solution 2024-12-11 09:16:17 -05:00
Bruno BELANYI a38bf45fa6 2024: d11: ex2: add input 2024-12-11 09:16:12 -05:00
Bruno BELANYI d1653a9aec 2024: d11: ex1: add solution 2024-12-11 09:16:06 -05:00
Bruno BELANYI 9f8f458c01 2024: d11: ex1: add input 2024-12-11 09:16:00 -05:00
Bruno BELANYI a35ae47246 2024: d10: ex2: add solution 2024-12-10 00:20:29 -05:00
Bruno BELANYI a286419745 2024: d10: ex2: add input 2024-12-10 00:20:22 -05:00
Bruno BELANYI 2572015d79 2024: d10: ex1: add solution 2024-12-10 00:20:16 -05:00
Bruno BELANYI ffe7be04fe 2024: d10: ex1: add input 2024-12-10 00:20:10 -05:00
Bruno BELANYI a33530ec13 2024: d09: ex2: add solution 2024-12-09 08:48:31 -05:00
Bruno BELANYI 2315fe3fa5 2024: d09: ex2: add input 2024-12-09 08:48:23 -05:00
Bruno BELANYI c6a9bb406b 2024: d09: ex1: add solution 2024-12-09 08:48:17 -05:00
Bruno BELANYI d593c86613 2024: d09: ex1: add input 2024-12-09 08:48:10 -05:00
Bruno BELANYI f633512263 2024: d08: ex2: add solution 2024-12-08 05:16:55 +00:00
Bruno BELANYI 835645531b 2024: d08: ex2: add input 2024-12-08 05:16:50 +00:00
Bruno BELANYI 5c352109de 2024: d08: ex1: add solution 2024-12-08 05:16:44 +00:00
Bruno BELANYI 0da5366293 2024: d08: ex1: add input 2024-12-08 05:16:38 +00:00
Bruno BELANYI 55568ccdb3 2024: d07: ex2: add solution 2024-12-07 10:43:12 +00:00
Bruno BELANYI 872b3bb98f 2024: d07: ex2: add input 2024-12-07 10:43:07 +00:00
Bruno BELANYI b918737ed1 2024: d07: ex1: add solution 2024-12-07 10:43:00 +00:00
Bruno BELANYI bf4018ac8b 2024: d07: ex1: add input 2024-12-07 10:42:51 +00:00
Bruno BELANYI 3eb1ed97df 2024: d06: ex2: add solution 2024-12-06 11:06:14 +00:00
Bruno BELANYI fb0a35831e 2024: d06: ex2: add input 2024-12-06 11:05:59 +00:00
Bruno BELANYI f6950f1c0a 2024: d06: ex1: add solution 2024-12-06 11:05:51 +00:00
Bruno BELANYI 6ce2468a20 2024: d06: ex1: add input 2024-12-06 11:05:42 +00:00
Bruno BELANYI 31c7a2d1e7 2024: d05: ex2: add solution 2024-12-05 10:47:22 +00:00
Bruno BELANYI 24ecbc6b74 2024: d05: ex2: add input 2024-12-05 10:47:15 +00:00
Bruno BELANYI fde618ecf6 2024: d05: ex1: add solution 2024-12-05 10:47:08 +00:00
Bruno BELANYI 42f91d84c9 2024: d05: ex1: add input 2024-12-05 10:46:59 +00:00
Bruno BELANYI 1712f53ff7 2024: d04: ex2: add solution 2024-12-04 10:36:07 +00:00
Bruno BELANYI 5fa5d3db54 2024: d04: ex2: add input 2024-12-04 10:35:51 +00:00
Bruno BELANYI d055076659 2024: d04: ex1: add solution 2024-12-04 10:35:39 +00:00
Bruno BELANYI 93314299fb 2024: d04: ex1: add input 2024-12-04 10:35:30 +00:00
Bruno BELANYI 7bebb8a981 2024: d03: ex2: add solution 2024-12-03 10:13:19 +00:00
Bruno BELANYI 67ab17f1f8 2024: d03: ex2: add input 2024-12-03 10:13:10 +00:00
Bruno BELANYI 170173e5d3 2024: d03: ex1: add solution 2024-12-03 10:12:55 +00:00
Bruno BELANYI de2503d8fd 2024: d03: ex1: add input 2024-12-03 10:12:45 +00:00
Bruno BELANYI 28a945c421 2024: d02: ex2: add solution 2024-12-02 10:24:02 +00:00
Bruno BELANYI 78ff7514f8 2024: d02: ex2: add input 2024-12-02 10:23:35 +00:00
Bruno BELANYI 3db8436347 2024: d02: ex1: add solution 2024-12-02 10:23:23 +00:00
71 changed files with 20706 additions and 0 deletions

28
2024/d02/ex1/ex1.py Executable file
View file

@ -0,0 +1,28 @@
#!/usr/bin/env python
import itertools
import sys
Report = list[int]
def solve(input: list[str]) -> int:
def parse(input: list[str]) -> list[Report]:
return [[int(n) for n in line.split()] for line in input]
def is_safe(report: Report) -> bool:
def is_increasing_safe(report: Report) -> bool:
return all(1 <= (b - a) <= 3 for a, b in itertools.pairwise(report))
return is_increasing_safe(report) or is_increasing_safe(report[::-1])
return sum(is_safe(report) for report in parse(input))
def main() -> None:
input = sys.stdin.read().splitlines()
print(solve(input))
if __name__ == "__main__":
main()

36
2024/d02/ex2/ex2.py Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python
import itertools
import sys
Report = list[int]
def solve(input: list[str]) -> int:
def parse(input: list[str]) -> list[Report]:
return [[int(n) for n in line.split()] for line in input]
def is_safe(report: Report) -> bool:
def is_increasing_safe(report: Report) -> bool:
return all(1 <= (b - a) <= 3 for a, b in itertools.pairwise(report))
return is_increasing_safe(report) or is_increasing_safe(report[::-1])
# Dampening by brute force
def is_dampened_safe(report: Report) -> bool:
for i in range(len(report)):
dampened_report = report[:i] + report[i + 1 :]
if is_safe(dampened_report):
return True
return False
return sum(is_dampened_safe(report) for report in parse(input))
def main() -> None:
input = sys.stdin.read().splitlines()
print(solve(input))
if __name__ == "__main__":
main()

1000
2024/d02/ex2/input Normal file

File diff suppressed because it is too large Load diff

36
2024/d03/ex1/ex1.py Executable file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python
import dataclasses
import re
import sys
@dataclasses.dataclass
class MulInstruction:
lhs: int
rhs: int
def calc(self) -> int:
return self.lhs * self.rhs
def solve(input: str) -> int:
def parse(input: str) -> list[MulInstruction]:
res: list[MulInstruction] = []
MUL_REGEX = re.compile(r"mul\((\d+),(\d+)\)")
for match in MUL_REGEX.finditer(input):
res.append(MulInstruction(int(match.group(1)), int(match.group(2))))
return res
return sum(inst.calc() for inst in parse(input))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

6
2024/d03/ex1/input Normal file
View file

@ -0,0 +1,6 @@
}}+{where()mul(873,602) mul(954,447)^where()~mul(548,799)-<what()mul(588,631)^who()'@( [mul(143,388)how(445,327))$ select()who()mul(746,719)mul(963,262)}'*+why()<?&/select()don't()[%]% ^^mul(933,492)don't() ^-who()(%how()]mul(583,700))!,where()mul(999,507)](mul(821,504)^%/;:-mul(471,220)who()&'who(161,37)<'mul(843,213),<mul(298,802)-()@how()where()@+[:mul(910,85)'when()($select()%-*mul(532,213)*from()select()$,what()mul(956,380)mul(326,87)mul(243,775)!/:from()&^^mul(118,409)!)what()select()mul(610,89)mul(432,774)from()# from()<mul(400,864):+&mul(957,923)'don't()+select()why()mul(496,383),&why()(-;)+!#mul(79,135)~{mul(500,619),#what(361,47)@&;@+mul(580,98)<>#why():$from()(!mul(660,615):where()mul(596,918)how()[what()how()who()]@mul(594,699)$>$&why()mul(951,813)mul(948,41)]mul(699,225)>mul(840,275):@~^@%^select()mul(695,594)what()->-mul(409,636)@ {++mul(999,290)when(339,689),[+[+?mul(558,848)how(),what()&}]{mul(344,337)$)$]+,$,,why()do()::select()^:mul(796,16)mul(526,718) mul(66,417)#@>~do()why()from()/select()when():&mul(8,111);!where()do()}@mul(433,239)*}how() {^!do()#^mul(167,905)-&%(mul(979,711)when()]who()'?mul(523,172)[^what(844,455)'what()[/~@mul(928,776)where()]&/mul(587,380)who()/when()how()from(),}#}mul(97,952)select(837,505)~@>~%mul(486,198)^!mul(968,779)do()[mul(206,321);,where()where())how()}/mul(6,867)-&<!*select()mul(615,984)~?who()#<{how()?@mul(617,643){ @,'why()+>what()(mul(683,583)^(mul(244,555)^where()(how()what()?-[,who()mul(827,305);&,!$*?mul(793,452)^ )+(%-where()<mul(318,238)<$-what()mul(802,394)?how()<mul(488,879)do()$}<:&mul(429,358)~how()mul(36,174)mul(87,398)+%what()]mul(822,311)mul(379,261)~when()mul(618,193)@)!))-what()how(645,829)[mul(964,102);who()don't(),[what(),,?select()why()@mul(121,293)select()@who()!mul(770,96)+;%from(467,168)mul(616,890)@%:)[mul(943,145) [from()&where(283,130){*where()mul(649,49)select())mul(877,73)from()do()where()?where()>who()from()@who(){*mul(592,919)/:what():who()mul(213,139)what()$!?*how(934,24)$-who()(mul(661,7)?from(),}/who()mul(876,585)how()why():when()[@@mul(433,918)why()why(),*{who()when()who()mul(144,14/#(<mul(656,306)&what()&{*@%select(709,225)/mul(843,135)who()$[don't()<mul(576,966)^,?>don't()@(@{~why()[who()mul(394,492)where()/mul(508,797)-mul(150,832)+$@why()(why()~mul(527,236)<don't()!#{how()*!,!mul(177,945)'mul(5,181)#!#'&?what()&mul(10,492):%/'*mul(822,748){!*]who()when()<!<mul(21,920)+do()-who()from(505,694)where()from()$who()where()where()/mul(827,561)how()when()mul(770,221)%when()who()mul(872,151)mul(453,84)['&+:mul(258,293)@#,where()mul(264,689)mul(90[mul(94,665)-who()don't()what()>!:@!^&!mul(324>?!from()where())mul(731,184)#(}who()'mul(666,377)how()(;mul(346,141)^select()/@[$how()@]?mul(702,502,^where()<}[mul(872,308)+^!<@from() {:mul(537,974)%when()when()%mul(563,805)select()>how()>^';mul(643,555))where(290,606)who()?mul(656,803),?$/*?when()}@ mul(228,902)~/from(){where()what()>@~mul(849,93)~+select()?-^}<don't()mul(844,117)(when()~,}# /:+mul(24,282)@where()~from()($what()what()*<mul(886,107)[#;mul(725,121) %[>mul(115,425)${what()mul(219,305)how()])from()<mul(401,458)-from()+mul(92,705)
}?/,(~+^mul(398,379)why()-!why(){}mul(618,341)how(818,559)'%}~+}'!<mul(128,74)*- &}+[mul(830,201)$when()mul(382,164) />select()~]~mul(41,659)<'{where():#+)$mul(447,137)where(120,771)$@why()#mul(457,857)<$from()$(who()@?mul(644,914)}mul(936,442);{*(why()mul(804,26);don't()why(),+*how() @:mul(668,778)%select() who() (,where()mul(66,974)^)when():$who()mul(832,615)#mul(572,646)where()how()what()when(673,330)where()when()&/mul(820,446)$why()where()mul(86,788)^~what()'mul(76,413)&'how()mul(616,424)what()select()}from()(/;mul(651,36)!{ mul[*mul(469,702)who()?;mul(331,879)?*from(54,751)who()#+[ mul(182,296)where(607,734){mul(920,190) :mul(660,732)^who()who()*'!mul(3,615)+{why(168,603)when(), mul(254,713); where()*from()~ !!#mul(897,311)]mul(629;what(280,32)>mul(194,563)^<how()when() }#<mul(27,237)?@where()mul(389,541)}'@when()}(*how()mul(671,516)do() ~select()!*']>&mulwho()when()'!what()why()?'}}!mul(414,213)$when()]+{why()mul(606,917)how()*?^,mul(292,543)>mul(326,145)*(&!;^:!#'mul;#@~where()<mul(81,169)mul(436,774)+when()%+where()-[}+mul(425,438)when()/}what()mul(76,978)>%;,from()select()mul(39,372)~[when()what()!+#who()]~mul(905,968from(843,581)(from()from()~what()how()when()mul(768,210)*mul(68,62)mul(777,345%{/select()%mul(458,251));what())how()where()how()when()mul(810,199)<~mul(252,749)don't()mul(915,327)(: mul(608,270)<%[!}-&mul(328,665)from()>*)how()mul(836,471)mul(270,799);(why();&~~mul(598,772)from()>mul(409,297)$mul(469,982)mul(457,665):@>{don't()why()<+,mul(293,172select(816,987)}why()mul(372,420)why()%mul(105,735),<]{mul?{$;>from()what()-$;mul(348,90)from()what()~mul(634,662)^do()$@]*)~,&mul(226,996)when()%]what()!@/&mul(322,135);who() &^select()*&}mul(967,104)from()}'who(701,7)~%[mul(687,163)@:<!how(){^/who()@mul(497,664))@!-(who()<mul(20,274)where(){%<where()?>+:mul(382,128)mul(831,450)mul(485,444)%^what()what()[$what()@}do()-%?'mul(204,152);$'/mul(63,376)mul(387,70)~@'{,':<mul(517,687)@ $^ )why()!mul(865,593)where(918,337)!;mul(786$$'$%why()select()[~$why()mul(667,335)~{+where()who()?from()mul(582,456)%,from()[from()how()mul(927,806)+(]?%mul(460,721)^^;^do(),how()when()select(435,369)}&mul(66[*how();>why()(%{how()<mul(997,260):'do()%::&what()}*who()mul(506,521)'who()%/!why()*&!don't()#@&mul(538,407)'^mul(84,106)'},#^where()%mul(105,225)-what()/how()/from()mul(49,421)@$)[)?why()'#}mul(707,127)@when() &(mul(732,645)'from()'*when()why()from()[who(850,51)?mul(566,427)how()>who()]',from()'how()why()mul(42,665)%'# [}mul(684,645){{%'mul(115,930)mul(552,181)mul(762,163)mul(202,193)+*[mul(525,337)+}-:](?^#mul(466,861)/do()'(;mul(860,319);mul(48,137){when() ~:< <mul(317,942)'~&#how()^mul(66,243)/(from()mul(678,119)when()!when()>from()mul(3,497)?when()< #?^@do()>;/?:mul(522,894)+{+mul(419,20)mul(139,677)where(119,273)*what()[^?mul(563,549)how()<@'%mul(560,434)what()where(),mul(886,302)mul(632,393)*what()!}{mul(769,651)'(mul(267,514)-[how()^:mul(64,902)when()mul(356,352# ;'mul(267,302)#(mul@;~+mul(471,643)!from())!what()from()~mul(429,997)/-mul(401,220)>{]what()what()@select()},mul(294,298)how()mul(230,3)/&what()]>]!how()/mul(888,907)](#>~}+#mul(17,816)/[+when()>from()]^:mul(94,85)
#)'{mul(531,103){ {where()what()from()mul(127,712))what()<mul(595,154)~>!%from()'/how()*when(940,337)mul(259,916)+}!-}[mul(703,780++;select()?why()[{mul(221,199)+mul(303,268)$don't()'[what();^mul(542,561);who()&,mul(68,800)[<'{}why()?^from()mul(26,194)?]who():;mul(641,921)#&where()mul(539,571)select()]~%%]when())mul(833,642);mul(209,564)}<^)when()mul(648,430/(#)/?(';where()what()mul(818,526) ]!what()do() <;:mulfrom() @-<select()what(557,962)$%mul(83,808)from()% {)mul(894,523){~?@'&,how()>mul(764,627)#/mul(887,607), do()$(},#^}}from()how()mul(184,287)where()$^mul(859,310){who()how()mul(692,592){>?&mul(223,912)what()^@ {{^@/mul(736,965)$)]];-#@&mul(600,145)~/}*-}how()mul(893,646):where()}mul(205,416)what()from()mul(35,844)mul(94,245))/<#</$when()who(236,448)mul(943,490)^?*!mul(187,639)select()mul(105,840)#;-;((&,select()mul(495,135)don't()when()(&mul(129,293)}}{~from()]select()*+mul(724,202)mul(540,481)+when()$><from()?$#mul(604,366)where()why()^select()mul(82,14){]what()##/^mul(661$mul(576,422)!}*mul(968,267)mul(501,251)<[,mul(999-mul(61,600)how()~ how()#&mul(488,199)+})who()# @what()mul(695,154)!{[don't()mul(454,729)what():(<%mul(656,115)from()!]when()when():?,mul(536,421)}select()when()<mul(550,82)(:mul(482,346)}%when()>+mul(189,780)from()how()#< ^don't()why()&who()where(){ >:mul(638,986)*+< ;mul(131,393),how(419,400)*@how()mul(856,729)who()$$[$[select()~<mul(553,105)why(720,700)']mul(780,579)}what()select()who()~//}^mul(811,393))/<#,mul(530,118)@'%<~mul(640,727)'-]:-:]+mul(124,151)~@{why()@/why()mul(523,641)'%select())/mul(70,234)-$#mul(589,488)^:how()(when()mul(66,473)$/!-{from()%]#]mul(417,212)~>{(when()$mul(613,175)}mul(503,337)~)what() mul:!-*}?~who()<mul(709,759)}what()^where()when()!select(820,39)]::mul(884,175):#mul(852,584)>-mul(649,886)+how(738,973)when()[(mul(593,702)where()%%^(]who()mul(456,697)%~^'when()how()mul(789,446)mul(737,439)mul(830,910):>why()when()how()'?]why()>do()#'&why()'from()mul(972,441):mul(157,521)mul(43,224):$who()>select()how()mul(52,740)'mul(136,716)select()mul(613,433)]>$^when()why()where()how();mul(978,314))$mul(695,29)}mul(778,660){how()<+$?mul(402,606)select()+~$do()mul(262,94)how()why()))#'^$@mul}mul(201,86)*select()mul(876,626)why()mul(174,750)where()(from()(mul(433,335)]@mul(29,940) :~what()$}where()select()mul(416,920)^&%<~^mul(276,648)mul(636,17);why()}-}mul(810,73)<@} how():from(900,831)what()mul(241,497)select()when()'&{mul(603,108):[,mul(941,454) $@mul>@<}'[, $mul(510,523)where(), ~];mul(584,102)<when()mul(907,301)]#select()select();{how()select()what()?mul(980,625)select())where(){:^mul(544,917)((how()['who()mul(628,364)who(272,887)@!^@{+~{don't()when() )(from()what()when()-mul(95,412)(mul(127,442)/mul(658,920)from()from())!$<&*mul(45,446)what()where()&![-% (%mul(304};do()why(81,149)#^mul(181,603)where()^;{(! ^;mul(381,353)~@$mul(129,558)where()?from(): mul(573,183<how()*how()(#(mul(626,301))?]/)how()mul(20,851)[$when()*how()mul(42,787)[! )@;:(;mul(98,614)why()mul(692,723)!'>' do()why()<&select(812,485)!mul(538,458)who()why()^'select(){{why()mul(773,196)when()why(713,26){,!do()?why()!when(),?mul(234,541)mul(558]!(%;}'-mul(721,55)
(<%@$?mul(856,705]>!#'++why() >#!/usr/bin/perlfrom()mul(147,188)<?$when()+$where()%mul(894,439)>where()what()mul(221,687)/)from()'[{mul(9,723)[{/?who()where()mul(113,227)> ~>$)mul(663,198)&[>#mul(567,600)]when()$@select())(%<&mul(472,423)#when()>(/]select()$;how(511,981)mul(785,371}-how():$where()(?~mul(731,455)mul(810,191);who()(@>,? !$mul(534,231&don't();]why();,#;where()[,mul(190,923) }when()mul <mul(909,876)[*~when()]mul(739,708)select()(@:~)/<@,mul(794,354)<mul(874,298)what()why()$+mul(669,535)&!^mul(260,4))mul(641,230)mul(516,429)'mul(141,983)!}when()select()where()+}[)do()&>:mul(525,573<{what() *$?from()from(){mul(885,340)why()>mul(398,414)?[where()<what()from()^mul(746,645)where(586,97)+'mul(523,150)/%()~how()where(580,13)@mul(446,624),'-mul(605,440),from()$/-where()mul(17,117) >$why()from())mul(988,667)mul(828,197)'why()/%*when()/*mul(799,415)where()]<~ ?>'-don't()^[(' ]%^~%mul(122,243)why();[how(951,959)how(435,882)~*-#don't()why()[what()what()'mul(218,944)!)&>'(where()+mul(686,595)#&when()mul(916,990))what()mul(414,411)>why()&select()!}why() ?>mul(820,386)select()mul(324,473)mul(690,413)!>$why()mul(23,907)who()%<who()))how()^mul(65,111)where()^$mul(793,643)&who() mul(481,441)+<mul(796,772)#^mul(827,58)]{where()*#>mul(579,551)where()when()how()?~&@-why()>mul(359,283)[don't() }mul(238,664)!]~^^#(why()mul(128,702)mul(750,811)what()',do()'@where()select()from(),/+&mul(640,613),&%+why()^from()from()*mul(314~${~*how()?what() mul(593,269)who()*mul(865,609)what()@~$+mul(784,462))],;;'what(){mul(902,580)when()<{~ ?>~how()mul(22,360)]mul(650,584)#select()!(why()/;+when()mul(173,450)where()mul(126,232)(?@/^how()why()who()mul(148,272)&?when()where()]mul(93,105)?!}!:@!mul(428,270)- where(179,717)>@!-,how()why()don't()!where()who()$:<mul(439,76)*,^mul~mul(69,32)!how()}**what()mul(496,817)when()*how()^+~how()from()mul{]&when()-:}why(540,134)>mul(472,276)<'&where()mul(334,580)'/-?+;(-mul(78,731)select()mul(584,89)*/>don't()/;''~how()?<mul(106,855)']mul(996,656){%:mul(873,777);how()(:#mulwhere(939,627)#^><mul(186,441)when()+?who()'$mul(297,888)how()%'?:-{&mul(291,979)}># how(261,707)$],mul(983,656)*> mul(340,628)]*][[/mul(193,206)(})~mul*/-#mul(976,903)%#why()$}-&mul(734,303)what()[from()*-/why()do()&why()!*]@from()&when()mul(339,902)from()([,[*^?how()mul(2,449)when()how()why()mul(799,379)-!#-mul(704,107)mul(205,807) :mul(787,710)mul(575,659)when(),];~'!mul(755,669){+&%$-<mul(533,448);#from()how()$what()-don't()from()] )mul(663,118)$from()$;who()do()#from()*?from()%mul(521,701/how()mul(357,734)who()from()+select()who()(*{%:mul(900,877)[{mul(276,197)!how()who()}$}?mul}$:why()who()who()mul(635,783)mul(276,497)[select()how()select()>,where()}# mul(555,644);^who()!}mul(341:@#{mul(135,278)where()how()what();where()mul(439,633),]$how()why()mul(708,508)where()%{why(744,659)mul(700--(why()*%/where()#<@don't()$?mul(39what(),#})$ select()how()~mul(847,132){)what(134,971)what(336,162))&/what()mul(470,625)#mul(275,789)where()<]mul(15,846)when()from()mul(21,575)%from()^<from()@-}from()*mul(437,525))+!~{select()don't()>when()when() ~(+select()what()mul(554,360)from()]~mul(785,136)}%#:?mul(117,254)who()do()% %;%-from(747,86)how()^/mul(313,607)why()mul(678,806),(mul(226,595)#%mul(415,823)']mul(873,709)#;select()'<> *mul(121,496)why()who()what()?where()mul(590,916)',/@what()how()?%mul(477,943)when()who()/';%mul(654,383)select()*why()'^select()]select()&mul(433,312);//~++what()&<?do()who()^&from()#how();[[#mul(512,521)%>![]mul(532,452)
+*<@;mul(470,836why()who()select()#when()select()where()from(812,299)</mul(987,617)when()&%;mul(85,662) select()select()*?>mul(469,324) select()why(){mul(891,321);'&$%@{mul(792,73)$$[who()>[[from():mul>why()?how()mul(522,233)([%select()mul(195,940)&mul(368,872)~}{who();!!>^^mul(920,394)^,select():?!%[mul(477,578): what()~!/select())who()/mul(976,739)>;who()who(43,925)&when()>>;+mul(857,247) mul(442,620){;mul(393,289)-!*mul(848,511)?how()}@mul(290,212))(~+#~:mul(150]*/>who()[>?:<mul(289,261)><]*[;+what()where()mul(307,698);;from()~%;where(84,170)[${mul(158,165):[what()^select()mul(977,383)'*@<! )mul(188,493)mul(566,212)&,who()]do()mul(644,488)how())+]~who()where()mul(113,502)mul(306,625),] ;/#&$;who()mul(418,801)#>>/;:mul(920,657)*how()when()mul(816,293)select()~$+^+mul(420,667);(^where());<from()[,do()'where()/!where()&?when()>mul(402,31)]mul(272,313)^>mul(161,164)@$<mulfrom()$when()<mul(718,501)+-who()mul(960,325);who()&{?mul(615,493)select(){]when())#{from(465,35)mul(905,145){[,&>$mul(260,136)&@}* > -mul(380,442)^#*!don't())?(;@mul(209/%(>,how()^mul(423,410)from()-mul(381,141)+~-)mul(674,158)^:what()>(^)who()mul*^,mul(74,315)!-),mul(341,503)where()/;*)why()),what()&mul(624,435)mul(880,482)}where():<select():^>]why()mul(367,134)when()(when()mul(166,251)@+,who(),mul(610,271)+>)(mul(455,461)>&@-()from()+]mul(232,944)&,@when()@]mul(523,215)mul(876,836) mul(335,254)<#-{from()^mul(153,522)what(52,828)who()where()from()from()@&>$mul,!&<don't()why(768,688)what(),);'mul(851,963)]&;(mul(45,859)[;select() ~%]when()!where()mul(807,272):#from()mul(943,224)?$mul(415,924)'from()?mul(204,131)}(>what()^>*{'mul(670,505)$mul&&/<don't()why()@#(*~/:>(mul(672,267)mul(540,120)<$[->!}mul(234,539)!%]who(){mul(30,143)*mul(545,761)where()'!how(935,4)who()%'{~mul(673,752why()what()^:mul(111,407)from()}mul(860,90)#who()/^!how()-!{!mul(217,327)what()!'where()mul(729,143)where()!how()#mul(362,874)$how()how()->who()~^mul(315,718)!'-@~mul(206,449):/[??#mul(185,796)]~mul(597,268);) >select()from()?)<*mul(516,734)when()what()select()#$select()-?,$mul(366,627)%*{mul(62,39)<what()mul(511,35)mul(879,156)-@]from()#select()mul(247,306;!mul(183,347)<mul(638,126)+>^/$from()+mul(250+~select()!from(){mul(981,151)#}mul(92,876))how()who(363,963)mul(827,341)::how()~&mul(407,705)#+>mul(576,849)mul(482,236)(^* who(),what()mul(544%who()('>*!$@,}mul(113,286)when()'from(685,677)do()%from(614,566)-select()$,-mul(234,452)}>[&who(){#from()&don't()why()select(645,338):why(840,833)+#mul(874,529)}>what()select()why()mul(168,89)}{*when()}do()when()*?$^;?)]mul(811,383)!mul(770,725):!*#[from()from()from(487,367);:mul(564,858)(mul(248,563)*:;'mul??mul(254,676)+where()from()?'[){ how()mul(250,339))'!')where()<?mul(410,838)(where()@mul(102,412)where()mul(173,786)-![mul(92,40)mul(888,277)'from()do()mul(390,731)@what()who()@%@who()&&?mul(930,981)>}from()why()-*!mul(740,619)~$when(370,81)where()%-#;^mul(291;^<-mul(266,422)@%select()/why() [mul(794,513)where()>{+mul(944,970)!why();mul(968,484)<from(),:>/what()who()mul(285,45)when()who()^when(),mul(728,164),#/[)mul(568,114)%@:select() /*!mul(763,536)?@mul(506,503))do()@)^/mul(763,386)/why()how()from(417,323)>what() where()mul(260,628)?:'+$why()+@&mul(697,677)+]when():mul(246,278)
$mul(48,81)mul(266,777)who())@*~!?)# mul(843,750}<what()+>mul(940,128)mul(477,389)who()}:when())<[when()mul(838,845)<when():;*mul(248,817)don't()+what();&/)?>~mul(464,153)why(166,536)</mul(893,554)when()what(){how()&how()mul(505,410)>{/&,~mul(282,701) -!?from();mul(101,631)from()<when()*&mul(187,146)[@+<?{[#{<mul(424,344);!?why()%}what()*>/mul(236,985)why(458,58)do()&*&>how()mul(310,399) :{}^]don't()->when()from()+ mul(389,902)why(301,687) select()}> who()mul(265,840)/mul(652,469)~where()what(){<>~mul(792,402);> $+@select(747,467)[mul(720,836)%what(984,399)[select()-+{}}mul(757,143)-)%from(),)+where()mul(810,426)<!*mul(596,769)$ from():]how()mul(67,919)why(485,244)]why(506,511)how()&,[{% mul(794,823)!/]-*<'where()mul(872~%how()$<}]}why()~how()mul(413,924)?+[>#who()^@mul,]-'(^^>mul(30,409),)from() mul(916,685what()how(){#/mul(494,862)<who()>-&mul(814,480)!&what()*mul(315,311)!when() @}*%#mul(571,122)~*mul(717,593))/mul(633,314)<^{[%{when()-<?mul(26,322)mul(792;(?:^mul(592,551)&from();%]who()<,$mul(276,734):mul(478,513)]when(637,697){mul& @+'[+mul(848,726)how(),from()-!&,<#do() !-mul(412,173)?''when()select()select();'when()mul(306,288)(!when()how(100,872)>,{mul(571,721):?,@~]select(){mul(275,614),select()/<mul(611,515)how(635,963)select()mul(741,23),select()why()^who(),%#}mul(144,95,why()why()~@^when(555,987)(mul(380,549)%:%&how()&mul(19,964)where(),*why()#%mul(194,612)}+^when()[mul(491,112))//what(){#-:mul(239,5){,?>{[@mul(965,299)what()?$where()(#,(?mul(642,519),+~*]mul(830,103)/]:mul(61,609)from()where()from()([mul(808,331)$mul(885,259)))}mul(902,561)$*:mul(320,613)[where()}mul(374,288)~mul(720,106)*~$mul(967,879),who()[what()}when()/#$-mul(81,187)mul(368,22);];<}- @{mul(882,60)#select()when()mul(144,567);what(),,#don't(){+from()'! mul(608,319)(mul(225,187)%%(<,@#+%select()mul(130,278)!select()}<when()where()mul(348,92):from()[mul(483,262)don't()*+&&}$mul(500,537)%(what()what()select()+^;do()where()]][/%select()*mul(118,729)+;[!why()$@mul(155,535)}from() ^*#select()how()'mul(685,187))*don't()what()(&/{mul(174,160)&+~:mul(100,237)<mul(234,939)mul(328,456)mul(427,653))where()why(162,868){,mul(58,176)'}why()from()&'why()?mul(449,899)-when()how()what()do()#,{,mul(529,302)?<]'*how()who()*~mul(382,944)mul(348,909),]/mul(595,427)-:mul(896,889);-)<mul(212,114)[}what()#how()mul(796,319)from()who()mul(161,245),mul(211,760)]*<+]where()mul(239,248)%mul(634,18)mul(501,317)why()#[who(542,47)what()*who()~,$do()}} where()*~[when(696,90)~when()mul(736,662)*%-$select()-$who()/mul(297,910) when()(when()>'@mul(353,117)]%'-^/?^mul(799,639)who()}-[>mul(495,249)where()*,<mul(79,846)how();mul(317,217)/mul(699,367)when()}mul(390,121),![,+]//,don't()@{what()(>)~mul(768,867)why()mul(305,695)don't()?]where() ?#@(who()mul(748,367)why()+[mul(643,18)})mul(343,964){'mul(287,548)?%do(),from();/?';select()mul(97,411)!!{?mul(105,759)how())how()@mul(663,882)~[mul(709,411)@;]what()when()mul(267,470)&mul(857,988)}/]^-select()]^:where()do()why()where()]-*mul(566,77)-<why()how();:~>#mul(217,308)what()~~(select()&mul(462,131)<+]%how()select()mul(242,763)'select()why()mul(316,185)[when()/ mul(584,440)from()

42
2024/d03/ex2/ex2.py Executable file
View file

@ -0,0 +1,42 @@
#!/usr/bin/env python
import dataclasses
import re
import sys
@dataclasses.dataclass
class MulInstruction:
lhs: int
rhs: int
def calc(self) -> int:
return self.lhs * self.rhs
def solve(input: str) -> int:
def parse(input: str) -> list[MulInstruction]:
res: list[MulInstruction] = []
MUL_REGEX = re.compile(r"do\(\)|don't\(\)|mul\((\d+),(\d+)\)")
do = True
for match in MUL_REGEX.finditer(input):
if match.group(0) in ("do()", "don't()"):
do = match.group(0) == "do()"
continue
if not do:
continue
res.append(MulInstruction(int(match.group(1)), int(match.group(2))))
return res
return sum(inst.calc() for inst in parse(input))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

6
2024/d03/ex2/input Normal file
View file

@ -0,0 +1,6 @@
}}+{where()mul(873,602) mul(954,447)^where()~mul(548,799)-<what()mul(588,631)^who()'@( [mul(143,388)how(445,327))$ select()who()mul(746,719)mul(963,262)}'*+why()<?&/select()don't()[%]% ^^mul(933,492)don't() ^-who()(%how()]mul(583,700))!,where()mul(999,507)](mul(821,504)^%/;:-mul(471,220)who()&'who(161,37)<'mul(843,213),<mul(298,802)-()@how()where()@+[:mul(910,85)'when()($select()%-*mul(532,213)*from()select()$,what()mul(956,380)mul(326,87)mul(243,775)!/:from()&^^mul(118,409)!)what()select()mul(610,89)mul(432,774)from()# from()<mul(400,864):+&mul(957,923)'don't()+select()why()mul(496,383),&why()(-;)+!#mul(79,135)~{mul(500,619),#what(361,47)@&;@+mul(580,98)<>#why():$from()(!mul(660,615):where()mul(596,918)how()[what()how()who()]@mul(594,699)$>$&why()mul(951,813)mul(948,41)]mul(699,225)>mul(840,275):@~^@%^select()mul(695,594)what()->-mul(409,636)@ {++mul(999,290)when(339,689),[+[+?mul(558,848)how(),what()&}]{mul(344,337)$)$]+,$,,why()do()::select()^:mul(796,16)mul(526,718) mul(66,417)#@>~do()why()from()/select()when():&mul(8,111);!where()do()}@mul(433,239)*}how() {^!do()#^mul(167,905)-&%(mul(979,711)when()]who()'?mul(523,172)[^what(844,455)'what()[/~@mul(928,776)where()]&/mul(587,380)who()/when()how()from(),}#}mul(97,952)select(837,505)~@>~%mul(486,198)^!mul(968,779)do()[mul(206,321);,where()where())how()}/mul(6,867)-&<!*select()mul(615,984)~?who()#<{how()?@mul(617,643){ @,'why()+>what()(mul(683,583)^(mul(244,555)^where()(how()what()?-[,who()mul(827,305);&,!$*?mul(793,452)^ )+(%-where()<mul(318,238)<$-what()mul(802,394)?how()<mul(488,879)do()$}<:&mul(429,358)~how()mul(36,174)mul(87,398)+%what()]mul(822,311)mul(379,261)~when()mul(618,193)@)!))-what()how(645,829)[mul(964,102);who()don't(),[what(),,?select()why()@mul(121,293)select()@who()!mul(770,96)+;%from(467,168)mul(616,890)@%:)[mul(943,145) [from()&where(283,130){*where()mul(649,49)select())mul(877,73)from()do()where()?where()>who()from()@who(){*mul(592,919)/:what():who()mul(213,139)what()$!?*how(934,24)$-who()(mul(661,7)?from(),}/who()mul(876,585)how()why():when()[@@mul(433,918)why()why(),*{who()when()who()mul(144,14/#(<mul(656,306)&what()&{*@%select(709,225)/mul(843,135)who()$[don't()<mul(576,966)^,?>don't()@(@{~why()[who()mul(394,492)where()/mul(508,797)-mul(150,832)+$@why()(why()~mul(527,236)<don't()!#{how()*!,!mul(177,945)'mul(5,181)#!#'&?what()&mul(10,492):%/'*mul(822,748){!*]who()when()<!<mul(21,920)+do()-who()from(505,694)where()from()$who()where()where()/mul(827,561)how()when()mul(770,221)%when()who()mul(872,151)mul(453,84)['&+:mul(258,293)@#,where()mul(264,689)mul(90[mul(94,665)-who()don't()what()>!:@!^&!mul(324>?!from()where())mul(731,184)#(}who()'mul(666,377)how()(;mul(346,141)^select()/@[$how()@]?mul(702,502,^where()<}[mul(872,308)+^!<@from() {:mul(537,974)%when()when()%mul(563,805)select()>how()>^';mul(643,555))where(290,606)who()?mul(656,803),?$/*?when()}@ mul(228,902)~/from(){where()what()>@~mul(849,93)~+select()?-^}<don't()mul(844,117)(when()~,}# /:+mul(24,282)@where()~from()($what()what()*<mul(886,107)[#;mul(725,121) %[>mul(115,425)${what()mul(219,305)how()])from()<mul(401,458)-from()+mul(92,705)
}?/,(~+^mul(398,379)why()-!why(){}mul(618,341)how(818,559)'%}~+}'!<mul(128,74)*- &}+[mul(830,201)$when()mul(382,164) />select()~]~mul(41,659)<'{where():#+)$mul(447,137)where(120,771)$@why()#mul(457,857)<$from()$(who()@?mul(644,914)}mul(936,442);{*(why()mul(804,26);don't()why(),+*how() @:mul(668,778)%select() who() (,where()mul(66,974)^)when():$who()mul(832,615)#mul(572,646)where()how()what()when(673,330)where()when()&/mul(820,446)$why()where()mul(86,788)^~what()'mul(76,413)&'how()mul(616,424)what()select()}from()(/;mul(651,36)!{ mul[*mul(469,702)who()?;mul(331,879)?*from(54,751)who()#+[ mul(182,296)where(607,734){mul(920,190) :mul(660,732)^who()who()*'!mul(3,615)+{why(168,603)when(), mul(254,713); where()*from()~ !!#mul(897,311)]mul(629;what(280,32)>mul(194,563)^<how()when() }#<mul(27,237)?@where()mul(389,541)}'@when()}(*how()mul(671,516)do() ~select()!*']>&mulwho()when()'!what()why()?'}}!mul(414,213)$when()]+{why()mul(606,917)how()*?^,mul(292,543)>mul(326,145)*(&!;^:!#'mul;#@~where()<mul(81,169)mul(436,774)+when()%+where()-[}+mul(425,438)when()/}what()mul(76,978)>%;,from()select()mul(39,372)~[when()what()!+#who()]~mul(905,968from(843,581)(from()from()~what()how()when()mul(768,210)*mul(68,62)mul(777,345%{/select()%mul(458,251));what())how()where()how()when()mul(810,199)<~mul(252,749)don't()mul(915,327)(: mul(608,270)<%[!}-&mul(328,665)from()>*)how()mul(836,471)mul(270,799);(why();&~~mul(598,772)from()>mul(409,297)$mul(469,982)mul(457,665):@>{don't()why()<+,mul(293,172select(816,987)}why()mul(372,420)why()%mul(105,735),<]{mul?{$;>from()what()-$;mul(348,90)from()what()~mul(634,662)^do()$@]*)~,&mul(226,996)when()%]what()!@/&mul(322,135);who() &^select()*&}mul(967,104)from()}'who(701,7)~%[mul(687,163)@:<!how(){^/who()@mul(497,664))@!-(who()<mul(20,274)where(){%<where()?>+:mul(382,128)mul(831,450)mul(485,444)%^what()what()[$what()@}do()-%?'mul(204,152);$'/mul(63,376)mul(387,70)~@'{,':<mul(517,687)@ $^ )why()!mul(865,593)where(918,337)!;mul(786$$'$%why()select()[~$why()mul(667,335)~{+where()who()?from()mul(582,456)%,from()[from()how()mul(927,806)+(]?%mul(460,721)^^;^do(),how()when()select(435,369)}&mul(66[*how();>why()(%{how()<mul(997,260):'do()%::&what()}*who()mul(506,521)'who()%/!why()*&!don't()#@&mul(538,407)'^mul(84,106)'},#^where()%mul(105,225)-what()/how()/from()mul(49,421)@$)[)?why()'#}mul(707,127)@when() &(mul(732,645)'from()'*when()why()from()[who(850,51)?mul(566,427)how()>who()]',from()'how()why()mul(42,665)%'# [}mul(684,645){{%'mul(115,930)mul(552,181)mul(762,163)mul(202,193)+*[mul(525,337)+}-:](?^#mul(466,861)/do()'(;mul(860,319);mul(48,137){when() ~:< <mul(317,942)'~&#how()^mul(66,243)/(from()mul(678,119)when()!when()>from()mul(3,497)?when()< #?^@do()>;/?:mul(522,894)+{+mul(419,20)mul(139,677)where(119,273)*what()[^?mul(563,549)how()<@'%mul(560,434)what()where(),mul(886,302)mul(632,393)*what()!}{mul(769,651)'(mul(267,514)-[how()^:mul(64,902)when()mul(356,352# ;'mul(267,302)#(mul@;~+mul(471,643)!from())!what()from()~mul(429,997)/-mul(401,220)>{]what()what()@select()},mul(294,298)how()mul(230,3)/&what()]>]!how()/mul(888,907)](#>~}+#mul(17,816)/[+when()>from()]^:mul(94,85)
#)'{mul(531,103){ {where()what()from()mul(127,712))what()<mul(595,154)~>!%from()'/how()*when(940,337)mul(259,916)+}!-}[mul(703,780++;select()?why()[{mul(221,199)+mul(303,268)$don't()'[what();^mul(542,561);who()&,mul(68,800)[<'{}why()?^from()mul(26,194)?]who():;mul(641,921)#&where()mul(539,571)select()]~%%]when())mul(833,642);mul(209,564)}<^)when()mul(648,430/(#)/?(';where()what()mul(818,526) ]!what()do() <;:mulfrom() @-<select()what(557,962)$%mul(83,808)from()% {)mul(894,523){~?@'&,how()>mul(764,627)#/mul(887,607), do()$(},#^}}from()how()mul(184,287)where()$^mul(859,310){who()how()mul(692,592){>?&mul(223,912)what()^@ {{^@/mul(736,965)$)]];-#@&mul(600,145)~/}*-}how()mul(893,646):where()}mul(205,416)what()from()mul(35,844)mul(94,245))/<#</$when()who(236,448)mul(943,490)^?*!mul(187,639)select()mul(105,840)#;-;((&,select()mul(495,135)don't()when()(&mul(129,293)}}{~from()]select()*+mul(724,202)mul(540,481)+when()$><from()?$#mul(604,366)where()why()^select()mul(82,14){]what()##/^mul(661$mul(576,422)!}*mul(968,267)mul(501,251)<[,mul(999-mul(61,600)how()~ how()#&mul(488,199)+})who()# @what()mul(695,154)!{[don't()mul(454,729)what():(<%mul(656,115)from()!]when()when():?,mul(536,421)}select()when()<mul(550,82)(:mul(482,346)}%when()>+mul(189,780)from()how()#< ^don't()why()&who()where(){ >:mul(638,986)*+< ;mul(131,393),how(419,400)*@how()mul(856,729)who()$$[$[select()~<mul(553,105)why(720,700)']mul(780,579)}what()select()who()~//}^mul(811,393))/<#,mul(530,118)@'%<~mul(640,727)'-]:-:]+mul(124,151)~@{why()@/why()mul(523,641)'%select())/mul(70,234)-$#mul(589,488)^:how()(when()mul(66,473)$/!-{from()%]#]mul(417,212)~>{(when()$mul(613,175)}mul(503,337)~)what() mul:!-*}?~who()<mul(709,759)}what()^where()when()!select(820,39)]::mul(884,175):#mul(852,584)>-mul(649,886)+how(738,973)when()[(mul(593,702)where()%%^(]who()mul(456,697)%~^'when()how()mul(789,446)mul(737,439)mul(830,910):>why()when()how()'?]why()>do()#'&why()'from()mul(972,441):mul(157,521)mul(43,224):$who()>select()how()mul(52,740)'mul(136,716)select()mul(613,433)]>$^when()why()where()how();mul(978,314))$mul(695,29)}mul(778,660){how()<+$?mul(402,606)select()+~$do()mul(262,94)how()why()))#'^$@mul}mul(201,86)*select()mul(876,626)why()mul(174,750)where()(from()(mul(433,335)]@mul(29,940) :~what()$}where()select()mul(416,920)^&%<~^mul(276,648)mul(636,17);why()}-}mul(810,73)<@} how():from(900,831)what()mul(241,497)select()when()'&{mul(603,108):[,mul(941,454) $@mul>@<}'[, $mul(510,523)where(), ~];mul(584,102)<when()mul(907,301)]#select()select();{how()select()what()?mul(980,625)select())where(){:^mul(544,917)((how()['who()mul(628,364)who(272,887)@!^@{+~{don't()when() )(from()what()when()-mul(95,412)(mul(127,442)/mul(658,920)from()from())!$<&*mul(45,446)what()where()&![-% (%mul(304};do()why(81,149)#^mul(181,603)where()^;{(! ^;mul(381,353)~@$mul(129,558)where()?from(): mul(573,183<how()*how()(#(mul(626,301))?]/)how()mul(20,851)[$when()*how()mul(42,787)[! )@;:(;mul(98,614)why()mul(692,723)!'>' do()why()<&select(812,485)!mul(538,458)who()why()^'select(){{why()mul(773,196)when()why(713,26){,!do()?why()!when(),?mul(234,541)mul(558]!(%;}'-mul(721,55)
(<%@$?mul(856,705]>!#'++why() >#!/usr/bin/perlfrom()mul(147,188)<?$when()+$where()%mul(894,439)>where()what()mul(221,687)/)from()'[{mul(9,723)[{/?who()where()mul(113,227)> ~>$)mul(663,198)&[>#mul(567,600)]when()$@select())(%<&mul(472,423)#when()>(/]select()$;how(511,981)mul(785,371}-how():$where()(?~mul(731,455)mul(810,191);who()(@>,? !$mul(534,231&don't();]why();,#;where()[,mul(190,923) }when()mul <mul(909,876)[*~when()]mul(739,708)select()(@:~)/<@,mul(794,354)<mul(874,298)what()why()$+mul(669,535)&!^mul(260,4))mul(641,230)mul(516,429)'mul(141,983)!}when()select()where()+}[)do()&>:mul(525,573<{what() *$?from()from(){mul(885,340)why()>mul(398,414)?[where()<what()from()^mul(746,645)where(586,97)+'mul(523,150)/%()~how()where(580,13)@mul(446,624),'-mul(605,440),from()$/-where()mul(17,117) >$why()from())mul(988,667)mul(828,197)'why()/%*when()/*mul(799,415)where()]<~ ?>'-don't()^[(' ]%^~%mul(122,243)why();[how(951,959)how(435,882)~*-#don't()why()[what()what()'mul(218,944)!)&>'(where()+mul(686,595)#&when()mul(916,990))what()mul(414,411)>why()&select()!}why() ?>mul(820,386)select()mul(324,473)mul(690,413)!>$why()mul(23,907)who()%<who()))how()^mul(65,111)where()^$mul(793,643)&who() mul(481,441)+<mul(796,772)#^mul(827,58)]{where()*#>mul(579,551)where()when()how()?~&@-why()>mul(359,283)[don't() }mul(238,664)!]~^^#(why()mul(128,702)mul(750,811)what()',do()'@where()select()from(),/+&mul(640,613),&%+why()^from()from()*mul(314~${~*how()?what() mul(593,269)who()*mul(865,609)what()@~$+mul(784,462))],;;'what(){mul(902,580)when()<{~ ?>~how()mul(22,360)]mul(650,584)#select()!(why()/;+when()mul(173,450)where()mul(126,232)(?@/^how()why()who()mul(148,272)&?when()where()]mul(93,105)?!}!:@!mul(428,270)- where(179,717)>@!-,how()why()don't()!where()who()$:<mul(439,76)*,^mul~mul(69,32)!how()}**what()mul(496,817)when()*how()^+~how()from()mul{]&when()-:}why(540,134)>mul(472,276)<'&where()mul(334,580)'/-?+;(-mul(78,731)select()mul(584,89)*/>don't()/;''~how()?<mul(106,855)']mul(996,656){%:mul(873,777);how()(:#mulwhere(939,627)#^><mul(186,441)when()+?who()'$mul(297,888)how()%'?:-{&mul(291,979)}># how(261,707)$],mul(983,656)*> mul(340,628)]*][[/mul(193,206)(})~mul*/-#mul(976,903)%#why()$}-&mul(734,303)what()[from()*-/why()do()&why()!*]@from()&when()mul(339,902)from()([,[*^?how()mul(2,449)when()how()why()mul(799,379)-!#-mul(704,107)mul(205,807) :mul(787,710)mul(575,659)when(),];~'!mul(755,669){+&%$-<mul(533,448);#from()how()$what()-don't()from()] )mul(663,118)$from()$;who()do()#from()*?from()%mul(521,701/how()mul(357,734)who()from()+select()who()(*{%:mul(900,877)[{mul(276,197)!how()who()}$}?mul}$:why()who()who()mul(635,783)mul(276,497)[select()how()select()>,where()}# mul(555,644);^who()!}mul(341:@#{mul(135,278)where()how()what();where()mul(439,633),]$how()why()mul(708,508)where()%{why(744,659)mul(700--(why()*%/where()#<@don't()$?mul(39what(),#})$ select()how()~mul(847,132){)what(134,971)what(336,162))&/what()mul(470,625)#mul(275,789)where()<]mul(15,846)when()from()mul(21,575)%from()^<from()@-}from()*mul(437,525))+!~{select()don't()>when()when() ~(+select()what()mul(554,360)from()]~mul(785,136)}%#:?mul(117,254)who()do()% %;%-from(747,86)how()^/mul(313,607)why()mul(678,806),(mul(226,595)#%mul(415,823)']mul(873,709)#;select()'<> *mul(121,496)why()who()what()?where()mul(590,916)',/@what()how()?%mul(477,943)when()who()/';%mul(654,383)select()*why()'^select()]select()&mul(433,312);//~++what()&<?do()who()^&from()#how();[[#mul(512,521)%>![]mul(532,452)
+*<@;mul(470,836why()who()select()#when()select()where()from(812,299)</mul(987,617)when()&%;mul(85,662) select()select()*?>mul(469,324) select()why(){mul(891,321);'&$%@{mul(792,73)$$[who()>[[from():mul>why()?how()mul(522,233)([%select()mul(195,940)&mul(368,872)~}{who();!!>^^mul(920,394)^,select():?!%[mul(477,578): what()~!/select())who()/mul(976,739)>;who()who(43,925)&when()>>;+mul(857,247) mul(442,620){;mul(393,289)-!*mul(848,511)?how()}@mul(290,212))(~+#~:mul(150]*/>who()[>?:<mul(289,261)><]*[;+what()where()mul(307,698);;from()~%;where(84,170)[${mul(158,165):[what()^select()mul(977,383)'*@<! )mul(188,493)mul(566,212)&,who()]do()mul(644,488)how())+]~who()where()mul(113,502)mul(306,625),] ;/#&$;who()mul(418,801)#>>/;:mul(920,657)*how()when()mul(816,293)select()~$+^+mul(420,667);(^where());<from()[,do()'where()/!where()&?when()>mul(402,31)]mul(272,313)^>mul(161,164)@$<mulfrom()$when()<mul(718,501)+-who()mul(960,325);who()&{?mul(615,493)select(){]when())#{from(465,35)mul(905,145){[,&>$mul(260,136)&@}* > -mul(380,442)^#*!don't())?(;@mul(209/%(>,how()^mul(423,410)from()-mul(381,141)+~-)mul(674,158)^:what()>(^)who()mul*^,mul(74,315)!-),mul(341,503)where()/;*)why()),what()&mul(624,435)mul(880,482)}where():<select():^>]why()mul(367,134)when()(when()mul(166,251)@+,who(),mul(610,271)+>)(mul(455,461)>&@-()from()+]mul(232,944)&,@when()@]mul(523,215)mul(876,836) mul(335,254)<#-{from()^mul(153,522)what(52,828)who()where()from()from()@&>$mul,!&<don't()why(768,688)what(),);'mul(851,963)]&;(mul(45,859)[;select() ~%]when()!where()mul(807,272):#from()mul(943,224)?$mul(415,924)'from()?mul(204,131)}(>what()^>*{'mul(670,505)$mul&&/<don't()why()@#(*~/:>(mul(672,267)mul(540,120)<$[->!}mul(234,539)!%]who(){mul(30,143)*mul(545,761)where()'!how(935,4)who()%'{~mul(673,752why()what()^:mul(111,407)from()}mul(860,90)#who()/^!how()-!{!mul(217,327)what()!'where()mul(729,143)where()!how()#mul(362,874)$how()how()->who()~^mul(315,718)!'-@~mul(206,449):/[??#mul(185,796)]~mul(597,268);) >select()from()?)<*mul(516,734)when()what()select()#$select()-?,$mul(366,627)%*{mul(62,39)<what()mul(511,35)mul(879,156)-@]from()#select()mul(247,306;!mul(183,347)<mul(638,126)+>^/$from()+mul(250+~select()!from(){mul(981,151)#}mul(92,876))how()who(363,963)mul(827,341)::how()~&mul(407,705)#+>mul(576,849)mul(482,236)(^* who(),what()mul(544%who()('>*!$@,}mul(113,286)when()'from(685,677)do()%from(614,566)-select()$,-mul(234,452)}>[&who(){#from()&don't()why()select(645,338):why(840,833)+#mul(874,529)}>what()select()why()mul(168,89)}{*when()}do()when()*?$^;?)]mul(811,383)!mul(770,725):!*#[from()from()from(487,367);:mul(564,858)(mul(248,563)*:;'mul??mul(254,676)+where()from()?'[){ how()mul(250,339))'!')where()<?mul(410,838)(where()@mul(102,412)where()mul(173,786)-![mul(92,40)mul(888,277)'from()do()mul(390,731)@what()who()@%@who()&&?mul(930,981)>}from()why()-*!mul(740,619)~$when(370,81)where()%-#;^mul(291;^<-mul(266,422)@%select()/why() [mul(794,513)where()>{+mul(944,970)!why();mul(968,484)<from(),:>/what()who()mul(285,45)when()who()^when(),mul(728,164),#/[)mul(568,114)%@:select() /*!mul(763,536)?@mul(506,503))do()@)^/mul(763,386)/why()how()from(417,323)>what() where()mul(260,628)?:'+$why()+@&mul(697,677)+]when():mul(246,278)
$mul(48,81)mul(266,777)who())@*~!?)# mul(843,750}<what()+>mul(940,128)mul(477,389)who()}:when())<[when()mul(838,845)<when():;*mul(248,817)don't()+what();&/)?>~mul(464,153)why(166,536)</mul(893,554)when()what(){how()&how()mul(505,410)>{/&,~mul(282,701) -!?from();mul(101,631)from()<when()*&mul(187,146)[@+<?{[#{<mul(424,344);!?why()%}what()*>/mul(236,985)why(458,58)do()&*&>how()mul(310,399) :{}^]don't()->when()from()+ mul(389,902)why(301,687) select()}> who()mul(265,840)/mul(652,469)~where()what(){<>~mul(792,402);> $+@select(747,467)[mul(720,836)%what(984,399)[select()-+{}}mul(757,143)-)%from(),)+where()mul(810,426)<!*mul(596,769)$ from():]how()mul(67,919)why(485,244)]why(506,511)how()&,[{% mul(794,823)!/]-*<'where()mul(872~%how()$<}]}why()~how()mul(413,924)?+[>#who()^@mul,]-'(^^>mul(30,409),)from() mul(916,685what()how(){#/mul(494,862)<who()>-&mul(814,480)!&what()*mul(315,311)!when() @}*%#mul(571,122)~*mul(717,593))/mul(633,314)<^{[%{when()-<?mul(26,322)mul(792;(?:^mul(592,551)&from();%]who()<,$mul(276,734):mul(478,513)]when(637,697){mul& @+'[+mul(848,726)how(),from()-!&,<#do() !-mul(412,173)?''when()select()select();'when()mul(306,288)(!when()how(100,872)>,{mul(571,721):?,@~]select(){mul(275,614),select()/<mul(611,515)how(635,963)select()mul(741,23),select()why()^who(),%#}mul(144,95,why()why()~@^when(555,987)(mul(380,549)%:%&how()&mul(19,964)where(),*why()#%mul(194,612)}+^when()[mul(491,112))//what(){#-:mul(239,5){,?>{[@mul(965,299)what()?$where()(#,(?mul(642,519),+~*]mul(830,103)/]:mul(61,609)from()where()from()([mul(808,331)$mul(885,259)))}mul(902,561)$*:mul(320,613)[where()}mul(374,288)~mul(720,106)*~$mul(967,879),who()[what()}when()/#$-mul(81,187)mul(368,22);];<}- @{mul(882,60)#select()when()mul(144,567);what(),,#don't(){+from()'! mul(608,319)(mul(225,187)%%(<,@#+%select()mul(130,278)!select()}<when()where()mul(348,92):from()[mul(483,262)don't()*+&&}$mul(500,537)%(what()what()select()+^;do()where()]][/%select()*mul(118,729)+;[!why()$@mul(155,535)}from() ^*#select()how()'mul(685,187))*don't()what()(&/{mul(174,160)&+~:mul(100,237)<mul(234,939)mul(328,456)mul(427,653))where()why(162,868){,mul(58,176)'}why()from()&'why()?mul(449,899)-when()how()what()do()#,{,mul(529,302)?<]'*how()who()*~mul(382,944)mul(348,909),]/mul(595,427)-:mul(896,889);-)<mul(212,114)[}what()#how()mul(796,319)from()who()mul(161,245),mul(211,760)]*<+]where()mul(239,248)%mul(634,18)mul(501,317)why()#[who(542,47)what()*who()~,$do()}} where()*~[when(696,90)~when()mul(736,662)*%-$select()-$who()/mul(297,910) when()(when()>'@mul(353,117)]%'-^/?^mul(799,639)who()}-[>mul(495,249)where()*,<mul(79,846)how();mul(317,217)/mul(699,367)when()}mul(390,121),![,+]//,don't()@{what()(>)~mul(768,867)why()mul(305,695)don't()?]where() ?#@(who()mul(748,367)why()+[mul(643,18)})mul(343,964){'mul(287,548)?%do(),from();/?';select()mul(97,411)!!{?mul(105,759)how())how()@mul(663,882)~[mul(709,411)@;]what()when()mul(267,470)&mul(857,988)}/]^-select()]^:where()do()why()where()]-*mul(566,77)-<why()how();:~>#mul(217,308)what()~~(select()&mul(462,131)<+]%how()select()mul(242,763)'select()why()mul(316,185)[when()/ mul(584,440)from()

43
2024/d04/ex1/ex1.py Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python
import itertools
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[Point, str]:
return {
Point(x, y): c for x, line in enumerate(input) for y, c in enumerate(line)
}
def count_xmas(grid: dict[Point, str], dims: Point) -> int:
max_x, max_y = dims
count = 0
for x, y in itertools.product(range(max_x), range(max_y)):
for dx, dy in itertools.product(range(-1, 1 + 1), repeat=2):
if dx == 0 and dy == 0:
continue
count += all(
grid.get(Point(x + dx * i, y + dy * i)) == c
for i, c in enumerate("XMAS")
)
return count
lines = input.splitlines()
grid = parse(lines)
return count_xmas(grid, Point(len(lines), len(lines[0])))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

140
2024/d04/ex1/input Normal file
View file

@ -0,0 +1,140 @@
SASASMSSSMSMSMSMSSMSAMXMAMAMXSXXXMAMMXSAMXMXMXSMMMXXXSXXAXSMMMAMXAXSMSSXXMSASASMXSSMSMSXMMMAMMMXXSAMXSSMXAXSASMMMXMASAXSXMXMAMXAMXXMAXXAMAMX
AASAXAAAAXXASASMXSAXAMXXSMSSMSAXSMSMMASAMAAXMAMAAAMMMMMSMXSAMXSSMSMXMAXMASXAXAMXAAXMAMXAMASAMAAMXMASAMAAMSMSASASMMMMAMSXSMASMMSMSMMASMMMSAMA
MXMXMMMSMMMMMAMXAMXMSSSMAXAAXMAMAAAXMASASMSXMASMMXSAAAAAMAXAMAXAAXAAMXMAMXMSMSMMXMASMSMXSASAXXXSASXMASXMMXAMMMAMMAXMXMMAXXAMAAAAAAMAMAAXSAMA
XSMSAXMAMAAXMAMMSSXSAAXSMMXXMASMMSMSMXSMMAMMSMAAXASMSMSSSMSSMMSMMMSSSSSSSMAMAAXMXXXAAAAAMMSAMSMSASMSXMASAXSAMMSMSMMMAAMAMMSSMSMSSSMAMMSMSAMX
XMAMAMSASMSSSMSAXAMXMSMAXAMMMXXXXMMXMAMAMXMXAXMMMMSAMAAXAXAXMXMAMXMXAAMAAMAMXMMXMMMMMMMMSAMAMMAMAMAMASXMXMXXSAXMAAASXSMXSAAAXXAXAXXSSMMASAMM
XMAMAMXAMXXXM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AAAAXAXAXMASMSMMSXSMMXMXXXMASXMXMSXSMASASAXMXXM
MSAAXSMMSAMAMMAMXAMAXASAMMXSAMSMMXMSSXSASMMAAMXMAMAAAMXMMMSMMAMSMSXMASXSASMMXSASMXMAXMAMXMASMSMSSSMXSASASXMAXXMXMXMASXSMAMAXMASAAMXMMMAMSMAX
SSMSXSAAXXMASXSXSASMSASAMAAMAMMMSXXXAASAMXMSMMSSMMXSAMAXSAMXMMMXAXASAMAMXMAMAMMMAXMAMMAMAMMSAXXMMXXAXXMAMXMSSSMSXXAAXXXMASXMASMMMSSMXMSAASXM
XXAAMMMMSMSASAXAMAAXMASAMMSSMMMAMAMMMMMAMXAMXAAAAAMMAMXXMASXMMSMXMASAMXMASMMMSSSSSMAMSASXSSMMMASASASMSMSMSAAAAAMMMMMSMMMASAMSXAXAAXMAAXSMSXM
MMMMAAAXAMMASMMXMSMSAMXXXXAAASMAMXMASXSSMMSMMMSSMMMSAMSXSAMXAAAAASXSAMXSASAAXAAAAAXAMSAMAMXAMSXMASAMSXAAAMMMSMMMAAAXXMASXSMMASMMMSASMSMAXMMS
XMMXSMSMMSMAMXXXXXMAMSAMXMSSMMSMSASMSXXAXAXXMAXXMSAMXXXXMASAMSMSAMXSXMAMXSXMMMSMSMMMMMAMAMSSMMMMAMAMAMSMXMXXMXMASMMSAMXAASAMXSXXXXMXAMMAMXSX

49
2024/d04/ex2/ex2.py Executable file
View file

@ -0,0 +1,49 @@
#!/usr/bin/env python
import itertools
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[Point, str]:
return {
Point(x, y): c for x, line in enumerate(input) for y, c in enumerate(line)
}
def count_xmas(grid: dict[Point, str], dims: Point) -> int:
max_x, max_y = dims
count = 0
for x, y in itertools.product(range(max_x), range(max_y)):
if grid.get(Point(x, y)) != "A":
continue
if {grid.get(Point(x + dx, y + dy)) for dx, dy in ((-1, -1), (1, 1))} != {
"M",
"S",
}:
continue
if {grid.get(Point(x + dx, y + dy)) for dx, dy in ((1, -1), (-1, 1))} != {
"M",
"S",
}:
continue
count += 1
return count
lines = input.splitlines()
grid = parse(lines)
return count_xmas(grid, Point(len(lines), len(lines[0])))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

140
2024/d04/ex2/input Normal file
View file

@ -0,0 +1,140 @@
SASASMSSSMSMSMSMSSMSAMXMAMAMXSXXXMAMMXSAMXMXMXSMMMXXXSXXAXSMMMAMXAXSMSSXXMSASASMXSSMSMSXMMMAMMMXXSAMXSSMXAXSASMMMXMASAXSXMXMAMXAMXXMAXXAMAMX
AASAXAAAAXXASASMXSAXAMXXSMSSMSAXSMSMMASAMAAXMAMAAAMMMMMSMXSAMXSSMSMXMAXMASXAXAMXAAXMAMXAMASAMAAMXMASAMAAMSMSASASMMMMAMSXSMASMMSMSMMASMMMSAMA
MXMXMMMSMMMMMAMXAMXMSSSMAXAAXMAMAAAXMASASMSXMASMMXSAAAAAMAXAMAXAAXAAMXMAMXMSMSMMXMASMSMXSASAXXXSASXMASXMMXAMMMAMMAXMXMMAXXAMAAAAAAMAMAAXSAMA
XSMSAXMAMAAXMAMMSSXSAAXSMMXXMASMMSMSMXSMMAMMSMAAXASMSMSSSMSSMMSMMMSSSSSSSMAMAAXMXXXAAAAAMMSAMSMSASMSXMASAXSAMMSMSMMMAAMAMMSSMSMSSSMAMMSMSAMX
XMAMAMSASMSSSMSAXAMXMSMAXAMMMXXXXMMXMAMAMXMXAXMMMMSAMAAXAXAXMXMAMXMXAAMAAMAMXMMXMMMMMMMMSAMAMMAMAMAMASXMXMXXSAXMAAASXSMXSAAAXXAXAXXSSMMASAMM
XMAMAMXAMXXXMAMXMMAXAAXMXSAASAMXSMASMASAMXSXMSXSXAMAMMMSSMMSXXMASAMMMMMXXMASMMMSMMASAMASMASXMMAMASXMAMXMAMSXMXSSSSMAMAXAMMSMMSMMAMXMAAMXMMMA
MSASXSMSMXSAMXMMMMSMXMM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XMAXXMXMXMASXSMAMAXMASAAMXMMMAMSMAX
SSMSXSAAXXMASXSXSASMSASAMAAMAMMMSXXXAASAMXMSMMSSMMXSAMAXSAMXMMMXAXASAMAMXMAMAMMMAXMAMMAMAMMSAXXMMXXAXXMAMXMSSSMSXXAAXXXMASXMASMMMSSMXMSAASXM
XXAAMMMMSMSASAXAMAAXMASAMMSSMMMAMAMMMMMAMXAMXAAAAAMMAMXXMASXMMSMXMASAMXMASMMMSSSSSMAMSASXSSMMMASASASMSMSMSAAAAAMMMMMSMMMASAMSXAXAAXMAAXSMSXM
MMMMAAAXAMMASMMXMSMSAMXXXXAAASMAMXMASXSSMMSMMMSSMMMSAMSXSAMXAAAAASXSAMXSASAAXAAAAAXAMSAMAMXAMSXMASAMSXAAAMMMSMMMAAAXXMASXSMMASMMMSASMSMAXMMS
XMMXSMSMMSMAMXXXXXMAMSAMXMSSMMSMSASMSXXAXAXXMAXXMSAMXXXXMASAMSMSAMXSXMAMXSXMMMSMSMMMMMAMAMSSMMMMAMAMAMSMXMXXMXMASMMSAMXAASAMXSXXXXMXAMMAMXSX

48
2024/d05/ex1/ex1.py Executable file
View file

@ -0,0 +1,48 @@
#!/usr/bin/env python
import collections
import sys
Graph = dict[int, set[int]]
def solve(input: str) -> int:
def parse_ordering(input: str) -> Graph:
graph: Graph = collections.defaultdict(set)
for l in input.splitlines():
lhs, rhs = map(int, l.split("|"))
graph[lhs].add(rhs)
return graph
def parse_updates(input: str) -> list[list[int]]:
return [[int(n) for n in line.split(",")] for line in input.splitlines()]
def parse(input: str) -> tuple[Graph, list[list[int]]]:
ordering, updates = input.split("\n\n")
return parse_ordering(ordering), parse_updates(updates)
def validate_update(ordering: Graph, update: list[int]) -> bool:
for i in range(len(update)):
for j in range(i + 1, len(update)):
lhs, rhs = update[i], update[j]
if lhs in ordering[rhs]:
return False
return True
def get_middle(update: list[int]) -> int:
assert len(update) % 2 == 1 # Sanity check
return update[len(update) // 2]
ordering, updates = parse(input)
return sum(
get_middle(update) for update in updates if validate_update(ordering, update)
)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1375
2024/d05/ex1/input Normal file

File diff suppressed because it is too large Load diff

60
2024/d05/ex2/ex2.py Executable file
View file

@ -0,0 +1,60 @@
#!/usr/bin/env python
import collections
import copy
import functools
import sys
Graph = dict[int, set[int]]
def solve(input: str) -> int:
def parse_ordering(input: str) -> Graph:
graph: Graph = collections.defaultdict(set)
for l in input.splitlines():
lhs, rhs = map(int, l.split("|"))
graph[lhs].add(rhs)
return graph
def parse_updates(input: str) -> list[list[int]]:
return [[int(n) for n in line.split(",")] for line in input.splitlines()]
def parse(input: str) -> tuple[Graph, list[list[int]]]:
ordering, updates = input.split("\n\n")
return parse_ordering(ordering), parse_updates(updates)
def validate_update(ordering: Graph, update: list[int]) -> tuple[int, int] | None:
for i in range(len(update)):
for j in range(i + 1, len(update)):
lhs, rhs = update[i], update[j]
if lhs in ordering[rhs]:
return i, j
return None
def get_middle(update: list[int]) -> int:
assert len(update) % 2 == 1 # Sanity check
return update[len(update) // 2]
def fix_update(ordering: Graph, update: list[int]) -> list[int]:
# The graph has cycles, so using a topological sort is out
# Instead just swap the wrong pages until we fixed the update
update = copy.copy(update)
while (indices := validate_update(ordering, update)) is not None:
lhs, rhs = indices
update[lhs], update[rhs] = update[rhs], update[lhs]
return update
ordering, updates = parse(input)
invalid_updates = filter(functools.partial(validate_update, ordering), updates)
fixed_updates = map(functools.partial(fix_update, ordering), invalid_updates)
return sum(get_middle(update) for update in fixed_updates)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1375
2024/d05/ex2/input Normal file

File diff suppressed because it is too large Load diff

99
2024/d06/ex1/ex1.py Executable file
View file

@ -0,0 +1,99 @@
#!/usr/bin/env python
import enum
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class Direction(enum.StrEnum):
UP = "^"
RIGHT = ">"
DOWN = "v"
LEFT = "<"
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.UP:
dx, dy = -1, 0
case Direction.RIGHT:
dx, dy = 0, 1
case Direction.DOWN:
dx, dy = 1, 0
case Direction.LEFT:
dx, dy = 0, -1
return Point(p.x + dx, p.y + dy)
def turn_right(self) -> "Direction":
match self:
case Direction.UP:
return Direction.RIGHT
case Direction.RIGHT:
return Direction.DOWN
case Direction.DOWN:
return Direction.LEFT
case Direction.LEFT:
return Direction.UP
class Guard(NamedTuple):
pos: Point
dir: Direction
def patrol_step(self, blockers: set[Point]) -> "Guard":
next_step = self.dir.step(self.pos)
if next_step not in blockers:
return Guard(next_step, self.dir)
return Guard(self.pos, self.dir.turn_right())
def solve(input: str) -> int:
def parse(input: list[str]) -> tuple[Guard, set[Point]]:
guard: Guard | None = None
blockers: set[Point] = set()
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
if c == "#":
blockers.add(Point(x, y))
continue
guard = Guard(Point(x, y), Direction(c))
assert guard is not None # Sanity check
return guard, blockers
def patrol(guard: Guard, blockers: set[Point], dims: Point) -> int:
max_x, max_y = dims
positions = {guard.pos}
while True:
if not (0 <= guard.pos.x < max_x):
break
if not (0 <= guard.pos.y < max_y):
break
positions.add(guard.pos)
guard = guard.patrol_step(blockers)
return len(positions)
lines = input.splitlines()
guard, blockers = parse(lines)
max_x, max_y = len(lines), len(lines[0])
return patrol(guard, blockers, Point(max_x, max_y))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

130
2024/d06/ex1/input Normal file
View file

@ -0,0 +1,130 @@
.........................................#.....#..##.....................#...........................#.....................#....#.
..................#................................#..#.................................#................#........................
.....##.........#..#........#......#............#.....#..................#............................#...#...#..#...#............
#..#...#....#...#.................................#.........................................#...............................#.....
.................##...................................................#.........................#....................#............
.............#.............#...................#...................#..................................#....#..#........#....#.....
..#.........................................................................................##....#.................#.............
...........#.........#.....#..#.................#...........##..........#....#....................................#........#.#....
#...#.........................................#..........................................................#........................
.............................................#................................#...............................##..........#.......
......#....#..............#..........................................#....#........................#...................##....#....
........#.#..............................#..#.............#.......#............................................................#..
....#...............#...#..#......#...........................#........................#...........#...#...................#......
..........................#...........##....#.......................................#..........................#.#................
....................#.........................................................#........#..........................................
..............#.............#.##.............#.........#..........#.......................................#...#.........#..#......
...............................................................#..........#........#.........#.............#.............#........
............#.................#...................#....#......................................................................#...
.......#....##....#......##.........#...........................................#....................................#.........#..
......#...#......................#............................##....##....................#.......................................
...................................##....................#.............................#........................#.................
..........................#.#.........................#..........................................................#................
.............#...#..........................................................#..#.#.#.....#....#.....#...................#........#
....#......#.............#...#......#.........#............##..................#.......................#..........................
.......................#.....#...................................#..........................#.....................................
#.....##....................................#.....#.....................................................#....#....................
............#...#...................................................................#.........#......................#............
................#....................................#.....#.........#.........#..............#...................................
..........................................................................................#.....#.#...#.........#.......#.........
#.............#..............................................#...#.#..#.....................#...#............#.#...#..............
..........................................#..................................................................#...#................
.........#.............................................#................................#.................#.....#................#
........................................................................................#.......#.....#..........#..........#.....
...........................#.......#......#..........#............#...............#........#...#......#...........................
...##...................#.................................#..................................##...................................
........................................................#.#.#.....#............................##................#................
......................................#....................#..................#...#.............................#...........#.....
.............................#...#.................#.............................#..............#.................................
#.....................................................................................................................#..#.....#..
...........................#..............................................#................................#....................#.
......#..................##................#....................#.............................................................#..#
.................#....................................................................................#...........................
....#.#..................................#..#........................##...#.............................#..............#..........
...............................................................................................................#...#.....#........
..#...................#.......................#........................................................................#..........
..#............#......................................###.........#..............................#..........#.................#...
.................................#..........................................................................#............#........
......................#...#...............#..............................#.......#........................#...........#........#..
..#..................#............................................................................#......#........................
..........................................................................#....#........#...................#.............#.......
..............#.........#.#............................................................................................#..........
........................#...#............................................#..............................#.........................
.........................................#...................................................#........................#...........
...#.................................................#..........#.............................#.....#.#.........#.................
............................#...........#...............................................................#........................#
..........................#..#..................#....................................#..................#.......................#.
......#...................#..............................#........#.##..........................................................#.
...........................#.....#.............................................................................#..................
..............#........................................................#.#.......#...#................#....#......................
...#...#..........................................................................................................................
..........##.....................#.#.............#...............................#.........................................#......
.#.#...................#.................................#.................................................#....#.................
........................#..............................................................................................#.......#..
...#....................................................................................................#.....##.....#............
.............#........................#.....................................................#.............#....................#.#
#........................................................................................#.....#..................................
........#..............#...............................#.......#...................................#..........#...................
.....................#.........................#.......#.......#.....#...........................................................#
...............#.....................................................................#..........#.................................
.................................#....#..........#..............................#...........#............................#........
..............#......#.........#...#.............#.......................#....#...................................................
...........................................................^.......................................................#..............
..........#...............................#.........................#.....................................................#.....#.
.##.....................#....................#.....#.......................................................#..##...#..........#...
.......................#...........#..#.#.....................................................#....................#..............
..................................................................#......#.............#..................................#.......
.#............................................#........................#...................................#.........#............
..................................................................................#.##.........................#..................
................#........#...........................................#...................................#........................
...............#........#....#...................#................................#........#.....#..........#.................#...
.....#.............................#..........................................................................................#...
............#..............#.....#........................................#............#............##..........#.................
........................................................................................#..........................#........##....
..#............................#...#.................................#....#..............#........................................
...#.....................#...........................................................................#.....................#......
....#.........................#.............#..................................#.........#..............#.........................
.....................#...................................................................................#..#......#..............
.....#.................................#...............................#.....#..........#.........................................
............#........#..........#....................#....................#..#.#.....................................#............
........................................#......#......................#......................................#..#.......#.........
...#...........#...............#.................#.............................................#..........#...#...................
.......#....##..............................#......#.......................#..................#..........#.................#...#..
.................................##...........................................................#....#..........#.#........#........
..................................#....##..#..#.......#............................#............#.#........................#......
..........................................#.....................................#.............##...#............#.................
....#....................#................................#....#..#.....................#................#...#..#..#..............
.............#...#..............................................................................#.................................
..........#..........................#.......................................#....................#..#.......#.........#.....#....
......................#............#...............#.....#.................#...............................#...#....#.........##..
..........................................................................##.............................#...#..............#.....
#.#...#..................................................#..................................#..#...#..............................
...........................................#....#..............#.........................#........................................
...........#....................#.....................##........................#.....#...................................#....#..
..........#..........#.................................................#...............................................#..........
.....................................................................................#......#.....................#.#.............
........#.#..........................#...............................................................................#............
..............#..#.............#...........#......................#....#..#......#...................#............................
........#.......#.................#........#..........#.....................#.........................................#...........
..........................................................#...................................#.....#.........#......#...#........
..........#.....#.....................#............#............#.#......................#....#.##.............#...........#......
...#.#..#.......#......#........#...........................#....................#.....#.........#...........#.................#..
........#.......................................#............#.............#..................#......#......#...............#.#...
....................#.....#........#.........................#.................................................#................#.
.......#..#...........................................#......#..................#..#......................#..#....................
#.#........#....#...#.............................................#............................#.....................#............
#...................#...........#...................#..#................................................................#.#.......
............#...#.#...........#..#.....................................................................#........................#.
...#..............................................#..............#......#...#..............................................#......
................#...#..#..................................................................................................##...#..
.............................#...#..#........#.........#...#...................#............................................#.....
............#......................#.......................................................#.#....................................
...#......................#......#.#...........................................#.....#....#......................#...#............
.....#..#..........#.............................#..........................................#............#..................#.....
.................#...#.......................#..................................................#....................#............
............#..................................................#.....#..............#.......#.............................#.#....#
........#.............#..#.......................................................................................#.........#......
......#...................#..........................................................#................#................#.........#
..................#...........................#.....#....#.......................................#..#......................#......
....................#....................................#....................#........#............#........#....#...............
.........#..............#....#.............................#..#..........#........#.....................#.#.........#.............

116
2024/d06/ex2/ex2.py Executable file
View file

@ -0,0 +1,116 @@
#!/usr/bin/env python
import enum
import itertools
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class Direction(enum.StrEnum):
UP = "^"
RIGHT = ">"
DOWN = "v"
LEFT = "<"
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.UP:
dx, dy = -1, 0
case Direction.RIGHT:
dx, dy = 0, 1
case Direction.DOWN:
dx, dy = 1, 0
case Direction.LEFT:
dx, dy = 0, -1
return Point(p.x + dx, p.y + dy)
def turn_right(self) -> "Direction":
match self:
case Direction.UP:
return Direction.RIGHT
case Direction.RIGHT:
return Direction.DOWN
case Direction.DOWN:
return Direction.LEFT
case Direction.LEFT:
return Direction.UP
class Guard(NamedTuple):
pos: Point
dir: Direction
def patrol_step(self, blockers: set[Point]) -> "Guard":
next_step = self.dir.step(self.pos)
if next_step not in blockers:
return Guard(next_step, self.dir)
return Guard(self.pos, self.dir.turn_right())
def solve(input: str) -> int:
def parse(input: list[str]) -> tuple[Guard, set[Point]]:
guard: Guard | None = None
blockers: set[Point] = set()
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
if c == "#":
blockers.add(Point(x, y))
continue
guard = Guard(Point(x, y), Direction(c))
assert guard is not None # Sanity check
return guard, blockers
def loops(guard: Guard, blockers: set[Point], dims: Point) -> int:
max_x, max_y = dims
visited: set[Guard] = set()
while True:
if not (0 <= guard.pos.x < max_x):
break
if not (0 <= guard.pos.y < max_y):
break
if guard in visited:
return True
visited.add(guard)
guard = guard.patrol_step(blockers)
return False
def count_obstructions(guard: Guard, blockers: set[Point], dims: Point) -> int:
res = 0
max_x, max_y = dims
for x, y in itertools.product(range(max_x), range(max_y)):
candidate = Point(x, y)
if candidate in blockers:
continue
if candidate == guard.pos:
continue
if not loops(guard, blockers | {candidate}, dims):
continue
res += 1
return res
lines = input.splitlines()
guard, blockers = parse(lines)
max_x, max_y = len(lines), len(lines[0])
return count_obstructions(guard, blockers, Point(max_x, max_y))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

130
2024/d06/ex2/input Normal file
View file

@ -0,0 +1,130 @@
.........................................#.....#..##.....................#...........................#.....................#....#.
..................#................................#..#.................................#................#........................
.....##.........#..#........#......#............#.....#..................#............................#...#...#..#...#............
#..#...#....#...#.................................#.........................................#...............................#.....
.................##...................................................#.........................#....................#............
.............#.............#...................#...................#..................................#....#..#........#....#.....
..#.........................................................................................##....#.................#.............
...........#.........#.....#..#.................#...........##..........#....#....................................#........#.#....
#...#.........................................#..........................................................#........................
.............................................#................................#...............................##..........#.......
......#....#..............#..........................................#....#........................#...................##....#....
........#.#..............................#..#.............#.......#............................................................#..
....#...............#...#..#......#...........................#........................#...........#...#...................#......
..........................#...........##....#.......................................#..........................#.#................
....................#.........................................................#........#..........................................
..............#.............#.##.............#.........#..........#.......................................#...#.........#..#......
...............................................................#..........#........#.........#.............#.............#........
............#.................#...................#....#......................................................................#...
.......#....##....#......##.........#...........................................#....................................#.........#..
......#...#......................#............................##....##....................#.......................................
...................................##....................#.............................#........................#.................
..........................#.#.........................#..........................................................#................
.............#...#..........................................................#..#.#.#.....#....#.....#...................#........#
....#......#.............#...#......#.........#............##..................#.......................#..........................
.......................#.....#...................................#..........................#.....................................
#.....##....................................#.....#.....................................................#....#....................
............#...#...................................................................#.........#......................#............
................#....................................#.....#.........#.........#..............#...................................
..........................................................................................#.....#.#...#.........#.......#.........
#.............#..............................................#...#.#..#.....................#...#............#.#...#..............
..........................................#..................................................................#...#................
.........#.............................................#................................#.................#.....#................#
........................................................................................#.......#.....#..........#..........#.....
...........................#.......#......#..........#............#...............#........#...#......#...........................
...##...................#.................................#..................................##...................................
........................................................#.#.#.....#............................##................#................
......................................#....................#..................#...#.............................#...........#.....
.............................#...#.................#.............................#..............#.................................
#.....................................................................................................................#..#.....#..
...........................#..............................................#................................#....................#.
......#..................##................#....................#.............................................................#..#
.................#....................................................................................#...........................
....#.#..................................#..#........................##...#.............................#..............#..........
...............................................................................................................#...#.....#........
..#...................#.......................#........................................................................#..........
..#............#......................................###.........#..............................#..........#.................#...
.................................#..........................................................................#............#........
......................#...#...............#..............................#.......#........................#...........#........#..
..#..................#............................................................................#......#........................
..........................................................................#....#........#...................#.............#.......
..............#.........#.#............................................................................................#..........
........................#...#............................................#..............................#.........................
.........................................#...................................................#........................#...........
...#.................................................#..........#.............................#.....#.#.........#.................
............................#...........#...............................................................#........................#
..........................#..#..................#....................................#..................#.......................#.
......#...................#..............................#........#.##..........................................................#.
...........................#.....#.............................................................................#..................
..............#........................................................#.#.......#...#................#....#......................
...#...#..........................................................................................................................
..........##.....................#.#.............#...............................#.........................................#......
.#.#...................#.................................#.................................................#....#.................
........................#..............................................................................................#.......#..
...#....................................................................................................#.....##.....#............
.............#........................#.....................................................#.............#....................#.#
#........................................................................................#.....#..................................
........#..............#...............................#.......#...................................#..........#...................
.....................#.........................#.......#.......#.....#...........................................................#
...............#.....................................................................#..........#.................................
.................................#....#..........#..............................#...........#............................#........
..............#......#.........#...#.............#.......................#....#...................................................
...........................................................^.......................................................#..............
..........#...............................#.........................#.....................................................#.....#.
.##.....................#....................#.....#.......................................................#..##...#..........#...
.......................#...........#..#.#.....................................................#....................#..............
..................................................................#......#.............#..................................#.......
.#............................................#........................#...................................#.........#............
..................................................................................#.##.........................#..................
................#........#...........................................#...................................#........................
...............#........#....#...................#................................#........#.....#..........#.................#...
.....#.............................#..........................................................................................#...
............#..............#.....#........................................#............#............##..........#.................
........................................................................................#..........................#........##....
..#............................#...#.................................#....#..............#........................................
...#.....................#...........................................................................#.....................#......
....#.........................#.............#..................................#.........#..............#.........................
.....................#...................................................................................#..#......#..............
.....#.................................#...............................#.....#..........#.........................................
............#........#..........#....................#....................#..#.#.....................................#............
........................................#......#......................#......................................#..#.......#.........
...#...........#...............#.................#.............................................#..........#...#...................
.......#....##..............................#......#.......................#..................#..........#.................#...#..
.................................##...........................................................#....#..........#.#........#........
..................................#....##..#..#.......#............................#............#.#........................#......
..........................................#.....................................#.............##...#............#.................
....#....................#................................#....#..#.....................#................#...#..#..#..............
.............#...#..............................................................................#.................................
..........#..........................#.......................................#....................#..#.......#.........#.....#....
......................#............#...............#.....#.................#...............................#...#....#.........##..
..........................................................................##.............................#...#..............#.....
#.#...#..................................................#..................................#..#...#..............................
...........................................#....#..............#.........................#........................................
...........#....................#.....................##........................#.....#...................................#....#..
..........#..........#.................................................#...............................................#..........
.....................................................................................#......#.....................#.#.............
........#.#..........................#...............................................................................#............
..............#..#.............#...........#......................#....#..#......#...................#............................
........#.......#.................#........#..........#.....................#.........................................#...........
..........................................................#...................................#.....#.........#......#...#........
..........#.....#.....................#............#............#.#......................#....#.##.............#...........#......
...#.#..#.......#......#........#...........................#....................#.....#.........#...........#.................#..
........#.......................................#............#.............#..................#......#......#...............#.#...
....................#.....#........#.........................#.................................................#................#.
.......#..#...........................................#......#..................#..#......................#..#....................
#.#........#....#...#.............................................#............................#.....................#............
#...................#...........#...................#..#................................................................#.#.......
............#...#.#...........#..#.....................................................................#........................#.
...#..............................................#..............#......#...#..............................................#......
................#...#..#..................................................................................................##...#..
.............................#...#..#........#.........#...#...................#............................................#.....
............#......................#.......................................................#.#....................................
...#......................#......#.#...........................................#.....#....#......................#...#............
.....#..#..........#.............................#..........................................#............#..................#.....
.................#...#.......................#..................................................#....................#............
............#..................................................#.....#..............#.......#.............................#.#....#
........#.............#..#.......................................................................................#.........#......
......#...................#..........................................................#................#................#.........#
..................#...........................#.....#....#.......................................#..#......................#......
....................#....................................#....................#........#............#........#....#...............
.........#..............#....#.............................#..#..........#........#.....................#.#.........#.............

38
2024/d07/ex1/ex1.py Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env python
import operator
import sys
def solve(input: str) -> int:
def parse(input: list[str]) -> list[tuple[int, list[int]]]:
return [
(int(value), [int(n) for n in numbers.split()])
for value, numbers in map(lambda l: l.split(": "), input)
]
def solvable(target: int, numbers: list[int]) -> bool:
def helper(current_value: int, current_index: int) -> bool:
next_index = current_index + 1
if len(numbers) == next_index:
return target == current_value
if current_value > target:
return False
for op in (operator.add, operator.mul):
if helper(op(current_value, numbers[next_index]), next_index):
return True
return False
return helper(numbers[0], 0)
equations = parse(input.splitlines())
return sum(value for value, numbers in equations if solvable(value, numbers))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

850
2024/d07/ex1/input Normal file
View file

@ -0,0 +1,850 @@
187418: 8 1 32 1 3 7 700 2 6 8 9 9
51480079: 88 650 9 8 1
45694842: 2 9 227 6 1 5 4 382 1 5 2
324153: 4 6 165 26 2 8 9 3 50 9
28501243947: 66 18 84 68 6 926 78 7
20763: 8 9 7 123 308 2 2 709
1275: 40 5 6 75 1
769249: 1 47 4 4 3 9 49
464700680640: 94 7 26 7 917 9 6 5 392
501133472: 3 901 3 9 3 979 557 15
1408080699: 2 93 35 12 4 5 87 48 64
257184: 4 68 8 6 116 72
381878965: 727 5 1 56 28 6 67
625: 79 5 41 488 13
1382535550: 8 91 1 5 66 931 4 470
543135657: 7 649 5 9 7 71 979 7
69632: 7 51 8 2 963 8 6 3 701 9
4087: 1 3 576 2 7 7 10 6 9 592
6351: 21 298 4 2 84 3
15702: 7 1 419 36 366
89661885: 8 112 1 585 25 8 84
266450902950: 65 7 59 2 57 968 9 9 71
194394: 194 366 28
972: 6 29 546 1 390
1833720: 1 6 4 6 4 9 6 4 4 2 777 5
7263349: 9 84 780 93 4 9
94534: 781 12 8 9 797
258695989: 582 14 4 246 129 421
1371: 187 9 440 9 726
1403130963: 45 547 2 6 4 8 70 22 2
5172: 1 28 3 88 3 4 94 642 6
240988525: 5 865 441 5 21 382 3 2
212541850: 6 4 84 927 5 3 813 73
9096239: 890 67 4 1 9 95 84
482781: 635 1 1 95 8 5 8 5 7 58 7
4540643307: 5 4 5 898 5 5 92 9 9 8 3 6
46738900180: 976 706 17 58 57 4 70
259616: 312 207 6 314 4
174270594: 544 745 4 43 21 1
23194043: 773 3 3 9 1 43
2838182357: 28 381 81 1 1 357
557952: 9 62 80 9 62 6 36 7 3 7 8
82653627132: 8 507 7 6 565 6 5 6 7 6 3
917397714: 9 173 97 71 4
63564: 846 1 75 48 65 1
16152750: 714 7 795 99 26 5 1 99
64418: 6 86 4 4 92 7 18
96932098: 5 46 19 320 98
412070765: 318 3 4 69 5 313 3 2
1986: 990 3 2
10295: 6 3 940 826 687 322
143356: 3 98 4 9 7 6
264829968: 293 12 106 7 543 9 3 3
73800979: 10 5 3 1 46 8 9 28 4 6 9 8
2804772: 6 600 892 39 9 8 8 2 4 6
300031: 8 3 55 545 31
20008369743: 8 330 6 82 4 2 5 6 4 7 5 6
13396057557: 8 76 91 17 220 4 4 7 7
116812844776: 96 59 477 3 7 982 85
1197286087823: 9 829 9 3 3 2 87 3 4 2 9 7
288934843: 4 13 212 33 43
12097735: 1 120 884 93 35
2323: 4 7 129 250 654
4452928: 18 97 1 472 24 82
3693500: 9 825 56 494 4 89
230650225261: 863 1 96 8 4 87 3 5 8 5 9
6471: 76 73 898 8 17
1137: 5 2 47 297 786
368741: 8 458 113 2 1 3 7 1 90 2
347319: 447 9 69 816 259
6153742: 8 4 2 9 7 5 1 344 7 1 71 2
2300212040: 6 7 7 7 55 15 727 15 56
217743931: 24 3 234 718 18 379
1143073502: 216 84 7 167 9
1447474: 516 7 4 9 165 6 3 7 839
24175: 481 3 8 49 70
1198210: 69 633 7 2 845
3200: 8 50 8
7529214347: 376 46 5 34 9 40 387
23264072: 279 730 556 4 83
58517605: 959 305 61
3694797: 647 68 9 47 51
98762746: 7 980 6 27 46
675: 3 6 4 7 15 30
3302: 7 94 25 93 47 1 630 6
50372628: 7 943 16 9 92 2 9 9 5 4 4
546760284: 60 9 134 67 84
48336753: 69 24 90 33 175 3
327848: 6 607 90 8 60
1099845: 461 9 60 39 45
2913111: 5 726 190 8 761
215712: 1 9 9 8 7 7 3 8 7 8 225 7
187980: 2 9 32 2 23 78 2
28105: 1 373 3 74 207
13669642: 17 8 6 964 2
7519900: 695 56 98 99 1
52373979: 62 253 34 7 9 543
244520658: 8 39 1 922 3 7 9 8 5 2 4 4
761166846259: 702 80 5 73 375 271 9
1710191: 6 84 90 95 27 164
108219300: 6 669 5 3 4 8 96 3 7 2 7 5
83418128640: 752 9 3 2 3 6 8 99 9 4 4 9
31892804: 39 3 73 81 67 4
42680000: 4 268 4 50 50
23479827: 4 984 35 679 7
210060261: 206 3 21 84 73 7 289 1
3177: 47 3 71 5 457
902503660: 6 44 763 56 93 6 254 7
30198724521: 7 8 9 2 9 47 2 379 45 2 2
2163: 746 2 19 85 518 49
954304: 2 1 2 3 2 40 3 7 950 52 8
5835456294: 30 7 48 396 292 2
43320718: 456 95 2 8 4 434
3308760: 5 302 5 42 52
5796: 9 92 7
25910231829: 3 67 706 3 1 832
878427678805: 92 26 1 1 81 50 952 6
1473321: 71 2 635 30 5 2 6 4 1
8400848504: 9 6 96 56 84 8 2 3 100 4
49322159387: 13 2 8 92 7 3 5 8 6 7 8 7
684519833: 7 61 4 519 836
191600640: 8 8 540 528 42
311237: 631 9 486 9 8 15 165
951160: 9 3 983 5 9 1 77 8 7 5 2 5
59041208704: 98 4 6 11 987 99 9 6 8
354018: 72 3 1 59 124 118 3 7
35886127: 3 87 3 92 2 1 5 4 603 9
701625: 77 9 8 62 3
136802924: 958 425 7 7 2 3 2 47 1 4
71282596: 6 54 22 259 6
245520: 385 71 4 5 528
3517169040: 8 5 5 8 125 7 530 7 9 76
7792441765301: 778 7 2 7 9 2 365 9 4 14
607622809527: 5 6 48 8 36 730 9 52 5 2
842: 9 22 5 2 7 9 4 43 3 8 1 30
1173375: 7 4 2 3 225 7
3650074: 2 84 12 328 977
3812606: 9 8 8 23 28 151 2 7 8 86
17360: 3 820 1 7 3 18 3 4 1 7 1 2
12405: 16 1 9 86 20 1
66919866641: 211 8 6 44 5 9 8 7 9 1 4 1
8013364: 58 157 88 8 4
185974: 7 48 4 54 8 59 1 3
565292571: 896 29 33 123 590
471460: 556 24 7 116 500
9804900: 24 54 270 87 70 46 7
425: 2 9 6 25
512403750: 9 91 84 6 625
7303840435: 730 383 36 68 35
44385941654: 45 63 8 215 364 2 1 50
17793072: 1 86 3 2 406 28 517 9 4
68567808019: 6 2 192 8 370 19 16 3
16224908: 4 970 9 7 596
9437: 5 938 7
386334417: 696 6 94 59 3 2 3 4
4935770786: 4 7 52 8 9 8 1 49 5 1 7 86
926168190738: 9 260 7 7 2 26 1 90 738
1086806: 7 5 51 5 656 80 6
2131: 274 7 96 46 71
3560: 20 70 840 60 591
545: 4 11 9 379 79 1 63
4101: 3 1 6 5 352 574 8 2 2 3 2
40731: 93 86 503 991 690 4 3
16841473152: 94 52 4 96 763 47
404950: 71 83 419 77 623
3500596447460: 1 323 6 7 7 58 2 9 7 46 2
199362631126: 7 7 56 28 4 1 26 31 126
1298121: 6 8 781 3 7 5 1 5 309 7 5
33750: 30 3 34 90 57 33 3
1048524: 29 69 524
28241257580297: 713 5 978 5 81 802 97
688232: 60 2 8 2 598 9 5 4 79 9
4970: 9 1 8 1 7 2 60 8 5 460 3 7
38071: 791 368 7 79 30 721
20128402: 2 48 2 6 482 80 9 59 23
97596756600: 435 466 95 724 7
6525364319935: 3 684 636 863 987 5
437787903: 8 114 4 4 91 9 9 3 8 9 1 3
1457: 3 3 44 4 1
293090: 5 241 283 6 53
619297: 52 9 92 9 4
962292: 765 10 95 31 478 4
648387: 36 28 83 2 3 3 34
466433: 424 110 3 3 1
6967: 4 102 1 8 6 9 8
3396540: 242 61 140
3561767: 12 400 7 99 726 11
979543: 1 8 7 250 87 260 3 6 2 5
27988800000: 5 25 700 4 952 4 21
133389: 241 6 54 3 6
9533672: 89 631 25 479 69 514
24714: 1 86 26 507 3 9
9455893049: 28 5 7 7 888 6 3 4 2 4 1 9
1224: 4 8 36 485 671
2058747: 4 7 378 1 9 524 2 4 8 1 1
8122: 5 47 60 205 2
23657723657: 6 32 183 51 94 23 63 8
1238563682: 618 2 4 5 32 6 5 9 4 6 82
7039053: 9 367 213 366 3
144999092: 8 8 31 41 2 9 96 87 2 9 9
3416010: 400 854 2 2 5
307549178: 782 6 9 5 5 963 3 3 683
344179424889: 46 2 5 737 4 2 48 8 8 1
55345590: 366 120 7 1 20 710 9
38358188702684: 9 5 89 8 4 3 7 740 537 5
7063729304401: 569 183 973 77 881
12816555: 762 92 2 3 3 10 1 410 5
9621: 94 2 21
70948948: 6 4 1 9 8 178 1 4 6 264 2
411358: 423 97 791 36 2
3369019540: 56 617 2 975 7 38 41
1504080630: 39 5 62 1 207 601
779137845564: 37 101 8 21 3 1 5 564
5800032: 309 677 4 6 98
4168816845: 6 78 89 36 160 8 4 5
2911: 4 5 56 2 255 31 385
1142856906: 8 1 5 4 3 1 6 8 55 1 900 6
5823576: 56 604 34 86 2
6608969236: 5 5 6 2 86 3 3 1 3 9 236
1328554651: 4 1 324 74 80 648
4947149: 9 3 4 102 43 9 71 9 5 6 3
239760188: 6 2 2 2 40 6 6 92 3 4 9 92
1891987951: 4 2 82 465 5 33 968 7
933744: 42 445 9 3 71 158 7
15774: 556 3 578 7 5 44 3
2945: 2 9 716 4 28 9
392802448878: 6 98 5 5 4 4 1 70 4 1 93 6
5644947: 3 26 1 2 80 40 9 112 35
1490: 1 7 638 69 2 5 41 8 5 1 1
210990: 8 63 99 4 30
121980885: 3 27 1 271 5 9 3 9 1 9 5 3
7300117: 79 8 15 13 769
108410439: 542 2 10 1 350 89
5184867: 948 53 94 103 53
1127: 6 74 638 2 399 8
455827: 91 5 827
61760955: 9 49 4 4 2 71 80 5 433
191368: 7 5 2 8 5 7 791 7 3 4 2 2
567544412088: 963 9 736 76 39 8 88
12146752: 709 2 3 8 76 1 28 5 9 7 6
885889: 8 42 9 347 3
1106: 43 67 6
7202952: 405 8 5 355 2
20562: 284 610 23 1
191497654329: 824 50 83 9 1 7 28 2 9
2808193: 767 4 1 61 5 1 3 52 3
133955535: 3 8 2 601 818 1 2 7 645
6752263840: 5 4 6 4 8 5 314 7 8 5 7 4
313500: 469 4 56 11 6
1110: 14 1 74
15488: 95 4 1 26 2 6 7 3 5
35418: 11 723 47 5 915
391535: 7 403 953 1 486 319
1388084: 724 71 27 92 65 7 3 9 1
44009264785064: 55 137 833 73 813 3 8
18867200: 3 4 99 7 6 8 383 51 8 16
9612421: 6 2 34 6 553 7 362 959
8117920: 267 4 11 691 52
294154650: 29 409 6 46 49
189788268: 3 18 4 6 65 6 38 1 6 5 6 3
1676757: 75 4 69 81 51 6
605176: 7 34 61 506 4
539081638393: 33 146 33 974 506
419239: 610 9 245 8 73
21401: 7 5 57 5 26
240460: 9 74 2 15 4 6 29 221 55
153678511980: 7 204 810 542 237 7
16223812320: 7 7 6 279 7 597 57 80
175564935: 2 84 8 14 11 38 9 5 403
6048: 5 2 7 29 91 4
675100: 61 8 11 316 628
1155949124: 477 411 8 76 737
94353: 31 58 52 857
1128071: 393 5 8 6 6 59 333 248
4621214: 2 639 901 1 79 31 2 4 6
26092259600: 53 195 2 981 280 50
182162: 11 253 91 7 1 6 99 5 2
4452230: 138 6 7 8 9 12 1 8 29 2 7
314085244: 9 88 419 166 946
2291933389799: 5 472 3 7 47 72 3 831 2
1637032: 433 52 912 646 1 68
8505: 3 6 929 96 31 17
1051: 4 5 75 352 24
53861: 91 51 712 33 1
12176325: 6 3 773 9 5 35
53550: 414 9 99 7 2
76978: 2 84 50 8 4 44 66
166020482: 73 1 8 684 41 2
2994024: 19 816 8 3 56 5 8
531: 9 2 39 7 89 6
534784472: 2 3 1 9 95 9 60 58 3 4 72
584932732319: 29 31 89 6 5 65 1 72 19
4514: 9 35 11 58 45
49509809: 76 41 91 983 2 87 21 2
1404717811: 8 8 16 4 2 756 717 811
2687382: 3 10 4 4 90 2 91 6 863
339914973856: 713 68 41 37 26 7 435
296058: 3 4 3 1 5 33 8 2 8 38 1 7
67488804: 89 745 8 6 94
1252695: 9 92 6 9 5 8 8 1 2 4 63 3
27424: 8 47 60 8 925 1 99
1943363853992: 1 200 2 46 8 5 159 88
6294075553: 2 892 5 1 34 5 191 5 7 3
9476: 1 2 37 338 23
5001673: 4 2 2 3 5 9 8 2 7 991 4 92
19: 10 1 1 4 5
465093: 75 2 74 94 7 9 9 2 4 8 5 9
1369373: 898 471 3 73 1
1525: 23 2 61
41257: 4 1 1 2 57
6264: 30 96 7 7 6 84
321300: 3 435 1 7 31 6 1 5 7
1368: 98 57 2 6 4 9 971 68
784450040: 9 76 199 62 2 374
6835209: 9 1 436 905 2 8 6 5 206
362124546: 88 29 796 7 8 9 2 2 9 2 3
126885: 5 9 63 72 7 19 3
5676536: 3 3 945 44 664
29555174: 875 281 36 5 6 710 4
1809145007: 289 626 497 3 7
64764: 7 8 2 3 2 7 7 5 5 676 86 6
327240: 12 594 3 9 1 20
3945066: 9 73 5 6 65
86424: 4 5 567 848 2 731 24
52286469: 3 1 489 9 82 4 4 9 637 8
4251579: 457 7 556 2 64 65 59
229770: 65 60 874 46 5
2700: 1 7 96 3 3
198787972: 4 3 5 6 68 5 2 45 4 2 5 2
10115: 77 5 231 5 5
4303635: 1 14 782 9 69 595
2678: 20 9 7 81 1
145017912744: 99 4 783 107 9 47 93 9
13034369: 5 7 43 6 5 3 375 49 4 73
989: 84 92 8 5 687 94 7 8 4
53545060811: 80 4 85 84 8 99 7 4
230081372: 8 2 49 651 7 6 4 1 4 9 7 2
58091386: 56 5 1 7 3 222 4 8 3 158
48204: 3 461 91 333 47 26
58448887252: 7 175 22 66 486 52
197235: 410 9 48
22386781689439: 956 7 65 6 2 8 6 943 9
119340: 9 5 52 51
563562323: 8 5 7 903 79 5 79 14 9
52547762: 724 8 9 2 6 7 29 4 2 6 6 8
227057993908: 99 6 26 82 199 192 52
2700292479: 1 925 1 9 50 3 84 383 3
119784: 7 3 2 79 7 6 6 6 20 53 1 5
217977480: 91 3 6 8 2 980 81
9559: 828 56 65 3 66
134739247559: 10 8 4 6 4 9 1 3 9 675 59
1284754815: 594 56 590 8 5 2 9 335
6090685515: 2 60 2 758 9 8 4 5 87 9 5
1352574963: 1 69 69 17 7 97 1 843 9
2936812726: 42 4 6 174 317 2 716 7
21: 2 7 4 2 6
166409: 6 2 268 24 9
322: 122 9 4 143 44
4538: 450 1 33 4
1862003: 2 9 302 215 610 449
86940: 85 9 10 3 8
38072: 6 613 4 15 4 692
99725486: 6 12 6 6 6 6 65 25 478 8
13750: 53 2 439 27 412
7038816: 57 6 65 7 80 9 3 454 8
2855136: 6 620 8 570 543 33
146592: 84 7 160 2 67 924
569936: 7 5 621 4 4
740: 20 53 1 7 659
70911: 5 2 8 66 2 9 1 4 8 1 4 511
64728: 3 66 6 93
265592: 440 6 7 2 545 6 967 2
1497366612: 2 53 9 78 513 63 7 404
61277: 150 5 1 2 9 5 2 48 8 1 7 5
3346539: 8 82 5 42 7 3 59
3365893552180: 12 995 7 28 7 37 180
1009: 6 15 53 50 885
127008: 83 7 894 37 84
562032713741: 3 869 174 21 199 59
987527: 34 61 3 9 385
19712100: 735 4 530 84 25
26901: 303 117 1 4 3 63
15116264: 9 8 75 48 25 2 457 7 68
204191226: 3 89 1 2 4 2 8 8 3 9 327 6
5198984: 8 3 8 6 9 72 994 4 526 7
11382: 759 1 164 7 868 6 594
504391: 852 73 848 8 39
530085603: 30 558 984 5 9 2 5
624: 9 2 136 475 2
3629563236: 359 2 247 54 379
395873445: 9 227 47 8 9 3 2 2 5 687
552102: 5 77 20 567 4 18 8 551
76000078085: 47 2 33 7 7 2 156 5 85
132685: 9 46 2 386 7 96 7 6 4 9
10372: 3 5 1 9 47 189 2 2
20543565: 978 2 65 3 7
1472385558: 5 7 6 340 794 7
14144491524: 44 2 64 983 5 24
2692998: 48 1 19 63 638
1252924947: 9 5 869 534 7 1 6 697
4716: 12 98 1 3 4
2496938: 3 41 7 725 9 4 2
1235912: 7 3 99 4 217 49 92 76
2481026: 30 810 510 18 8
287777439: 74 83 411 2 3 1 57
6343360: 2 6 7 72 76 688
77516: 1 1 75 479 37
3030894: 8 7 6 1 2 4 71 29 4 2 6 40
5048088466: 80 631 8 765 7 71 6 30
359727: 897 80 5 923 4
74387040000: 50 52 80 5 13 393 7 2
220838337605: 65 48 56 44 760 1 76 5
25607876: 595 532 43
33263: 524 4 63
2233205: 956 6 4 389 348
49713: 115 54 9 4 4 86 2 5 864
6057554870011: 931 7 9 189 8 55 903 1
933697: 3 833 1 93 913 4 3 42
10924942: 780 353 14
284929536: 3 4 4 3 98 94 861 92 6
6695: 7 914 191 1 7 3 86 9
6245883: 9 989 85 62 6
30: 7 3 9
10155582722: 755 6 35 8 3 2 4 2 30 8 4
10213731200: 5 4 576 94 262 88 80
234673837: 41 81 31 4 7 5 831 6
324941866: 7 8 7 7 365 27 2 6 1 81
145341868: 995 4 961 6 38
2637745: 8 2 828 7 199
17982455851: 64 2 4 2 9 222 5 7 4 6 1
9608793: 574 956 628 4 8 381
719687: 71 9 6 80 7
48985815113: 85 571 450 8 151 11
4889892: 8 3 15 9 3 428 1 8 7 4 1 7
1505669220: 88 648 947 77 8 9 6 30
2127186: 818 91 468 3 9 5 8 58
4029145071: 15 562 37 64 45 3 287
79038: 48 661 1 2 707 2 981 9
50824: 50 7 1 2 4
3007: 79 29 5 6 2 9 8 778 72 7
97461: 25 779 5 81 5
72103770: 6 1 827 5 378 66 7 8 9 9
10958: 307 747 41 7 1
20287324856: 7 5 97 1 79 3 6 92 1 9 5 4
169639: 2 68 2 1 83 8 95 5 154
4596255180: 1 67 6 67 55 1 8 3
95786: 425 259 28 5 26
42269125: 80 6 331 22 4
293888: 4 2 4 2 821 54 425 4 7 8
5203652120: 2 260 36 52 120
214028823995: 9 7 889 2 670 7 1 9 9 5
46785931: 9 5 104 6 7 59 8 5 32 8 3
1249: 3 183 78 584 38
39642467328: 73 27 10 3 3 984 667
33264275: 22 782 2 3 5 73
138424899: 9 68 143 89 9
70342494: 195 958 61 9 447 47
194789: 83 3 782 50 21
183549: 6 40 399 7 2
68052: 6 51 553 9 649 5 2 9 53
14620480: 6 7 1 905 1 6 8 8 369 8 8
3453258: 89 388 58
17724262883: 35 92 24 1 8 2 8 688 1
10296335: 7 22 23 9 62 57
930: 913 11 6
1528389206: 198 7 907 4 822 218
684211: 6 9 76 7 596 6 570 23
3953055575502: 7 6 7 10 4 7 3 860 4 476
235864: 2 35 864
342199842: 46 6 70 4 41 37 6 6 2 3
38875005: 620 627 6 94 5
47902: 717 6 2 40 13 432 8 4
3437568326: 2 4 8 2 9 373 10 4 8 6
71911489: 7 5 38 258 633 233
116689560: 681 2 5 571 6
13336633: 66 535 516 3 33 43 97
2561353: 1 5 2 472 41
7100813: 998 73 78 85 83
9016487158: 1 915 3 3 9 3 8 94 49 5 8
231873894863: 2 98 42 2 777 863
17802929988398: 456 79 167 49 972 49
205498: 8 9 2 3 56 48 4 3 3 3 622
53767644: 537 673 5 4 290
64823081: 4 8 1 546 742 390 5 4 7
224054: 257 30 7 9 29
4381459: 84 3 629 5 9
156092264318: 26 60 92 264 319
4835710: 112 7 5 2 9 521 1 9 6 5 7
2097368646: 9 961 2 9 299 4 9 18 5 6
5199015150: 4 1 529 40 234 15 7 6 5
2263449: 7 236 8 2 9 8 8 3 245 9
17923542: 2 12 2 91 92 702 44 2
1822830370: 4 619 7 451 14 8 394 8
787528: 423 7 8 9 44 3 1 1 667 2
2861205060: 1 5 86 5 18 7 917 76 51
2139301: 80 347 23 77 10
78: 31 33 14
1938: 1 1 1 68 101 7 2 9 6
439607545: 6 29 378 3 1 904 1 481
21129: 704 3 9
1581: 848 1 21 649 1 62
2662: 68 3 62 2
3026494946287: 8 57 4 1 57 8 189 9 86
146835081730: 339 7 1 96 2 20 9 2 6 9 9
54568804: 1 65 99 848 4
344196191: 65 802 3 62 78 22 75
6009142314: 4 852 1 77 5 533 7 654
2293044: 902 37 6 407 6
66217250: 8 327 12 68 256 9 242
7449: 10 105 7 23 76
713: 73 50 586 1 3
8396761070: 691 9 821 3 5 9 9 5 8 56
84093834: 76 226 4 612 59 3 3 2 8
8021: 24 3 293 87 23
4588059: 8 55 5 8 547 1 6 4 2 27 3
896: 3 6 96 7 8
203856: 117 9 49 83 2 2 6
1755: 5 5 6 56 19
94983133313: 91 4 9 6 9 2 71 611 3
36501584: 421 59 200 84 76
2739260160: 83 8 78 3 60 67 32
11431577: 4 85 4 54 86 8 74 57
3904975: 762 183 28 451 36
1061781890400: 1 90 712 99 797 210
104260: 218 2 8 71 451 26
12831: 231 3 479 96 793 8 8 7
1867: 249 621 9 9 24 955
2736990: 52 56 9 19 3 930
7372456: 13 3 9 5 55 158 676 41
13995957291847: 87 86 655 4 838 852 7
262752: 7 755 9 180 6 8
116756: 60 85 8 86 665 5
21520534503978: 2 25 8 1 883 953 4 978
20702160: 65 72 7 8 45
47451357: 15 6 1 3 4 4 603 108 9 3
90184: 892 1 6 91 4
522977087: 6 8 8 35 75 5 5 9 76 6 5 3
19773: 938 46 2 9 3
591448: 96 8 611
151932: 9 6 8 7 300 6 997 7 3 2 6
677133: 55 94 96 7 17 8 15
62605459434: 236 75 5 33 5 4 2 6 609
1134716637: 5 134 4 814 576 8 51
203685: 138 7 885 22 3 8 3 5 5
411259430463: 7 60 4 988 2 7 384 7 6 3
69479410: 6 28 93 7 8 23 711 631
36480513: 747 4 5 10 488 73
6529930114: 98 37 398 638 110 1
3158302: 8 32 7 4 688 78 3 1
1329: 956 213 6 95 59
103528339432: 4 38 9 5 1 5 6 9 887 536
26058526: 86 1 69 6 3 7 155 75 3
16637174616501: 60 5 9 577 2 88 3 4 3 52
496403648: 24 10 1 419 8 617 8
70983429060: 234 1 5 20 1 6 8 5 8 5 60
18430386766: 7 5 42 7 776 198 55 34
4336513875: 7 869 534 1 3 15 89
146733: 2 179 8 8 6 300 99 15
719431: 1 418 7 4 4 7 4 5 8 35 6
123489453: 1 235 650 2 9 89 47 87
1817054297589: 6 40 395 5 4 297 592
28112657546: 48 73 71 58 113 6
3698184: 79 871 389 268 4
33904566: 8 359 3 95 2 97 9 4 3 6
3749036750: 37 4 903 6 750
9653520: 2 28 2 5 57 584
64502825: 7 9 20 171 8 60 5 65 5
258198671: 2 6 840 55 551 7 1
7876133: 9 9 32 46 963 718
795924: 8 31 3 51 873 48
25961153: 58 89 55 630 17 9 2 6 5
7689010: 83 6 602 699 9
37694322: 5 57 3 329 134 775 17
370720500: 7 6 371 8 767 1 14 606
396636777: 67 6 965 6 4 7 3 29 7
683362696: 68 33 62 6 96
176659289957: 8 2 3 57 824 8 899 57
942096: 6 830 74 2 5 4 2 1 93 6
139897: 50 6 4 5 466 3 86 8
25310524: 842 9 835 4 4
284646313: 7 2 858 677 4 623 5 4 7
182325: 361 418 3 75 7 6 6 75
55: 3 2 9 35 5
2383002: 384 31 62 73 207
5783478945: 61 2 9 15 7 14 8 351
6822681600: 8 840 490 56 37
4081902: 9 88 7 5 2 10 7 506
499758: 1 27 41 426 326
129: 53 7 61 3 5
4093163: 940 75 4 8 3 8 7 5 6 317
1735787709: 4 7 39 10 8 4 8 5 35 5 1 9
1466379: 6 8 8 1 4 3 6 5 625 6 25 9
1132930: 2 44 81 8 2 3 19 2 6 6 2 8
813082430: 2 9 2 27 72 5 616 486 5
39761608992: 8 3 1 5 9 4 7 9 942 476 4
183663: 3 17 407 9
290472: 52 7 798
26524378336980: 2 7 808 977 3 92 8 980
130466560295040: 778 533 9 98 816 190
4905495936: 4 11 17 93 808 99 8
593640: 492 5 5 1 2 3 39 9 6 30
6233: 9 12 68 7 6 2 1 5 3 16 41
36038: 9 476 863 7 9
128815: 1 2 88 15
1864323072: 202 292 9 128 8
9950315: 52 4 938 51 3 8
501726: 5 476 303 187 5
92280: 922 27 2 9 42
76472: 661 208 88
61014: 1 97 1 629 1
17078477400: 1 44 4 5 128 308 2 5 3 8
376022848: 21 760 1 4 224 6 56 8
6639080646: 945 3 2 7 7 99 881 643
116944: 4 3 7 38 81 6 3 8 1 441 7
230277087093: 319 430 9 801 93
1043119420033: 4 31 6 1 4 341 2 350 35
17346278: 6 45 69 9 157 545 18
2901672: 2 287 1 16 72
117015525: 5 1 8 594 4 9 97 6 3 3 55
48944038: 539 9 71 608 5 703 26
51469483: 113 965 472 217 26
35344593648: 7 54 7 822 238 549 78
9385011: 938 493 5 9 22
8666140861: 5 6 6 1 4 44 60 6 6 1 8 5
5300472946: 692 5 31 762 948
25608: 87 4 3 24 552
308240474597: 770 6 5 8 429 45 5 9 2 5
16439885: 2 8 822 3 50 651 5 77
544500: 8 22 253 37 26 4 2
30379565: 3 903 1 5 323 1 9 565
41656: 144 47 794 31 41
24807: 48 7 63 7 552
3485: 499 4 74 6 23
839060: 1 27 1 35 5 7 9 3 7 6 1 25
23088: 9 9 33 42 148
9154663: 4 817 311 8 7 91 6 63 1
90682288496: 7 577 8 5 20 1 6 748 6
43937079: 5 770 7 89 91 4
29472: 614 6 8
11561778226: 2 6 6 4 34 9 9 963 2 2 2 6
117144416: 317 8 8 6 6 8 39 8 1 956
2462640: 3 8 15 2 9 7 5 8 4 7 930 8
6991816: 6 2 867 3 4 5 7 8 1 35 4 9
10813: 12 76 14 37 576
5764467: 90 94 9 8 5 2 68 92 9 4 2
20995047250: 5 814 4 6 7 9 4 4 7 9 2 50
340676: 492 32 5 92 7
460049: 9 8 839 39 5 69 4 8 2 7 8
39360102: 46 101 5 7 845 2
632489040: 632 48 896 1 73 6
4515: 73 1 4 5 15
22440: 4 8 21 663 561
34573: 26 2 65 77 3
1205424: 3 48 930 2 4 1 4 2 4 1 9
2288024: 4 6 411 9 92 7 5 56 6 8
7166740: 5 62 4 980 103
43925184: 68 7 767 23 8 8 1 2 6 2 8
73957520: 8 4 6 1 3 4 440 67 560
4497072: 449 6 858 3 211
379852098: 65 68 68 3 29 7 9 6 1 2 6
7039622942269: 7 491 357 4 6 9 683 84
59297832: 83 895 586 9 11 8
3222143: 98 427 77 4 1
2706396: 2 7 4 9 9 8 5 5 8 3 85 609
54899: 9 40 5 8 99
15470567600: 423 6 737 988 9 1 6 4 4
414459045: 640 8 468 369 3 13 35
28680: 286 73 7
148225337: 5 63 394 6 5 4 4 922 7
1548: 8 9 20 83 25
52488: 55 4 5 8 81
309758831546: 7 4 3 4 39 7 4 3 145 1 8 8
45710059: 2 77 5 38 5 17 26 89 7 8
110968: 3 8 9 4 5 435 3 4 32 1 1 5
296175877: 2 3 124 9 3 2 46 71 6 55
183182295: 3 6 31 82 295
18032285875: 733 246 26 459 875
2252773168103: 6 690 743 91 370 3
208683: 90 1 303 531
5905: 5 83 9 4 59 3
2547957588: 2 135 6 7 9 4 5 57 5 87
864108: 10 525 233 204 889
2632797169: 9 5 78 52 578 3 5 71 2 2
3861135: 17 94 6 330 91 42
279877248: 98 69 966 503 72
4321455138000: 567 4 611 20 75 693 3
109506168: 771 73 43 3 9 5 8 896 9
131686680949: 2 344 6 55 3 632 1 950
11285568: 42 3 622 48 3
7429: 6 7 35 15 5 4
1344632850: 6 81 825 986 19
1349: 12 9 23 866
135629: 52 4 5 3 5 6 17 4 6 39 65
109541641: 772 1 665 3 705 71
36454: 32 11 847 33
18256000: 79 4 792 326 64
634608: 9 784 13 13 8
2149222: 391 7 54 21 1
1020512181: 8 89 9 3 3 4 40 80 1 8 9 3
778156485: 6 21 5 4 2 7 23 663 9 5 3
4983272739052: 280 5 530 11 920 4 73
4161: 72 44 925 60 8
2507022432: 4 489 6 9 8 2 8 8 90 2 8 2
650605: 9 12 629 60 5
2092992: 85 1 3 991 24
26902: 9 2 3 74 6 5 42 9 8 123 2
15599: 4 151 98 1
41225189: 8 16 1 91 44 429 5
1473989040: 7 228 6 1 30 32 920
61866: 20 28 934 3 21
570190125: 471 99 1 90 128
16235927: 6 26 35 731 992 855
21528: 565 2 1 2 1 8 1 9 6 66 6
43993993848: 6 2 8 95 805 62 28 5 1
26706275149: 4 60 451 2 58 6 5 42 8
1011: 52 7 635 6 6
299093: 9 8 2 4 7 8 4 9 4 5 5 867
833382: 6 3 6 23 671
14505768: 2 97 268 3 93
4923890: 93 61 526 4
48105: 751 4 16 3 38
1414794: 70 38 16 61 251 11 6 3
38616996: 4 79 68 791 2 3 6 999
1904796000: 39 8 606 4 9 546 999
147334: 9 732 65 44 22
34232: 7 31 598 42 2
12270967818: 27 722 9 885 5 2 3 8 8
9264135: 3 451 441 25 6 4 13 5
45507450163: 45 496 11 450 163
91440: 4 41 6 916 5 48
88344832: 882 4 8 38 8 41
287671639: 985 29 202 1 1 56 7 2 4
507668: 911 8 804 90 4 70 20 8
394114: 19 837 51 434 7 469
77382: 5 9 5 55 29 4 9 3 3 7 30 8
9957630062: 56 9 310 73 2 291 7 3 2
10296: 7 98 3 1 6 84 3 735 9
295260: 7 2 18 9 84 1 39 3 19 6 7
4701: 20 57 34 2 2 2 1
3848560: 28 4 8 7 72 8 359 20 4
16949608: 7 1 3 413 8 6 3 42 8 2 5 8
31453576: 53 1 2 33 580 21 77 8
314611: 33 9 24 86 773
15245: 6 2 1 2 5 5 4 6 89 9 853 5
7265: 1 7 7 6 8 1 7 669 3 4 6 63
548073: 9 88 282 20 669 324
62260835: 2 971 916 9 35
835164: 30 4 3 513 44
19800544: 440 45 1 136 407
33392435588: 73 829 54 739 9 746
9119277: 4 1 433 39 2 6 1 1 2 5 9
2473338468: 2 4 24 446 155 3 3
3391904: 5 42 291 248 8
4854: 89 310 738 77 4
7990517: 1 659 3 2 747 8 6 61 5
27168: 195 80 8 6 16
356592: 9 7 6 9 7 152 11 45 57
803: 3 2 792 3 2
7324966325691: 7 8 327 4 12 3 814 2 3 4
4348464: 87 238 35 34 6
78: 1 31 1 46
2333: 395 903 8 93 9 2 923
17413920: 1 730 95 8 2 580 2 9
121371: 6 2 1 1 7 693 57 1 8 35 3
52915920: 201 2 263 2 54 66
4205: 1 6 82 9 6 722 4 3 5 3 5
102938: 2 8 7 70 62 1 157 73 8
64212990: 15 423 269 5 109
2891: 2 24 4 15 11
7707154: 411 954 4 1 7 1 3 6 7 94
83830: 1 40 2 3 27 7 24 2 6 62
342729: 7 83 272 14 9
55247775: 541 851 8 16 41 15
4259: 5 73 7 5 4 5
13394887: 4 7 2 2 6 5 58 783 7 6 2 7
904: 4 2 727 80 91
7641038: 485 1 8 860 516 6 18 2
2359540874: 2 546 3 8 6 36 71
833: 42 62 1 14 7
1581: 4 60 857 1 1 7 477
225893352782: 225 893 35 278 2
19077: 40 9 28 247 58
1026671144: 5 46 3 74 8 359 8 7 69 3
398072: 44 3 635 56 3
15469480: 409 1 539 35 90 2
1809270: 8 331 48 85 55 45
2627552: 4 7 26 3 6 25 2 2 8 7 5 2
6983: 1 950 1 70 6 9 4 844 1
864439333: 8 98 80 439 330
7739: 857 9 14 4 8
527424: 5 19 6 32 67
178358491551: 242 66 42 758 968 3 1
23466: 4 60 4 1 2 1 166 8 5 379
8865: 1 788 193 3 9 3
25531136601: 2 55 311 36 601
1435774: 8 84 27 578 18 4
6228: 4 878 7 7 5
1642: 3 8 3 4 2
38584000: 8 6 4 2 41 6 95 2 4 8 875
24723940: 209 31 477 9 8 4
2116117: 697 3 2 6 7 23 425 36 6
3124451126: 26 3 11 12 78 4 6
86185: 879 9 4 4 6 66 8 9 1 853
35383157110: 2 1 792 31 43 730 7
1658134437620: 7 3 5 233 465 44 2 485
43437081675: 5 713 216 2 176 77
800998632: 7 3 214 4 54 246 378
5200: 8 9 463 9 8 377
33760: 67 2 3 2 5
1120091: 63 5 55 37 344 8 11 16
140: 1 47 92
5721882: 42 49 29 2 469 82
34206: 37 6 77 9 2
121: 29 3 76 9 4
4941531369: 91 54 22 5 53 137 1
3463558642: 28 13 87 971 1 63 8 4
31093720: 66 7 5 73 6 1 4 910 840
52280: 5 1 75 7 847 8 8 62 40
3272268: 59 5 644 459 701 4
35454732: 7 7 984 5 32 3 9 69 37 2
450758928: 51 4 59 2 8 8 4 195 2 24
36492: 364 1 86 1 6
34656285942: 83 93 1 51 2 9 3 54 223
326592350: 8 36 5 81 40 5 70
3808350: 6 3 623 19 8 8 675
611496: 9 626 28 3 36
415429: 373 436 513 1 412
6713332057: 97 3 884 5 46 57
3383861896801: 1 81 38 1 955 5 6 9 77 1
140384: 3 5 5 970 47 3 33 761
1916: 5 6 4 4 9 7 2 1 4 342 2
17252: 5 11 140 63 3 5 76
10500: 5 35 2 1 30
1593745: 54 868 34 1 2 2 92
307311: 8 376 8 68 2 42
60696: 89 75 61 8 9
76288046546: 13 6 4 9 5 7 303 6 1 2 14
9273613: 92 73 613
335922: 331 2 2 37 3 84 50 9 51
17043713: 44 220 1 98 132 8 64
1755720677: 48 77 180 2 677
763: 42 250 7 1 463
4841686083: 60 23 90 24 88 90
7945523600154: 895 166 1 764 70 15 4
292513: 2 25 91 64 1 852 460
44328197: 73 877 3 29 962 2 3 12
4732438201: 5 87 4 2 77 2 6 700
1690422050730: 2 600 86 8 216 76 2 5 7
73303: 35 74 8 31 1 1 9 3 9 1 52
2929506: 1 9 186 175 6

41
2024/d07/ex2/ex2.py Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env python
import operator
import sys
def solve(input: str) -> int:
def parse(input: list[str]) -> list[tuple[int, list[int]]]:
return [
(int(value), [int(n) for n in numbers.split()])
for value, numbers in map(lambda l: l.split(": "), input)
]
def solvable(target: int, numbers: list[int]) -> bool:
def concat(lhs: int, rhs: int) -> int:
return int(str(lhs) + str(rhs))
def helper(current_value: int, current_index: int) -> bool:
next_index = current_index + 1
if len(numbers) == next_index:
return target == current_value
if current_value > target:
return False
for op in (operator.add, operator.mul, concat):
if helper(op(current_value, numbers[next_index]), next_index):
return True
return False
return helper(numbers[0], 0)
equations = parse(input.splitlines())
return sum(value for value, numbers in equations if solvable(value, numbers))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

850
2024/d07/ex2/input Normal file
View file

@ -0,0 +1,850 @@
187418: 8 1 32 1 3 7 700 2 6 8 9 9
51480079: 88 650 9 8 1
45694842: 2 9 227 6 1 5 4 382 1 5 2
324153: 4 6 165 26 2 8 9 3 50 9
28501243947: 66 18 84 68 6 926 78 7
20763: 8 9 7 123 308 2 2 709
1275: 40 5 6 75 1
769249: 1 47 4 4 3 9 49
464700680640: 94 7 26 7 917 9 6 5 392
501133472: 3 901 3 9 3 979 557 15
1408080699: 2 93 35 12 4 5 87 48 64
257184: 4 68 8 6 116 72
381878965: 727 5 1 56 28 6 67
625: 79 5 41 488 13
1382535550: 8 91 1 5 66 931 4 470
543135657: 7 649 5 9 7 71 979 7
69632: 7 51 8 2 963 8 6 3 701 9
4087: 1 3 576 2 7 7 10 6 9 592
6351: 21 298 4 2 84 3
15702: 7 1 419 36 366
89661885: 8 112 1 585 25 8 84
266450902950: 65 7 59 2 57 968 9 9 71
194394: 194 366 28
972: 6 29 546 1 390
1833720: 1 6 4 6 4 9 6 4 4 2 777 5
7263349: 9 84 780 93 4 9
94534: 781 12 8 9 797
258695989: 582 14 4 246 129 421
1371: 187 9 440 9 726
1403130963: 45 547 2 6 4 8 70 22 2
5172: 1 28 3 88 3 4 94 642 6
240988525: 5 865 441 5 21 382 3 2
212541850: 6 4 84 927 5 3 813 73
9096239: 890 67 4 1 9 95 84
482781: 635 1 1 95 8 5 8 5 7 58 7
4540643307: 5 4 5 898 5 5 92 9 9 8 3 6
46738900180: 976 706 17 58 57 4 70
259616: 312 207 6 314 4
174270594: 544 745 4 43 21 1
23194043: 773 3 3 9 1 43
2838182357: 28 381 81 1 1 357
557952: 9 62 80 9 62 6 36 7 3 7 8
82653627132: 8 507 7 6 565 6 5 6 7 6 3
917397714: 9 173 97 71 4
63564: 846 1 75 48 65 1
16152750: 714 7 795 99 26 5 1 99
64418: 6 86 4 4 92 7 18
96932098: 5 46 19 320 98
412070765: 318 3 4 69 5 313 3 2
1986: 990 3 2
10295: 6 3 940 826 687 322
143356: 3 98 4 9 7 6
264829968: 293 12 106 7 543 9 3 3
73800979: 10 5 3 1 46 8 9 28 4 6 9 8
2804772: 6 600 892 39 9 8 8 2 4 6
300031: 8 3 55 545 31
20008369743: 8 330 6 82 4 2 5 6 4 7 5 6
13396057557: 8 76 91 17 220 4 4 7 7
116812844776: 96 59 477 3 7 982 85
1197286087823: 9 829 9 3 3 2 87 3 4 2 9 7
288934843: 4 13 212 33 43
12097735: 1 120 884 93 35
2323: 4 7 129 250 654
4452928: 18 97 1 472 24 82
3693500: 9 825 56 494 4 89
230650225261: 863 1 96 8 4 87 3 5 8 5 9
6471: 76 73 898 8 17
1137: 5 2 47 297 786
368741: 8 458 113 2 1 3 7 1 90 2
347319: 447 9 69 816 259
6153742: 8 4 2 9 7 5 1 344 7 1 71 2
2300212040: 6 7 7 7 55 15 727 15 56
217743931: 24 3 234 718 18 379
1143073502: 216 84 7 167 9
1447474: 516 7 4 9 165 6 3 7 839
24175: 481 3 8 49 70
1198210: 69 633 7 2 845
3200: 8 50 8
7529214347: 376 46 5 34 9 40 387
23264072: 279 730 556 4 83
58517605: 959 305 61
3694797: 647 68 9 47 51
98762746: 7 980 6 27 46
675: 3 6 4 7 15 30
3302: 7 94 25 93 47 1 630 6
50372628: 7 943 16 9 92 2 9 9 5 4 4
546760284: 60 9 134 67 84
48336753: 69 24 90 33 175 3
327848: 6 607 90 8 60
1099845: 461 9 60 39 45
2913111: 5 726 190 8 761
215712: 1 9 9 8 7 7 3 8 7 8 225 7
187980: 2 9 32 2 23 78 2
28105: 1 373 3 74 207
13669642: 17 8 6 964 2
7519900: 695 56 98 99 1
52373979: 62 253 34 7 9 543
244520658: 8 39 1 922 3 7 9 8 5 2 4 4
761166846259: 702 80 5 73 375 271 9
1710191: 6 84 90 95 27 164
108219300: 6 669 5 3 4 8 96 3 7 2 7 5
83418128640: 752 9 3 2 3 6 8 99 9 4 4 9
31892804: 39 3 73 81 67 4
42680000: 4 268 4 50 50
23479827: 4 984 35 679 7
210060261: 206 3 21 84 73 7 289 1
3177: 47 3 71 5 457
902503660: 6 44 763 56 93 6 254 7
30198724521: 7 8 9 2 9 47 2 379 45 2 2
2163: 746 2 19 85 518 49
954304: 2 1 2 3 2 40 3 7 950 52 8
5835456294: 30 7 48 396 292 2
43320718: 456 95 2 8 4 434
3308760: 5 302 5 42 52
5796: 9 92 7
25910231829: 3 67 706 3 1 832
878427678805: 92 26 1 1 81 50 952 6
1473321: 71 2 635 30 5 2 6 4 1
8400848504: 9 6 96 56 84 8 2 3 100 4
49322159387: 13 2 8 92 7 3 5 8 6 7 8 7
684519833: 7 61 4 519 836
191600640: 8 8 540 528 42
311237: 631 9 486 9 8 15 165
951160: 9 3 983 5 9 1 77 8 7 5 2 5
59041208704: 98 4 6 11 987 99 9 6 8
354018: 72 3 1 59 124 118 3 7
35886127: 3 87 3 92 2 1 5 4 603 9
701625: 77 9 8 62 3
136802924: 958 425 7 7 2 3 2 47 1 4
71282596: 6 54 22 259 6
245520: 385 71 4 5 528
3517169040: 8 5 5 8 125 7 530 7 9 76
7792441765301: 778 7 2 7 9 2 365 9 4 14
607622809527: 5 6 48 8 36 730 9 52 5 2
842: 9 22 5 2 7 9 4 43 3 8 1 30
1173375: 7 4 2 3 225 7
3650074: 2 84 12 328 977
3812606: 9 8 8 23 28 151 2 7 8 86
17360: 3 820 1 7 3 18 3 4 1 7 1 2
12405: 16 1 9 86 20 1
66919866641: 211 8 6 44 5 9 8 7 9 1 4 1
8013364: 58 157 88 8 4
185974: 7 48 4 54 8 59 1 3
565292571: 896 29 33 123 590
471460: 556 24 7 116 500
9804900: 24 54 270 87 70 46 7
425: 2 9 6 25
512403750: 9 91 84 6 625
7303840435: 730 383 36 68 35
44385941654: 45 63 8 215 364 2 1 50
17793072: 1 86 3 2 406 28 517 9 4
68567808019: 6 2 192 8 370 19 16 3
16224908: 4 970 9 7 596
9437: 5 938 7
386334417: 696 6 94 59 3 2 3 4
4935770786: 4 7 52 8 9 8 1 49 5 1 7 86
926168190738: 9 260 7 7 2 26 1 90 738
1086806: 7 5 51 5 656 80 6
2131: 274 7 96 46 71
3560: 20 70 840 60 591
545: 4 11 9 379 79 1 63
4101: 3 1 6 5 352 574 8 2 2 3 2
40731: 93 86 503 991 690 4 3
16841473152: 94 52 4 96 763 47
404950: 71 83 419 77 623
3500596447460: 1 323 6 7 7 58 2 9 7 46 2
199362631126: 7 7 56 28 4 1 26 31 126
1298121: 6 8 781 3 7 5 1 5 309 7 5
33750: 30 3 34 90 57 33 3
1048524: 29 69 524
28241257580297: 713 5 978 5 81 802 97
688232: 60 2 8 2 598 9 5 4 79 9
4970: 9 1 8 1 7 2 60 8 5 460 3 7
38071: 791 368 7 79 30 721
20128402: 2 48 2 6 482 80 9 59 23
97596756600: 435 466 95 724 7
6525364319935: 3 684 636 863 987 5
437787903: 8 114 4 4 91 9 9 3 8 9 1 3
1457: 3 3 44 4 1
293090: 5 241 283 6 53
619297: 52 9 92 9 4
962292: 765 10 95 31 478 4
648387: 36 28 83 2 3 3 34
466433: 424 110 3 3 1
6967: 4 102 1 8 6 9 8
3396540: 242 61 140
3561767: 12 400 7 99 726 11
979543: 1 8 7 250 87 260 3 6 2 5
27988800000: 5 25 700 4 952 4 21
133389: 241 6 54 3 6
9533672: 89 631 25 479 69 514
24714: 1 86 26 507 3 9
9455893049: 28 5 7 7 888 6 3 4 2 4 1 9
1224: 4 8 36 485 671
2058747: 4 7 378 1 9 524 2 4 8 1 1
8122: 5 47 60 205 2
23657723657: 6 32 183 51 94 23 63 8
1238563682: 618 2 4 5 32 6 5 9 4 6 82
7039053: 9 367 213 366 3
144999092: 8 8 31 41 2 9 96 87 2 9 9
3416010: 400 854 2 2 5
307549178: 782 6 9 5 5 963 3 3 683
344179424889: 46 2 5 737 4 2 48 8 8 1
55345590: 366 120 7 1 20 710 9
38358188702684: 9 5 89 8 4 3 7 740 537 5
7063729304401: 569 183 973 77 881
12816555: 762 92 2 3 3 10 1 410 5
9621: 94 2 21
70948948: 6 4 1 9 8 178 1 4 6 264 2
411358: 423 97 791 36 2
3369019540: 56 617 2 975 7 38 41
1504080630: 39 5 62 1 207 601
779137845564: 37 101 8 21 3 1 5 564
5800032: 309 677 4 6 98
4168816845: 6 78 89 36 160 8 4 5
2911: 4 5 56 2 255 31 385
1142856906: 8 1 5 4 3 1 6 8 55 1 900 6
5823576: 56 604 34 86 2
6608969236: 5 5 6 2 86 3 3 1 3 9 236
1328554651: 4 1 324 74 80 648
4947149: 9 3 4 102 43 9 71 9 5 6 3
239760188: 6 2 2 2 40 6 6 92 3 4 9 92
1891987951: 4 2 82 465 5 33 968 7
933744: 42 445 9 3 71 158 7
15774: 556 3 578 7 5 44 3
2945: 2 9 716 4 28 9
392802448878: 6 98 5 5 4 4 1 70 4 1 93 6
5644947: 3 26 1 2 80 40 9 112 35
1490: 1 7 638 69 2 5 41 8 5 1 1
210990: 8 63 99 4 30
121980885: 3 27 1 271 5 9 3 9 1 9 5 3
7300117: 79 8 15 13 769
108410439: 542 2 10 1 350 89
5184867: 948 53 94 103 53
1127: 6 74 638 2 399 8
455827: 91 5 827
61760955: 9 49 4 4 2 71 80 5 433
191368: 7 5 2 8 5 7 791 7 3 4 2 2
567544412088: 963 9 736 76 39 8 88
12146752: 709 2 3 8 76 1 28 5 9 7 6
885889: 8 42 9 347 3
1106: 43 67 6
7202952: 405 8 5 355 2
20562: 284 610 23 1
191497654329: 824 50 83 9 1 7 28 2 9
2808193: 767 4 1 61 5 1 3 52 3
133955535: 3 8 2 601 818 1 2 7 645
6752263840: 5 4 6 4 8 5 314 7 8 5 7 4
313500: 469 4 56 11 6
1110: 14 1 74
15488: 95 4 1 26 2 6 7 3 5
35418: 11 723 47 5 915
391535: 7 403 953 1 486 319
1388084: 724 71 27 92 65 7 3 9 1
44009264785064: 55 137 833 73 813 3 8
18867200: 3 4 99 7 6 8 383 51 8 16
9612421: 6 2 34 6 553 7 362 959
8117920: 267 4 11 691 52
294154650: 29 409 6 46 49
189788268: 3 18 4 6 65 6 38 1 6 5 6 3
1676757: 75 4 69 81 51 6
605176: 7 34 61 506 4
539081638393: 33 146 33 974 506
419239: 610 9 245 8 73
21401: 7 5 57 5 26
240460: 9 74 2 15 4 6 29 221 55
153678511980: 7 204 810 542 237 7
16223812320: 7 7 6 279 7 597 57 80
175564935: 2 84 8 14 11 38 9 5 403
6048: 5 2 7 29 91 4
675100: 61 8 11 316 628
1155949124: 477 411 8 76 737
94353: 31 58 52 857
1128071: 393 5 8 6 6 59 333 248
4621214: 2 639 901 1 79 31 2 4 6
26092259600: 53 195 2 981 280 50
182162: 11 253 91 7 1 6 99 5 2
4452230: 138 6 7 8 9 12 1 8 29 2 7
314085244: 9 88 419 166 946
2291933389799: 5 472 3 7 47 72 3 831 2
1637032: 433 52 912 646 1 68
8505: 3 6 929 96 31 17
1051: 4 5 75 352 24
53861: 91 51 712 33 1
12176325: 6 3 773 9 5 35
53550: 414 9 99 7 2
76978: 2 84 50 8 4 44 66
166020482: 73 1 8 684 41 2
2994024: 19 816 8 3 56 5 8
531: 9 2 39 7 89 6
534784472: 2 3 1 9 95 9 60 58 3 4 72
584932732319: 29 31 89 6 5 65 1 72 19
4514: 9 35 11 58 45
49509809: 76 41 91 983 2 87 21 2
1404717811: 8 8 16 4 2 756 717 811
2687382: 3 10 4 4 90 2 91 6 863
339914973856: 713 68 41 37 26 7 435
296058: 3 4 3 1 5 33 8 2 8 38 1 7
67488804: 89 745 8 6 94
1252695: 9 92 6 9 5 8 8 1 2 4 63 3
27424: 8 47 60 8 925 1 99
1943363853992: 1 200 2 46 8 5 159 88
6294075553: 2 892 5 1 34 5 191 5 7 3
9476: 1 2 37 338 23
5001673: 4 2 2 3 5 9 8 2 7 991 4 92
19: 10 1 1 4 5
465093: 75 2 74 94 7 9 9 2 4 8 5 9
1369373: 898 471 3 73 1
1525: 23 2 61
41257: 4 1 1 2 57
6264: 30 96 7 7 6 84
321300: 3 435 1 7 31 6 1 5 7
1368: 98 57 2 6 4 9 971 68
784450040: 9 76 199 62 2 374
6835209: 9 1 436 905 2 8 6 5 206
362124546: 88 29 796 7 8 9 2 2 9 2 3
126885: 5 9 63 72 7 19 3
5676536: 3 3 945 44 664
29555174: 875 281 36 5 6 710 4
1809145007: 289 626 497 3 7
64764: 7 8 2 3 2 7 7 5 5 676 86 6
327240: 12 594 3 9 1 20
3945066: 9 73 5 6 65
86424: 4 5 567 848 2 731 24
52286469: 3 1 489 9 82 4 4 9 637 8
4251579: 457 7 556 2 64 65 59
229770: 65 60 874 46 5
2700: 1 7 96 3 3
198787972: 4 3 5 6 68 5 2 45 4 2 5 2
10115: 77 5 231 5 5
4303635: 1 14 782 9 69 595
2678: 20 9 7 81 1
145017912744: 99 4 783 107 9 47 93 9
13034369: 5 7 43 6 5 3 375 49 4 73
989: 84 92 8 5 687 94 7 8 4
53545060811: 80 4 85 84 8 99 7 4
230081372: 8 2 49 651 7 6 4 1 4 9 7 2
58091386: 56 5 1 7 3 222 4 8 3 158
48204: 3 461 91 333 47 26
58448887252: 7 175 22 66 486 52
197235: 410 9 48
22386781689439: 956 7 65 6 2 8 6 943 9
119340: 9 5 52 51
563562323: 8 5 7 903 79 5 79 14 9
52547762: 724 8 9 2 6 7 29 4 2 6 6 8
227057993908: 99 6 26 82 199 192 52
2700292479: 1 925 1 9 50 3 84 383 3
119784: 7 3 2 79 7 6 6 6 20 53 1 5
217977480: 91 3 6 8 2 980 81
9559: 828 56 65 3 66
134739247559: 10 8 4 6 4 9 1 3 9 675 59
1284754815: 594 56 590 8 5 2 9 335
6090685515: 2 60 2 758 9 8 4 5 87 9 5
1352574963: 1 69 69 17 7 97 1 843 9
2936812726: 42 4 6 174 317 2 716 7
21: 2 7 4 2 6
166409: 6 2 268 24 9
322: 122 9 4 143 44
4538: 450 1 33 4
1862003: 2 9 302 215 610 449
86940: 85 9 10 3 8
38072: 6 613 4 15 4 692
99725486: 6 12 6 6 6 6 65 25 478 8
13750: 53 2 439 27 412
7038816: 57 6 65 7 80 9 3 454 8
2855136: 6 620 8 570 543 33
146592: 84 7 160 2 67 924
569936: 7 5 621 4 4
740: 20 53 1 7 659
70911: 5 2 8 66 2 9 1 4 8 1 4 511
64728: 3 66 6 93
265592: 440 6 7 2 545 6 967 2
1497366612: 2 53 9 78 513 63 7 404
61277: 150 5 1 2 9 5 2 48 8 1 7 5
3346539: 8 82 5 42 7 3 59
3365893552180: 12 995 7 28 7 37 180
1009: 6 15 53 50 885
127008: 83 7 894 37 84
562032713741: 3 869 174 21 199 59
987527: 34 61 3 9 385
19712100: 735 4 530 84 25
26901: 303 117 1 4 3 63
15116264: 9 8 75 48 25 2 457 7 68
204191226: 3 89 1 2 4 2 8 8 3 9 327 6
5198984: 8 3 8 6 9 72 994 4 526 7
11382: 759 1 164 7 868 6 594
504391: 852 73 848 8 39
530085603: 30 558 984 5 9 2 5
624: 9 2 136 475 2
3629563236: 359 2 247 54 379
395873445: 9 227 47 8 9 3 2 2 5 687
552102: 5 77 20 567 4 18 8 551
76000078085: 47 2 33 7 7 2 156 5 85
132685: 9 46 2 386 7 96 7 6 4 9
10372: 3 5 1 9 47 189 2 2
20543565: 978 2 65 3 7
1472385558: 5 7 6 340 794 7
14144491524: 44 2 64 983 5 24
2692998: 48 1 19 63 638
1252924947: 9 5 869 534 7 1 6 697
4716: 12 98 1 3 4
2496938: 3 41 7 725 9 4 2
1235912: 7 3 99 4 217 49 92 76
2481026: 30 810 510 18 8
287777439: 74 83 411 2 3 1 57
6343360: 2 6 7 72 76 688
77516: 1 1 75 479 37
3030894: 8 7 6 1 2 4 71 29 4 2 6 40
5048088466: 80 631 8 765 7 71 6 30
359727: 897 80 5 923 4
74387040000: 50 52 80 5 13 393 7 2
220838337605: 65 48 56 44 760 1 76 5
25607876: 595 532 43
33263: 524 4 63
2233205: 956 6 4 389 348
49713: 115 54 9 4 4 86 2 5 864
6057554870011: 931 7 9 189 8 55 903 1
933697: 3 833 1 93 913 4 3 42
10924942: 780 353 14
284929536: 3 4 4 3 98 94 861 92 6
6695: 7 914 191 1 7 3 86 9
6245883: 9 989 85 62 6
30: 7 3 9
10155582722: 755 6 35 8 3 2 4 2 30 8 4
10213731200: 5 4 576 94 262 88 80
234673837: 41 81 31 4 7 5 831 6
324941866: 7 8 7 7 365 27 2 6 1 81
145341868: 995 4 961 6 38
2637745: 8 2 828 7 199
17982455851: 64 2 4 2 9 222 5 7 4 6 1
9608793: 574 956 628 4 8 381
719687: 71 9 6 80 7
48985815113: 85 571 450 8 151 11
4889892: 8 3 15 9 3 428 1 8 7 4 1 7
1505669220: 88 648 947 77 8 9 6 30
2127186: 818 91 468 3 9 5 8 58
4029145071: 15 562 37 64 45 3 287
79038: 48 661 1 2 707 2 981 9
50824: 50 7 1 2 4
3007: 79 29 5 6 2 9 8 778 72 7
97461: 25 779 5 81 5
72103770: 6 1 827 5 378 66 7 8 9 9
10958: 307 747 41 7 1
20287324856: 7 5 97 1 79 3 6 92 1 9 5 4
169639: 2 68 2 1 83 8 95 5 154
4596255180: 1 67 6 67 55 1 8 3
95786: 425 259 28 5 26
42269125: 80 6 331 22 4
293888: 4 2 4 2 821 54 425 4 7 8
5203652120: 2 260 36 52 120
214028823995: 9 7 889 2 670 7 1 9 9 5
46785931: 9 5 104 6 7 59 8 5 32 8 3
1249: 3 183 78 584 38
39642467328: 73 27 10 3 3 984 667
33264275: 22 782 2 3 5 73
138424899: 9 68 143 89 9
70342494: 195 958 61 9 447 47
194789: 83 3 782 50 21
183549: 6 40 399 7 2
68052: 6 51 553 9 649 5 2 9 53
14620480: 6 7 1 905 1 6 8 8 369 8 8
3453258: 89 388 58
17724262883: 35 92 24 1 8 2 8 688 1
10296335: 7 22 23 9 62 57
930: 913 11 6
1528389206: 198 7 907 4 822 218
684211: 6 9 76 7 596 6 570 23
3953055575502: 7 6 7 10 4 7 3 860 4 476
235864: 2 35 864
342199842: 46 6 70 4 41 37 6 6 2 3
38875005: 620 627 6 94 5
47902: 717 6 2 40 13 432 8 4
3437568326: 2 4 8 2 9 373 10 4 8 6
71911489: 7 5 38 258 633 233
116689560: 681 2 5 571 6
13336633: 66 535 516 3 33 43 97
2561353: 1 5 2 472 41
7100813: 998 73 78 85 83
9016487158: 1 915 3 3 9 3 8 94 49 5 8
231873894863: 2 98 42 2 777 863
17802929988398: 456 79 167 49 972 49
205498: 8 9 2 3 56 48 4 3 3 3 622
53767644: 537 673 5 4 290
64823081: 4 8 1 546 742 390 5 4 7
224054: 257 30 7 9 29
4381459: 84 3 629 5 9
156092264318: 26 60 92 264 319
4835710: 112 7 5 2 9 521 1 9 6 5 7
2097368646: 9 961 2 9 299 4 9 18 5 6
5199015150: 4 1 529 40 234 15 7 6 5
2263449: 7 236 8 2 9 8 8 3 245 9
17923542: 2 12 2 91 92 702 44 2
1822830370: 4 619 7 451 14 8 394 8
787528: 423 7 8 9 44 3 1 1 667 2
2861205060: 1 5 86 5 18 7 917 76 51
2139301: 80 347 23 77 10
78: 31 33 14
1938: 1 1 1 68 101 7 2 9 6
439607545: 6 29 378 3 1 904 1 481
21129: 704 3 9
1581: 848 1 21 649 1 62
2662: 68 3 62 2
3026494946287: 8 57 4 1 57 8 189 9 86
146835081730: 339 7 1 96 2 20 9 2 6 9 9
54568804: 1 65 99 848 4
344196191: 65 802 3 62 78 22 75
6009142314: 4 852 1 77 5 533 7 654
2293044: 902 37 6 407 6
66217250: 8 327 12 68 256 9 242
7449: 10 105 7 23 76
713: 73 50 586 1 3
8396761070: 691 9 821 3 5 9 9 5 8 56
84093834: 76 226 4 612 59 3 3 2 8
8021: 24 3 293 87 23
4588059: 8 55 5 8 547 1 6 4 2 27 3
896: 3 6 96 7 8
203856: 117 9 49 83 2 2 6
1755: 5 5 6 56 19
94983133313: 91 4 9 6 9 2 71 611 3
36501584: 421 59 200 84 76
2739260160: 83 8 78 3 60 67 32
11431577: 4 85 4 54 86 8 74 57
3904975: 762 183 28 451 36
1061781890400: 1 90 712 99 797 210
104260: 218 2 8 71 451 26
12831: 231 3 479 96 793 8 8 7
1867: 249 621 9 9 24 955
2736990: 52 56 9 19 3 930
7372456: 13 3 9 5 55 158 676 41
13995957291847: 87 86 655 4 838 852 7
262752: 7 755 9 180 6 8
116756: 60 85 8 86 665 5
21520534503978: 2 25 8 1 883 953 4 978
20702160: 65 72 7 8 45
47451357: 15 6 1 3 4 4 603 108 9 3
90184: 892 1 6 91 4
522977087: 6 8 8 35 75 5 5 9 76 6 5 3
19773: 938 46 2 9 3
591448: 96 8 611
151932: 9 6 8 7 300 6 997 7 3 2 6
677133: 55 94 96 7 17 8 15
62605459434: 236 75 5 33 5 4 2 6 609
1134716637: 5 134 4 814 576 8 51
203685: 138 7 885 22 3 8 3 5 5
411259430463: 7 60 4 988 2 7 384 7 6 3
69479410: 6 28 93 7 8 23 711 631
36480513: 747 4 5 10 488 73
6529930114: 98 37 398 638 110 1
3158302: 8 32 7 4 688 78 3 1
1329: 956 213 6 95 59
103528339432: 4 38 9 5 1 5 6 9 887 536
26058526: 86 1 69 6 3 7 155 75 3
16637174616501: 60 5 9 577 2 88 3 4 3 52
496403648: 24 10 1 419 8 617 8
70983429060: 234 1 5 20 1 6 8 5 8 5 60
18430386766: 7 5 42 7 776 198 55 34
4336513875: 7 869 534 1 3 15 89
146733: 2 179 8 8 6 300 99 15
719431: 1 418 7 4 4 7 4 5 8 35 6
123489453: 1 235 650 2 9 89 47 87
1817054297589: 6 40 395 5 4 297 592
28112657546: 48 73 71 58 113 6
3698184: 79 871 389 268 4
33904566: 8 359 3 95 2 97 9 4 3 6
3749036750: 37 4 903 6 750
9653520: 2 28 2 5 57 584
64502825: 7 9 20 171 8 60 5 65 5
258198671: 2 6 840 55 551 7 1
7876133: 9 9 32 46 963 718
795924: 8 31 3 51 873 48
25961153: 58 89 55 630 17 9 2 6 5
7689010: 83 6 602 699 9
37694322: 5 57 3 329 134 775 17
370720500: 7 6 371 8 767 1 14 606
396636777: 67 6 965 6 4 7 3 29 7
683362696: 68 33 62 6 96
176659289957: 8 2 3 57 824 8 899 57
942096: 6 830 74 2 5 4 2 1 93 6
139897: 50 6 4 5 466 3 86 8
25310524: 842 9 835 4 4
284646313: 7 2 858 677 4 623 5 4 7
182325: 361 418 3 75 7 6 6 75
55: 3 2 9 35 5
2383002: 384 31 62 73 207
5783478945: 61 2 9 15 7 14 8 351
6822681600: 8 840 490 56 37
4081902: 9 88 7 5 2 10 7 506
499758: 1 27 41 426 326
129: 53 7 61 3 5
4093163: 940 75 4 8 3 8 7 5 6 317
1735787709: 4 7 39 10 8 4 8 5 35 5 1 9
1466379: 6 8 8 1 4 3 6 5 625 6 25 9
1132930: 2 44 81 8 2 3 19 2 6 6 2 8
813082430: 2 9 2 27 72 5 616 486 5
39761608992: 8 3 1 5 9 4 7 9 942 476 4
183663: 3 17 407 9
290472: 52 7 798
26524378336980: 2 7 808 977 3 92 8 980
130466560295040: 778 533 9 98 816 190
4905495936: 4 11 17 93 808 99 8
593640: 492 5 5 1 2 3 39 9 6 30
6233: 9 12 68 7 6 2 1 5 3 16 41
36038: 9 476 863 7 9
128815: 1 2 88 15
1864323072: 202 292 9 128 8
9950315: 52 4 938 51 3 8
501726: 5 476 303 187 5
92280: 922 27 2 9 42
76472: 661 208 88
61014: 1 97 1 629 1
17078477400: 1 44 4 5 128 308 2 5 3 8
376022848: 21 760 1 4 224 6 56 8
6639080646: 945 3 2 7 7 99 881 643
116944: 4 3 7 38 81 6 3 8 1 441 7
230277087093: 319 430 9 801 93
1043119420033: 4 31 6 1 4 341 2 350 35
17346278: 6 45 69 9 157 545 18
2901672: 2 287 1 16 72
117015525: 5 1 8 594 4 9 97 6 3 3 55
48944038: 539 9 71 608 5 703 26
51469483: 113 965 472 217 26
35344593648: 7 54 7 822 238 549 78
9385011: 938 493 5 9 22
8666140861: 5 6 6 1 4 44 60 6 6 1 8 5
5300472946: 692 5 31 762 948
25608: 87 4 3 24 552
308240474597: 770 6 5 8 429 45 5 9 2 5
16439885: 2 8 822 3 50 651 5 77
544500: 8 22 253 37 26 4 2
30379565: 3 903 1 5 323 1 9 565
41656: 144 47 794 31 41
24807: 48 7 63 7 552
3485: 499 4 74 6 23
839060: 1 27 1 35 5 7 9 3 7 6 1 25
23088: 9 9 33 42 148
9154663: 4 817 311 8 7 91 6 63 1
90682288496: 7 577 8 5 20 1 6 748 6
43937079: 5 770 7 89 91 4
29472: 614 6 8
11561778226: 2 6 6 4 34 9 9 963 2 2 2 6
117144416: 317 8 8 6 6 8 39 8 1 956
2462640: 3 8 15 2 9 7 5 8 4 7 930 8
6991816: 6 2 867 3 4 5 7 8 1 35 4 9
10813: 12 76 14 37 576
5764467: 90 94 9 8 5 2 68 92 9 4 2
20995047250: 5 814 4 6 7 9 4 4 7 9 2 50
340676: 492 32 5 92 7
460049: 9 8 839 39 5 69 4 8 2 7 8
39360102: 46 101 5 7 845 2
632489040: 632 48 896 1 73 6
4515: 73 1 4 5 15
22440: 4 8 21 663 561
34573: 26 2 65 77 3
1205424: 3 48 930 2 4 1 4 2 4 1 9
2288024: 4 6 411 9 92 7 5 56 6 8
7166740: 5 62 4 980 103
43925184: 68 7 767 23 8 8 1 2 6 2 8
73957520: 8 4 6 1 3 4 440 67 560
4497072: 449 6 858 3 211
379852098: 65 68 68 3 29 7 9 6 1 2 6
7039622942269: 7 491 357 4 6 9 683 84
59297832: 83 895 586 9 11 8
3222143: 98 427 77 4 1
2706396: 2 7 4 9 9 8 5 5 8 3 85 609
54899: 9 40 5 8 99
15470567600: 423 6 737 988 9 1 6 4 4
414459045: 640 8 468 369 3 13 35
28680: 286 73 7
148225337: 5 63 394 6 5 4 4 922 7
1548: 8 9 20 83 25
52488: 55 4 5 8 81
309758831546: 7 4 3 4 39 7 4 3 145 1 8 8
45710059: 2 77 5 38 5 17 26 89 7 8
110968: 3 8 9 4 5 435 3 4 32 1 1 5
296175877: 2 3 124 9 3 2 46 71 6 55
183182295: 3 6 31 82 295
18032285875: 733 246 26 459 875
2252773168103: 6 690 743 91 370 3
208683: 90 1 303 531
5905: 5 83 9 4 59 3
2547957588: 2 135 6 7 9 4 5 57 5 87
864108: 10 525 233 204 889
2632797169: 9 5 78 52 578 3 5 71 2 2
3861135: 17 94 6 330 91 42
279877248: 98 69 966 503 72
4321455138000: 567 4 611 20 75 693 3
109506168: 771 73 43 3 9 5 8 896 9
131686680949: 2 344 6 55 3 632 1 950
11285568: 42 3 622 48 3
7429: 6 7 35 15 5 4
1344632850: 6 81 825 986 19
1349: 12 9 23 866
135629: 52 4 5 3 5 6 17 4 6 39 65
109541641: 772 1 665 3 705 71
36454: 32 11 847 33
18256000: 79 4 792 326 64
634608: 9 784 13 13 8
2149222: 391 7 54 21 1
1020512181: 8 89 9 3 3 4 40 80 1 8 9 3
778156485: 6 21 5 4 2 7 23 663 9 5 3
4983272739052: 280 5 530 11 920 4 73
4161: 72 44 925 60 8
2507022432: 4 489 6 9 8 2 8 8 90 2 8 2
650605: 9 12 629 60 5
2092992: 85 1 3 991 24
26902: 9 2 3 74 6 5 42 9 8 123 2
15599: 4 151 98 1
41225189: 8 16 1 91 44 429 5
1473989040: 7 228 6 1 30 32 920
61866: 20 28 934 3 21
570190125: 471 99 1 90 128
16235927: 6 26 35 731 992 855
21528: 565 2 1 2 1 8 1 9 6 66 6
43993993848: 6 2 8 95 805 62 28 5 1
26706275149: 4 60 451 2 58 6 5 42 8
1011: 52 7 635 6 6
299093: 9 8 2 4 7 8 4 9 4 5 5 867
833382: 6 3 6 23 671
14505768: 2 97 268 3 93
4923890: 93 61 526 4
48105: 751 4 16 3 38
1414794: 70 38 16 61 251 11 6 3
38616996: 4 79 68 791 2 3 6 999
1904796000: 39 8 606 4 9 546 999
147334: 9 732 65 44 22
34232: 7 31 598 42 2
12270967818: 27 722 9 885 5 2 3 8 8
9264135: 3 451 441 25 6 4 13 5
45507450163: 45 496 11 450 163
91440: 4 41 6 916 5 48
88344832: 882 4 8 38 8 41
287671639: 985 29 202 1 1 56 7 2 4
507668: 911 8 804 90 4 70 20 8
394114: 19 837 51 434 7 469
77382: 5 9 5 55 29 4 9 3 3 7 30 8
9957630062: 56 9 310 73 2 291 7 3 2
10296: 7 98 3 1 6 84 3 735 9
295260: 7 2 18 9 84 1 39 3 19 6 7
4701: 20 57 34 2 2 2 1
3848560: 28 4 8 7 72 8 359 20 4
16949608: 7 1 3 413 8 6 3 42 8 2 5 8
31453576: 53 1 2 33 580 21 77 8
314611: 33 9 24 86 773
15245: 6 2 1 2 5 5 4 6 89 9 853 5
7265: 1 7 7 6 8 1 7 669 3 4 6 63
548073: 9 88 282 20 669 324
62260835: 2 971 916 9 35
835164: 30 4 3 513 44
19800544: 440 45 1 136 407
33392435588: 73 829 54 739 9 746
9119277: 4 1 433 39 2 6 1 1 2 5 9
2473338468: 2 4 24 446 155 3 3
3391904: 5 42 291 248 8
4854: 89 310 738 77 4
7990517: 1 659 3 2 747 8 6 61 5
27168: 195 80 8 6 16
356592: 9 7 6 9 7 152 11 45 57
803: 3 2 792 3 2
7324966325691: 7 8 327 4 12 3 814 2 3 4
4348464: 87 238 35 34 6
78: 1 31 1 46
2333: 395 903 8 93 9 2 923
17413920: 1 730 95 8 2 580 2 9
121371: 6 2 1 1 7 693 57 1 8 35 3
52915920: 201 2 263 2 54 66
4205: 1 6 82 9 6 722 4 3 5 3 5
102938: 2 8 7 70 62 1 157 73 8
64212990: 15 423 269 5 109
2891: 2 24 4 15 11
7707154: 411 954 4 1 7 1 3 6 7 94
83830: 1 40 2 3 27 7 24 2 6 62
342729: 7 83 272 14 9
55247775: 541 851 8 16 41 15
4259: 5 73 7 5 4 5
13394887: 4 7 2 2 6 5 58 783 7 6 2 7
904: 4 2 727 80 91
7641038: 485 1 8 860 516 6 18 2
2359540874: 2 546 3 8 6 36 71
833: 42 62 1 14 7
1581: 4 60 857 1 1 7 477
225893352782: 225 893 35 278 2
19077: 40 9 28 247 58
1026671144: 5 46 3 74 8 359 8 7 69 3
398072: 44 3 635 56 3
15469480: 409 1 539 35 90 2
1809270: 8 331 48 85 55 45
2627552: 4 7 26 3 6 25 2 2 8 7 5 2
6983: 1 950 1 70 6 9 4 844 1
864439333: 8 98 80 439 330
7739: 857 9 14 4 8
527424: 5 19 6 32 67
178358491551: 242 66 42 758 968 3 1
23466: 4 60 4 1 2 1 166 8 5 379
8865: 1 788 193 3 9 3
25531136601: 2 55 311 36 601
1435774: 8 84 27 578 18 4
6228: 4 878 7 7 5
1642: 3 8 3 4 2
38584000: 8 6 4 2 41 6 95 2 4 8 875
24723940: 209 31 477 9 8 4
2116117: 697 3 2 6 7 23 425 36 6
3124451126: 26 3 11 12 78 4 6
86185: 879 9 4 4 6 66 8 9 1 853
35383157110: 2 1 792 31 43 730 7
1658134437620: 7 3 5 233 465 44 2 485
43437081675: 5 713 216 2 176 77
800998632: 7 3 214 4 54 246 378
5200: 8 9 463 9 8 377
33760: 67 2 3 2 5
1120091: 63 5 55 37 344 8 11 16
140: 1 47 92
5721882: 42 49 29 2 469 82
34206: 37 6 77 9 2
121: 29 3 76 9 4
4941531369: 91 54 22 5 53 137 1
3463558642: 28 13 87 971 1 63 8 4
31093720: 66 7 5 73 6 1 4 910 840
52280: 5 1 75 7 847 8 8 62 40
3272268: 59 5 644 459 701 4
35454732: 7 7 984 5 32 3 9 69 37 2
450758928: 51 4 59 2 8 8 4 195 2 24
36492: 364 1 86 1 6
34656285942: 83 93 1 51 2 9 3 54 223
326592350: 8 36 5 81 40 5 70
3808350: 6 3 623 19 8 8 675
611496: 9 626 28 3 36
415429: 373 436 513 1 412
6713332057: 97 3 884 5 46 57
3383861896801: 1 81 38 1 955 5 6 9 77 1
140384: 3 5 5 970 47 3 33 761
1916: 5 6 4 4 9 7 2 1 4 342 2
17252: 5 11 140 63 3 5 76
10500: 5 35 2 1 30
1593745: 54 868 34 1 2 2 92
307311: 8 376 8 68 2 42
60696: 89 75 61 8 9
76288046546: 13 6 4 9 5 7 303 6 1 2 14
9273613: 92 73 613
335922: 331 2 2 37 3 84 50 9 51
17043713: 44 220 1 98 132 8 64
1755720677: 48 77 180 2 677
763: 42 250 7 1 463
4841686083: 60 23 90 24 88 90
7945523600154: 895 166 1 764 70 15 4
292513: 2 25 91 64 1 852 460
44328197: 73 877 3 29 962 2 3 12
4732438201: 5 87 4 2 77 2 6 700
1690422050730: 2 600 86 8 216 76 2 5 7
73303: 35 74 8 31 1 1 9 3 9 1 52
2929506: 1 9 186 175 6

50
2024/d08/ex1/ex1.py Executable file
View file

@ -0,0 +1,50 @@
#!/usr/bin/env python
import itertools
import sys
from collections import defaultdict
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[str, set[Point]]:
res: dict[str, set[Point]] = defaultdict(set)
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
res[c].add(Point(x, y))
return res
def find_antinodes(grid: dict[str, set[Point]], dims: Point) -> set[Point]:
max_x, max_y = dims
antinodes: set[Point] = set()
for antennas in grid.values():
for start, end in itertools.permutations(antennas, 2):
dx, dy = end.x - start.x, end.y - start.y
x, y = start.x - dx, start.y - dy
if not (0 <= x < max_x):
continue
if not (0 <= y < max_y):
continue
antinodes.add(Point(x, y))
return antinodes
lines = input.splitlines()
max_x, max_y = len(lines), len(lines[0])
grid = parse(lines)
return len(find_antinodes(grid, Point(max_x, max_y)))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

50
2024/d08/ex1/input Normal file
View file

@ -0,0 +1,50 @@
.A...........5........................pL..........
.................................p......L.........
......................................L...........
.......................................C..........
........v...................7...............C.....
..................................p........L......
.................vA......3........................
.......A.....3....................................
........................s....X3...................
..A......5.................9....3.................
.......8...........s.........7.............C..m...
................8......t........7.......9.........
....................o......Z.............y........
...............s.......Y.v.o......y....0..........
..................................................
..5................8.......................m...J..
5...............................0....aX...........
.V............v.s.........Z.o..7....a.............
2..........f...........P..............9...J.M.....
...............f..........P.....V......y....1.J...
...g...................o.......0l...........N..B..
..................Y...............................
......G...............f.....Z..t..............1...
............G......Z......h................B....C.
.........w....h.Y....j............a........J..y...
.............P....z..........................1....
w.......P...z...R......r8.........................
........w.........................................
.................h.G.........m............BM......
......4.....fa.................G...i....X......W..
V........4..............................tW.9...i..
............2h..............0.......tX...M........
.....z.........................l..................
.......2..........................................
..r........................Y................W...i.
.......w.........q..................i.............
.........H.2....4.................................
..........Q.....j.......M.....lrN.................
..x...H.Q.......O.....c...........................
....H.......................S.....................
.....................O..S.......6..........b......
...c.......F...Q.j.........l....T.....R...........
...........Q.F.......c.I.....1.........R....T.....
............F........I.O......r..T.............b..
..n.........q.........F.I..............T..b.......
.......n...........z..O....x.......N........b.....
.....S............................................
..........q.........cS..x4I......6................
..j.....gn.q.......x...................N...6......
...........g..n................R......B...........

51
2024/d08/ex2/ex2.py Executable file
View file

@ -0,0 +1,51 @@
#!/usr/bin/env python
import itertools
import sys
from collections import defaultdict
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[str, set[Point]]:
res: dict[str, set[Point]] = defaultdict(set)
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
res[c].add(Point(x, y))
return res
def find_antinodes(grid: dict[str, set[Point]], dims: Point) -> set[Point]:
max_x, max_y = dims
antinodes: set[Point] = set()
for antennas in grid.values():
for start, end in itertools.permutations(antennas, 2):
dx, dy = end.x - start.x, end.y - start.y
for i in itertools.count():
x, y = start.x - dx * i, start.y - dy * i
if not (0 <= x < max_x):
break
if not (0 <= y < max_y):
break
antinodes.add(Point(x, y))
return antinodes
lines = input.splitlines()
max_x, max_y = len(lines), len(lines[0])
grid = parse(lines)
return len(find_antinodes(grid, Point(max_x, max_y)))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

50
2024/d08/ex2/input Normal file
View file

@ -0,0 +1,50 @@
.A...........5........................pL..........
.................................p......L.........
......................................L...........
.......................................C..........
........v...................7...............C.....
..................................p........L......
.................vA......3........................
.......A.....3....................................
........................s....X3...................
..A......5.................9....3.................
.......8...........s.........7.............C..m...
................8......t........7.......9.........
....................o......Z.............y........
...............s.......Y.v.o......y....0..........
..................................................
..5................8.......................m...J..
5...............................0....aX...........
.V............v.s.........Z.o..7....a.............
2..........f...........P..............9...J.M.....
...............f..........P.....V......y....1.J...
...g...................o.......0l...........N..B..
..................Y...............................
......G...............f.....Z..t..............1...
............G......Z......h................B....C.
.........w....h.Y....j............a........J..y...
.............P....z..........................1....
w.......P...z...R......r8.........................
........w.........................................
.................h.G.........m............BM......
......4.....fa.................G...i....X......W..
V........4..............................tW.9...i..
............2h..............0.......tX...M........
.....z.........................l..................
.......2..........................................
..r........................Y................W...i.
.......w.........q..................i.............
.........H.2....4.................................
..........Q.....j.......M.....lrN.................
..x...H.Q.......O.....c...........................
....H.......................S.....................
.....................O..S.......6..........b......
...c.......F...Q.j.........l....T.....R...........
...........Q.F.......c.I.....1.........R....T.....
............F........I.O......r..T.............b..
..n.........q.........F.I..............T..b.......
.......n...........z..O....x.......N........b.....
.....S............................................
..........q.........cS..x4I......6................
..j.....gn.q.......x...................N...6......
...........g..n................R......B...........

62
2024/d09/ex1/ex1.py Executable file
View file

@ -0,0 +1,62 @@
#!/usr/bin/env python
import sys
def solve(input: str) -> int:
def parse(input: str) -> tuple[list[int], list[int]]:
files: list[int] = []
free: list[int] = []
for i, c in enumerate(input):
if c == "\n":
continue
(files if i % 2 == 0 else free).append(int(c))
# Make `to_disk` slightly simpler
if len(files) > len(free):
free.append(0)
return files, free
def to_disk(files: list[int], free: list[int]) -> list[int | None]:
assert len(files) == len(free) # Sanity check
disk: list[int | None] = []
for i in range(len(files)):
disk.extend([i for _ in range(files[i])])
disk.extend([None for _ in range(free[i])])
return disk
def compact(disk: list[int | None]) -> list[int]:
last = len(disk) - 1
for i in range(len(disk)):
# Are we finished compacting?
if i >= last:
break
# Is this a free space?
if disk[i] is not None:
continue
assert disk[last] is not None # Sanity check
disk[i], disk[last] = disk[last], disk[i]
# Find next block to compact
while disk[last] is None:
last -= 1
# At this point, `None` are at the end
# Naive list comprehension to appease the type checker
return [n for n in disk if n is not None]
files, free = parse(input)
disk = to_disk(files, free)
return sum(i * n for i, n in enumerate(compact(disk)))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1
2024/d09/ex1/input Normal file

File diff suppressed because one or more lines are too long

93
2024/d09/ex2/ex2.py Executable file
View file

@ -0,0 +1,93 @@
#!/usr/bin/env python
import sys
from typing import NamedTuple
class FilePosition(NamedTuple):
pos: int
length: int
class ParsedDisk(NamedTuple):
files: list[FilePosition]
holes: list[FilePosition]
def solve(input: str) -> int:
def parse(input: str) -> tuple[list[int], list[int]]:
files: list[int] = []
free: list[int] = []
for i, c in enumerate(input):
if c == "\n":
continue
(files if i % 2 == 0 else free).append(int(c))
# Make `to_disk` slightly simpler
if len(files) > len(free):
free.append(0)
return files, free
def to_disk(files: list[int], free: list[int]) -> ParsedDisk:
assert len(files) == len(free) # Sanity check
pos = 0
disk_files: list[FilePosition] = []
holes: list[FilePosition] = []
for i in range(len(files)):
disk_files.append(FilePosition(pos, files[i]))
pos += files[i]
holes.append(FilePosition(pos, free[i]))
pos += free[i]
return ParsedDisk(disk_files, holes)
def compact(disk: ParsedDisk) -> list[int | None]:
def move_files(disk: ParsedDisk) -> dict[int, FilePosition]:
new_files: dict[int, FilePosition] = {}
for i, (pos, length) in reversed(list(enumerate(disk.files))):
for h in range(len(disk.holes)):
# Hole must be big enough to fit the file
if length > disk.holes[h].length:
continue
# Hole must be to the left of the file
if pos < disk.holes[h].pos:
break
# We found a hole, move the file into it
pos = disk.holes[h].pos
disk.holes[h] = FilePosition(
length=disk.holes[h].length - length,
pos=disk.holes[h].pos + length,
)
break
new_files[i] = FilePosition(pos, length)
return new_files
def to_disk(files: dict[int, FilePosition]) -> list[int | None]:
disk: list[int | None] = [None] * max(
(f.pos + f.length) for f in files.values()
)
for i, f in files.items():
for j in range(f.length):
assert disk[f.pos + j] is None # Sanity check
disk[f.pos + j] = i
return disk
new_files = move_files(disk)
return to_disk(new_files)
files, free = parse(input)
disk = to_disk(files, free)
return sum(i * n for i, n in enumerate(compact(disk)) if n is not None)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1
2024/d09/ex2/input Normal file

File diff suppressed because one or more lines are too long

66
2024/d10/ex1/ex1.py Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env python
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
TopoMap = dict[Point, int]
def solve(input: str) -> int:
def parse(input: list[str]) -> TopoMap:
return {
Point(x, y): int(c)
for x, line in enumerate(input)
for y, c in enumerate(line)
}
def find_trail_heads(map: TopoMap) -> set[Point]:
return {p for p, height in map.items() if height == 0}
def score_trail(map: TopoMap, start: Point) -> int:
assert map[start] == 0 # Sanity check
res = 0
queue = {start}
visited: set[Point] = set()
while queue:
p = queue.pop()
visited.add(p)
cur_height = map[p]
if cur_height == 9:
res += 1
for n in p.neighbours():
if map.get(n, cur_height) != (cur_height + 1):
continue
if n in visited:
continue
queue.add(n)
return res
map = parse(input.splitlines())
trail_heads = find_trail_heads(map)
return sum(score_trail(map, head) for head in sorted(trail_heads))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

59
2024/d10/ex1/input Normal file
View file

@ -0,0 +1,59 @@
18776569014346783430321009012345676543089876765012101843210
09683458723454894321234218987432189452176769854323678956521
14592987654098765436549367016543032360145678765014545697434
23601678432132650145678456323456501278234549343478034788910
10712569549241043278901285434787654329103234256589121078923
89803434678950012789854398103490769210567145187678438967434
67810326589867821016760187312521898123498076094501567456556
50981810410778932345123272210634567087654189143215678304567
41832900325696543451074561028701256198563778012324569213498
32963871234587123898785654139987341017652890123473478012323
87874562187671034567698763245676892456701287634982101701414
96565653094544343452188898743786743326898096545679876894505
05454512123349852143089889652898653217652125621043965787676
12343103098256765001234767601701062108943034432152014690189
01289544567187678114345678015612341007765403569061023543287
01276632101096789823210599126543652210812312678278710871296
10345789780125679814676587439874743321907654589189658960345
01234695690434578705689436510165894430418523971012347454434
12304504541128963210790325565256766569349010810143232323521
23413213232037654309821019874305412678256186743256101210650
34329832198747012313412301878912301569107898653087082198761
65896701007658965412301498965887432354518947894198898017321
96785432216234878905432567054896345823101456763234745654450
87123870125165687876541230123445458910112398654125656723765
21012965634018796982650345678032567421012567432098749810894
76321034676569805401721214789121076578323456501589038902923
85432123589458012392895603210434789489210167895610121451012
96524323428301123483486578765965672374331321234785430543212
87012410210216782174987439834874301065145490121096789678101
73453891346785493065234328703893216521036787654567645679201
02567765445698304160145012012743227434321098943658938983210
11098894332103215659876430125652108965670101812340127654321
25437743210114106765454309836543345696987872701235672105898
36727654012325699877869218747434210780745963890104383236785
49818123963445788566978745658923312321894854761201294345656
56709037874236567345432036547012103456783203454398761787654
43237654365187665432301127015432176501654112341432650198323
54108910210094572301432098326721085432456043210541043278910
45678921109001481676501287445856794101387456101650169867610
38787632278112390789043016532943893232297887232789856701521
29698543465243654632132105621032124540196996243456765432430
10101012354305783541245094765021043256785432123455965432107
67652765410216792150956783876107650122312301098767874345698
58543894324345891067810782987238987201406784567854901236787
49987685456543282123425691096543271230545493201993210340123
32106452567650112054534567899454100045654320192387651259654
40045321898342106567651056928767652198743410887434540568798
51235430210289287438122345210178943329652378976543039875687
67896787320176396129034434356598712410701237010132128064516
10765698451965445001545423347895606549890796521243989123105
23896787567843234652436710212874307432037887430145478798234
34785896765432128763429876108963218901126986543234567017345
25634789854578019854210785654851019985435100125676454156236
18721034563689108943218798743344328776434234234981043205145
09343123872672397654309654312235899643421965547872124314076
43216012901521087898701211201156732554310876958943235023489
56905438765432076985654300321076541467215467867654332133012
47876329034310145676701098730987210398706326321038949874323
56981010123421234565892345645678901237987015432127654365434

61
2024/d10/ex2/ex2.py Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env python
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
TopoMap = dict[Point, int]
def solve(input: str) -> int:
def parse(input: list[str]) -> TopoMap:
return {
Point(x, y): int(c)
for x, line in enumerate(input)
for y, c in enumerate(line)
}
def find_trail_heads(map: TopoMap) -> set[Point]:
return {p for p, height in map.items() if height == 0}
def rate_trail(map: TopoMap, start: Point) -> int:
def helper(pos: Point) -> int:
if map[pos] == 9:
return 1
res = 0
for n in pos.neighbours():
if map.get(n, -1) != (map[pos] + 1):
continue
res += helper(n)
return res
assert map[start] == 0 # Sanity check
return helper(start)
map = parse(input.splitlines())
trail_heads = find_trail_heads(map)
return sum(rate_trail(map, head) for head in sorted(trail_heads))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

59
2024/d10/ex2/input Normal file
View file

@ -0,0 +1,59 @@
18776569014346783430321009012345676543089876765012101843210
09683458723454894321234218987432189452176769854323678956521
14592987654098765436549367016543032360145678765014545697434
23601678432132650145678456323456501278234549343478034788910
10712569549241043278901285434787654329103234256589121078923
89803434678950012789854398103490769210567145187678438967434
67810326589867821016760187312521898123498076094501567456556
50981810410778932345123272210634567087654189143215678304567
41832900325696543451074561028701256198563778012324569213498
32963871234587123898785654139987341017652890123473478012323
87874562187671034567698763245676892456701287634982101701414
96565653094544343452188898743786743326898096545679876894505
05454512123349852143089889652898653217652125621043965787676
12343103098256765001234767601701062108943034432152014690189
01289544567187678114345678015612341007765403569061023543287
01276632101096789823210599126543652210812312678278710871296
10345789780125679814676587439874743321907654589189658960345
01234695690434578705689436510165894430418523971012347454434
12304504541128963210790325565256766569349010810143232323521
23413213232037654309821019874305412678256186743256101210650
34329832198747012313412301878912301569107898653087082198761
65896701007658965412301498965887432354518947894198898017321
96785432216234878905432567054896345823101456763234745654450
87123870125165687876541230123445458910112398654125656723765
21012965634018796982650345678032567421012567432098749810894
76321034676569805401721214789121076578323456501589038902923
85432123589458012392895603210434789489210167895610121451012
96524323428301123483486578765965672374331321234785430543212
87012410210216782174987439834874301065145490121096789678101
73453891346785493065234328703893216521036787654567645679201
02567765445698304160145012012743227434321098943658938983210
11098894332103215659876430125652108965670101812340127654321
25437743210114106765454309836543345696987872701235672105898
36727654012325699877869218747434210780745963890104383236785
49818123963445788566978745658923312321894854761201294345656
56709037874236567345432036547012103456783203454398761787654
43237654365187665432301127015432176501654112341432650198323
54108910210094572301432098326721085432456043210541043278910
45678921109001481676501287445856794101387456101650169867610
38787632278112390789043016532943893232297887232789856701521
29698543465243654632132105621032124540196996243456765432430
10101012354305783541245094765021043256785432123455965432107
67652765410216792150956783876107650122312301098767874345698
58543894324345891067810782987238987201406784567854901236787
49987685456543282123425691096543271230545493201993210340123
32106452567650112054534567899454100045654320192387651259654
40045321898342106567651056928767652198743410887434540568798
51235430210289287438122345210178943329652378976543039875687
67896787320176396129034434356598712410701237010132128064516
10765698451965445001545423347895606549890796521243989123105
23896787567843234652436710212874307432037887430145478798234
34785896765432128763429876108963218901126986543234567017345
25634789854578019854210785654851019985435100125676454156236
18721034563689108943218798743344328776434234234981043205145
09343123872672397654309654312235899643421965547872124314076
43216012901521087898701211201156732554310876958943235023489
56905438765432076985654300321076541467215467867654332133012
47876329034310145676701098730987210398706326321038949874323
56981010123421234565892345645678901237987015432127654365434

35
2024/d11/ex1/ex1.py Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env python
import sys
def solve(input: str) -> int:
def parse(input: str) -> list[int]:
return [int(n) for n in input.split()]
def blink(stones: list[int]) -> list[int]:
res: list[int] = []
for n in stones:
if n == 0:
res.append(1)
elif len(str(n)) % 2 == 0:
s = str(n)
lhs, rhs = s[: len(s) // 2], s[len(s) // 2 :]
res.extend((int(lhs), int(rhs)))
else:
res.append(n * 2024)
return res
stones = parse(input)
for _ in range(25):
stones = blink(stones)
return len(stones)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1
2024/d11/ex1/input Normal file
View file

@ -0,0 +1 @@
0 7 6618216 26481 885 42 202642 8791

37
2024/d11/ex2/ex2.py Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env python
import sys
from collections import Counter
def solve(input: str) -> int:
def parse(input: str) -> Counter[int]:
return Counter(int(n) for n in input.split())
def blink(stones: Counter[int]) -> Counter[int]:
res: Counter[int] = Counter()
for n, count in stones.items():
if n == 0:
res[1] += count
elif len(str(n)) % 2 == 0:
s = str(n)
lhs, rhs = s[: len(s) // 2], s[len(s) // 2 :]
res[int(lhs)] += count
res[int(rhs)] += count
else:
res[n * 2024] += count
return res
stones = parse(input)
for _ in range(75):
stones = blink(stones)
return sum(stones.values())
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1
2024/d11/ex2/input Normal file
View file

@ -0,0 +1 @@
0 7 6618216 26481 885 42 202642 8791

67
2024/d12/ex1/ex1.py Executable file
View file

@ -0,0 +1,67 @@
#!/usr/bin/env python
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[Point, str]:
return {
Point(x, y): c for x, line in enumerate(input) for y, c in enumerate(line)
}
def find_plots(garden: dict[Point, str]) -> list[set[Point]]:
res: list[set[Point]] = []
visited: set[Point] = set()
for p, plant in garden.items():
if p in visited:
continue
plot: set[Point] = set()
to_visit = {p}
while to_visit:
p = to_visit.pop()
visited.add(p)
plot.add(p)
assert garden[p] == plant # Sanity check
for n in p.neighbours():
if garden.get(n) != plant:
continue
if n in visited:
continue
to_visit.add(n)
res.append(plot)
return res
def fence_price(plot: set[Point]) -> int:
area = len(plot)
perimeter = sum(n not in plot for p in plot for n in p.neighbours())
return area * perimeter
garden = parse(input.splitlines())
plots = find_plots(garden)
return sum(map(fence_price, plots))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

140
2024/d12/ex1/input Normal file
View file

@ -0,0 +1,140 @@
TTTTTTTTTTTTTTDDDDDDDDDDDDAAAKKKKKKKKKKKKKKKKKKKKKKKRRRRRRRRRRRRRXXXXXXXXXXZFFFFFFFFFFOFVVVVVVQQQQQUQQQQQQQQQQQQQQQQQCCGGNNNNHHHHHHHHHHHHHHH
TTTTTTTTTTTTTTDDDDDDDDDDDDAAAAAAKKKKKFKKKKKKKKKKKKKKRRRRRRRRRRRXXXXXXXXXXXXZFFFFFFFFFFFFFFFVMMQQQQQQQQQQQQQQQQQQQQQQQGGGGNNNNHHHHHHHHHHHHHHH
TTTTTTTTTTTTDDDDDDDDDDDUAAAAAAAAAKKFFFKKKKKKKKKKKKKKRRRRRRRRRRXXXXXXXXMXMMFFFFFFFFFFFFFFFMMMMMNQQQQQQQQQQQQQQQQQQQQQZZGGNNNNHHHHHHHHHHHHHHHH
TTTTTTTBTTTTDDDDDDDDDDUUUAAAAAAAKKKKFFKKKKKKKKKVLLLLLRRRRRRRRRXXXXXXXMMMMMFMMMMFFFFFFFFFXMMHMMNQQQQQQQIQQQQQQQQQQQQQQQGGNNNNVVVHHHHHHHHHHHHH
TTTTBTBBTTTTDDDDDDDDDDUUUAAAAAAAKKKFFKKKKKKKKKNLLLLLLRRRRRRRRRXXXXXXXMMMMMMMMMFFFFFFFFHXXXMHHNNQ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YRRRRXXXXXPPPPPPPPIIIIIIAAAAAAAAAEEEEEEEQQQQQQQQQQQQUVVVVVIIIIIIIIIGSSSSSSSSYVVYYYYYYYYYYYQQQ
TTTTTTTTTTTTTLLLLLLLVVLLLLLLGGGGFGGGGGGYYYYYYYRYRRRRXXRRPPPPPPPIIIIIIIIIIIAAAAAAAAAEEEEQQQQQQQQQQQUUVFFFIIIIIIIIYYGGSSSSSSSSVYYYYYYYYYYQQQQQ
TTTTTTTTTMTLLLLLLLLLLVLLLLLLGSSGGGGSSSYYYYYYYRRRRRRRRRRRRRPPPPPIIIIIIIIIIIIAAAAAAAAEHEEQQQQQQQQQQQQQVVFFIIIIIIIYYYGGGVVSVSVVVYYYYYYYQQQQQQQQ
TTTTTTTTLLLLLLLLLLLLLLLLLLLLGSSSGTGSSYYYYYYYYYRRRRRRRRRRRRRPRRIIIIIIIIIIIAAAAAAAAAAEHEEQQQQQQQQQQQQQQFFFFIIIIIIIIYYGGGVVVVVVVYYYWYYYQQQQQQQQ

90
2024/d12/ex2/ex2.py Executable file
View file

@ -0,0 +1,90 @@
#!/usr/bin/env python
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
def solve(input: str) -> int:
def parse(input: list[str]) -> dict[Point, str]:
return {
Point(x, y): c for x, line in enumerate(input) for y, c in enumerate(line)
}
def find_plots(garden: dict[Point, str]) -> list[set[Point]]:
res: list[set[Point]] = []
visited: set[Point] = set()
for p, plant in garden.items():
if p in visited:
continue
plot: set[Point] = set()
to_visit = {p}
while to_visit:
p = to_visit.pop()
visited.add(p)
plot.add(p)
assert garden[p] == plant # Sanity check
for n in p.neighbours():
if garden.get(n) != plant:
continue
if n in visited:
continue
to_visit.add(n)
res.append(plot)
return res
def count_corners(plot: set[Point]) -> int:
def corners(p: Point) -> int:
res = 0
for dx, dy in (
(-1, -1),
(1, 1),
(-1, 1),
(1, -1),
):
diag = Point(p.x + dx, p.y + dy)
vert = Point(p.x + dx, p.y)
hori = Point(p.x, p.y + dy)
# Both sides are out: an outside corner
if vert not in plot and hori not in plot:
res += 1
# Both sides are in, diagonal is out: an inside corner
if vert in plot and hori in plot and diag not in plot:
res += 1
return res
return sum(corners(p) for p in plot)
def fence_price(plot: set[Point]) -> int:
area = len(plot)
# Number of sides is equal to number of corners
sides = count_corners(plot)
return area * sides
garden = parse(input.splitlines())
plots = find_plots(garden)
return sum(map(fence_price, plots))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

140
2024/d12/ex2/input Normal file
View file

@ -0,0 +1,140 @@
TTTTTTTTTTTTTTDDDDDDDDDDDDAAAKKKKKKKKKKKKKKKKKKKKKKKRRRRRRRRRRRRRXXXXXXXXXXZFFFFFFFFFFOFVVVVVVQQQQQUQQQQQQQQQQQQQQQQQCCGGNNNNHHHHHHHHHHHHHHH
TTTTTTTTTTTTTTDDDDDDDDDDDDAAAAAAKKKKKFKKKKKKKKKKKKKKRRRRRRRRRRRXXXXXXXXXXXXZFFFFFFFFFFFFFFFVMMQQQQQQQQQQQQQQQQQQQQQQQGGGGNNNNHHHHHHHHHHHHHHH
TTTTTTTTTTTTDDDDDDDDDDDUAAAAAAAAAKKFFFKKKKKKKKKKKKKKRRRRRRRRRRXXXXXXXXMXMMFFFFFFFFFFFFFFFMMMMMNQQQQQQQQQQQQQQQQQQQQQZZGGNNNNHHHHHHHHHHHHHHHH
TTTTTTTBTTTTDDDDDDDDDDUUUAAAAAAAKKKKFFKKKKKKKKKVLLLLLRRRRRRRRRXXXXXXXMMMMMFMMMMFFFFFFFFFXMMHMMNQQQQQQQIQQQQQQQQQQQQQQQGGNNNNVVVHHHHHHHHHHHHH
TTTTBTBBTTTTDDDDDDDDDDUUUAAAAAAAKKKFFKKKKKKKKKNLLLLLLRRRRRRRRRXXXXXXXMMMMMMMMMFFFFF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GGGEYYYYYYYYRYRRRRXXXXXPPPPPPPPIIIIIIAAAAAAAAAEEEEEEEQQQQQQQQQQQQUVVVVVIIIIIIIIIGSSSSSSSSYVVYYYYYYYYYYYQQQ
TTTTTTTTTTTTTLLLLLLLVVLLLLLLGGGGFGGGGGGYYYYYYYRYRRRRXXRRPPPPPPPIIIIIIIIIIIAAAAAAAAAEEEEQQQQQQQQQQQUUVFFFIIIIIIIIYYGGSSSSSSSSVYYYYYYYYYYQQQQQ
TTTTTTTTTMTLLLLLLLLLLVLLLLLLGSSGGGGSSSYYYYYYYRRRRRRRRRRRRRPPPPPIIIIIIIIIIIIAAAAAAAAEHEEQQQQQQQQQQQQQVVFFIIIIIIIYYYGGGVVSVSVVVYYYYYYYQQQQQQQQ
TTTTTTTTLLLLLLLLLLLLLLLLLLLLGSSSGTGSSYYYYYYYYYRRRRRRRRRRRRRPRRIIIIIIIIIIIAAAAAAAAAAEHEEQQQQQQQQQQQQQQFFFFIIIIIIIIYYGGGVVVVVVVYYYWYYYQQQQQQQQ

79
2024/d13/ex1/ex1.py Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/env python
import dataclasses
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class ClawMachine:
a_delta: Point
b_delta: Point
prize: Point
def solve(input: str) -> int:
def parse_button(input: str) -> Point:
deltas = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("+")[1]), deltas.split(", "))
return Point(x, y)
def parse_prize(input: str) -> Point:
coords = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("=")[1]), coords.split(", "))
return Point(x, y)
def parse_claw_machine(input: list[str]) -> ClawMachine:
assert len(input) == 3 # Sanity check
return ClawMachine(
parse_button(input[0]),
parse_button(input[1]),
parse_prize(input[2]),
)
def parse(input: str) -> list[ClawMachine]:
return [parse_claw_machine(group.splitlines()) for group in input.split("\n\n")]
def play_machine(machine: ClawMachine) -> int | None:
def found_prize(row: list[tuple[int, Point]]) -> int | None:
for tokens, p in row:
if p == machine.prize:
return tokens
return None
row = [
(3 * i, Point(machine.a_delta.x * i, machine.a_delta.y * i))
for i in range(101)
]
res = found_prize(row)
for _ in range(100):
row = [
(tokens + 1, Point(p.x + machine.b_delta.x, p.y + machine.b_delta.y))
for tokens, p in row
]
tmp = found_prize(row)
if tmp is None:
continue
if res is None:
res = tmp
res = min(res, tmp)
return res
claw_machines = parse(input)
return sum(
tokens for tokens in map(play_machine, claw_machines) if tokens is not None
)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1279
2024/d13/ex1/input Normal file

File diff suppressed because it is too large Load diff

69
2024/d13/ex2/ex2.py Executable file
View file

@ -0,0 +1,69 @@
#!/usr/bin/env python
import dataclasses
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class ClawMachine:
a_delta: Point
b_delta: Point
prize: Point
def solve(input: str) -> int:
def parse_button(input: str) -> Point:
deltas = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("+")[1]), deltas.split(", "))
return Point(x, y)
def parse_prize(input: str) -> Point:
coords = input.split(": ")[1].strip()
x, y = map(lambda delta: int(delta.split("=")[1]), coords.split(", "))
return Point(10000000000000 + x, 10000000000000 + y)
def parse_claw_machine(input: list[str]) -> ClawMachine:
assert len(input) == 3 # Sanity check
return ClawMachine(
parse_button(input[0]),
parse_button(input[1]),
parse_prize(input[2]),
)
def parse(input: str) -> list[ClawMachine]:
return [parse_claw_machine(group.splitlines()) for group in input.split("\n\n")]
def play_machine(machine: ClawMachine) -> int | None:
a_dx, a_dy = machine.a_delta
b_dx, b_dy = machine.b_delta
px, py = machine.prize
a = (px * b_dy - py * b_dx) // (b_dy * a_dx - b_dx * a_dy)
b = (px * a_dy - py * a_dx) // (a_dy * b_dx - a_dx * b_dy)
if a * a_dx + b * b_dx != px:
return None
if a * a_dy + b * b_dy != py:
return None
return 3 * a + b
claw_machines = parse(input)
return sum(
tokens for tokens in map(play_machine, claw_machines) if tokens is not None
)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

1279
2024/d13/ex2/input Normal file

File diff suppressed because it is too large Load diff

61
2024/d14/ex1/ex1.py Executable file
View file

@ -0,0 +1,61 @@
#!/usr/bin/env python
import dataclasses
import functools
import operator
import sys
from collections import Counter
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class Robot:
pos: Point
vel: Point
def step(self, dims: Point, delta: int = 1) -> "Robot":
x, y = self.pos.x + self.vel.x * delta, self.pos.y + self.vel.y * delta
return Robot(
Point(x % dims.x, y % dims.y),
self.vel,
)
def solve(input: str) -> int:
def parse_robot(input: str) -> Robot:
pos, vel = map(lambda s: s.split("=")[1], input.split(" "))
return Robot(
Point(*map(int, pos.split(","))),
Point(*map(int, vel.split(","))),
)
def parse(input: list[str]) -> list[Robot]:
return [parse_robot(line) for line in input]
def compute_safety(robots: list[Robot], dims: Point) -> int:
mid_x, mid_y = dims.x // 2, dims.y // 2
counts: Counter[tuple[bool, bool]] = Counter()
for x, y in map(lambda robot: robot.pos, robots):
if x == mid_x or y == mid_y:
continue
counts[(x < mid_x, y < mid_y)] += 1
return functools.reduce(operator.mul, counts.values())
robots = parse(input.splitlines())
dims = Point(101, 103)
robots = [robot.step(dims, 100) for robot in robots]
return compute_safety(robots, dims)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

500
2024/d14/ex1/input Normal file
View file

@ -0,0 +1,500 @@
p=62,20 v=85,-14
p=88,18 v=-70,97
p=51,21 v=35,-22
p=19,56 v=2,45
p=93,11 v=-87,26
p=90,67 v=44,-13
p=99,34 v=82,57
p=55,42 v=82,22
p=61,22 v=-24,-95
p=100,7 v=18,-29
p=92,56 v=-56,66
p=66,15 v=-6,77
p=62,21 v=68,39
p=8,80 v=-72,-90
p=33,40 v=89,-46
p=28,10 v=-4,-64
p=4,78 v=-55,1
p=87,23 v=-32,-10
p=1,76 v=85,6
p=15,51 v=-35,-75
p=58,98 v=-41,80
p=34,17 v=-25,-47
p=66,81 v=23,50
p=48,97 v=-53,88
p=99,69 v=-97,83
p=25,23 v=-38,31
p=16,54 v=91,37
p=12,65 v=-85,-41
p=13,62 v=51,64
p=54,16 v=-91,-30
p=99,92 v=34,30
p=44,21 v=-50,-9
p=0,55 v=15,-46
p=68,23 v=-53,-51
p=29,51 v=24,-55
p=42,10 v=-98,28
p=76,50 v=-55,-54
p=83,24 v=65,-70
p=13,15 v=-85,64
p=2,53 v=-43,-59
p=8,88 v=-24,34
p=100,50 v=33,-20
p=24,83 v=17,54
p=18,71 v=52,38
p=93,21 v=-33,-18
p=8,78 v=-19,-7
p=23,31 v=61,-46
p=76,60 v=47,46
p=51,26 v=-53,32
p=32,54 v=-76,33
p=66,65 v=-42,62
p=19,3 v=78,-23
p=96,46 v=88,-76
p=53,44 v=12,-13
p=64,56 v=-30,64
p=41,52 v=35,-24
p=49,9 v=-28,35
p=77,18 v=9,-43
p=57,3 v=97,-97
p=81,57 v=-23,27
p=13,73 v=-22,-90
p=97,76 v=-46,-49
p=63,43 v=-80,99
p=90,96 v=-37,-92
p=89,33 v=82,-42
p=79,64 v=-19,-58
p=64,65 v=59,-90
p=84,54 v=17,24
p=95,42 v=18,-13
p=90,43 v=-36,-62
p=83,2 v=32,-97
p=34,69 v=-38,-78
p=91,17 v=18,31
p=42,82 v=74,-94
p=1,33 v=-72,-42
p=97,82 v=-20,-94
p=83,83 v=-23,40
p=56,22 v=85,-22
p=50,42 v=25,-70
p=32,1 v=88,-60
p=63,71 v=-3,-33
p=49,85 v=-67,59
p=18,8 v=-23,39
p=24,60 v=-76,-87
p=34,100 v=-88,-85
p=84,84 v=44,79
p=16,101 v=53,-64
p=44,33 v=88,-25
p=52,22 v=-43,-35
p=30,63 v=-23,-86
p=14,40 v=65,-50
p=56,98 v=-41,88
p=42,11 v=-14,-72
p=72,9 v=-4,-72
p=26,71 v=-47,-62
p=92,18 v=-71,15
p=81,40 v=59,7
p=79,69 v=16,64
p=4,40 v=24,-83
p=17,78 v=65,-32
p=87,85 v=81,-36
p=98,27 v=42,42
p=100,55 v=72,95
p=94,12 v=-80,61
p=73,34 v=96,-38
p=32,30 v=-63,-38
p=45,37 v=-27,-75
p=6,0 v=-72,-68
p=24,58 v=39,41
p=25,74 v=-26,-15
p=99,82 v=80,64
p=88,54 v=-94,-21
p=100,81 v=29,-28
p=84,87 v=56,6
p=71,17 v=-95,-96
p=37,89 v=-9,-18
p=42,30 v=-78,-59
p=92,17 v=-68,14
p=31,55 v=88,66
p=28,10 v=-13,-62
p=30,30 v=29,60
p=89,80 v=8,-42
p=23,75 v=41,-44
p=65,78 v=-55,42
p=1,80 v=-9,19
p=54,78 v=36,83
p=10,40 v=66,-95
p=67,71 v=8,58
p=23,17 v=12,69
p=36,70 v=76,21
p=7,63 v=-60,-65
p=39,96 v=87,41
p=8,56 v=-34,-90
p=64,66 v=9,79
p=2,61 v=4,17
p=64,51 v=28,-6
p=91,25 v=-41,69
p=92,3 v=-85,47
p=61,41 v=-90,57
p=86,61 v=-69,70
p=82,45 v=7,-13
p=23,39 v=-78,-40
p=58,3 v=-30,15
p=87,30 v=87,-25
p=21,84 v=39,34
p=36,26 v=89,-59
p=90,51 v=-83,-91
p=5,39 v=79,-87
p=5,63 v=66,-74
p=71,45 v=21,-21
p=49,40 v=-68,-66
p=68,93 v=96,96
p=67,96 v=46,51
p=72,44 v=-32,82
p=15,90 v=15,2
p=26,78 v=28,-44
p=7,3 v=-87,-39
p=74,101 v=94,-76
p=90,20 v=-6,-46
p=22,17 v=-68,-63
p=12,81 v=-37,14
p=37,84 v=-15,22
p=75,31 v=83,-63
p=48,2 v=-90,-27
p=44,94 v=-63,31
p=73,71 v=-50,22
p=22,101 v=39,51
p=49,94 v=-90,26
p=93,67 v=5,-12
p=57,83 v=-68,80
p=86,82 v=44,-32
p=3,64 v=87,-62
p=43,87 v=-20,-57
p=40,18 v=-8,-56
p=80,46 v=-89,57
p=79,26 v=-18,27
p=3,27 v=-98,77
p=99,44 v=42,-99
p=25,27 v=-72,23
p=98,24 v=43,85
p=54,93 v=-28,-60
p=29,4 v=86,80
p=42,96 v=-75,14
p=75,77 v=54,81
p=96,63 v=-46,-33
p=51,94 v=88,-69
p=31,88 v=51,39
p=75,15 v=-43,-84
p=8,18 v=93,63
p=20,65 v=99,30
p=71,5 v=72,-98
p=31,95 v=63,-19
p=87,70 v=-68,71
p=11,55 v=15,37
p=63,36 v=10,36
p=41,98 v=37,10
p=27,78 v=26,-36
p=53,93 v=30,18
p=78,25 v=-58,-80
p=21,100 v=-73,66
p=36,33 v=25,11
p=65,3 v=-92,-68
p=46,22 v=-64,48
p=49,87 v=-91,38
p=82,37 v=6,16
p=24,94 v=-30,-3
p=14,94 v=94,37
p=28,32 v=39,-1
p=35,19 v=-68,-25
p=3,51 v=-47,70
p=12,6 v=-29,-28
p=28,19 v=15,2
p=75,45 v=95,-67
p=76,4 v=7,-93
p=45,29 v=-63,-37
p=41,22 v=-64,93
p=67,45 v=10,-36
p=51,1 v=21,-74
p=25,84 v=1,-81
p=15,36 v=-47,-29
p=44,98 v=24,-81
p=79,30 v=45,94
p=45,57 v=12,-57
p=12,23 v=65,78
p=65,76 v=-68,17
p=100,100 v=79,23
p=75,22 v=58,-84
p=82,65 v=69,-74
p=76,6 v=-61,-61
p=61,38 v=27,53
p=68,94 v=86,37
p=64,71 v=6,-88
p=21,93 v=-53,-65
p=32,86 v=64,-98
p=11,11 v=-95,-95
p=36,32 v=-38,65
p=23,95 v=91,-65
p=31,33 v=12,-34
p=12,5 v=-99,-72
p=50,3 v=-91,-93
p=74,66 v=33,13
p=22,7 v=-12,-97
p=11,6 v=41,-43
p=14,16 v=-21,60
p=95,76 v=81,-61
p=3,55 v=79,99
p=43,97 v=-1,-60
p=73,66 v=31,-33
p=60,33 v=73,-57
p=63,57 v=71,-95
p=86,11 v=-20,-80
p=50,28 v=86,-34
p=66,5 v=-80,45
p=96,87 v=67,6
p=52,16 v=-53,40
p=31,31 v=38,32
p=96,23 v=-34,-72
p=46,64 v=-91,45
p=14,19 v=-73,60
p=31,85 v=12,-32
p=19,36 v=-36,-46
p=39,21 v=-52,15
p=98,34 v=-10,81
p=96,65 v=-9,1
p=97,75 v=-21,34
p=22,0 v=64,2
p=8,15 v=-24,36
p=67,1 v=61,-89
p=64,76 v=70,34
p=22,29 v=-74,-54
p=73,48 v=-41,-75
p=83,7 v=-82,-72
p=57,6 v=-66,-93
p=31,21 v=-50,81
p=90,21 v=-56,-35
p=79,73 v=54,77
p=62,64 v=60,29
p=51,70 v=-96,-6
p=35,71 v=75,-33
p=9,56 v=53,-58
p=63,48 v=-94,49
p=61,72 v=82,55
p=51,79 v=-66,5
p=2,62 v=46,-46
p=56,2 v=10,-64
p=42,74 v=-64,75
p=0,83 v=17,-61
p=3,59 v=-97,33
p=40,82 v=-15,47
p=89,8 v=94,19
p=76,26 v=-95,-23
p=4,86 v=79,76
p=4,32 v=-77,31
p=35,38 v=-9,-59
p=78,87 v=72,-57
p=72,72 v=-72,67
p=94,33 v=-2,-93
p=59,96 v=37,-19
p=90,24 v=-83,-1
p=88,61 v=69,50
p=67,28 v=35,-66
p=40,63 v=75,29
p=84,27 v=-42,-91
p=40,21 v=-31,-30
p=1,50 v=-34,-95
p=87,59 v=96,-94
p=36,19 v=-78,-68
p=5,43 v=-78,91
p=27,49 v=91,-99
p=61,85 v=11,14
p=89,61 v=-83,-97
p=31,78 v=-86,81
p=76,69 v=33,-82
p=74,28 v=-43,-71
p=23,27 v=-35,86
p=80,74 v=-33,-86
p=99,10 v=43,-10
p=59,55 v=-41,-95
p=89,94 v=58,43
p=72,87 v=7,67
p=68,73 v=-29,-57
p=1,46 v=80,41
p=45,33 v=36,-38
p=24,4 v=46,21
p=18,94 v=-35,5
p=82,45 v=53,74
p=93,75 v=-83,-86
p=14,3 v=51,-80
p=74,30 v=-30,-96
p=70,38 v=-29,-34
p=55,76 v=-94,-13
p=11,82 v=-10,38
p=11,55 v=-35,-4
p=93,76 v=6,-57
p=17,57 v=-80,-42
p=47,82 v=18,94
p=84,70 v=-84,1
p=48,94 v=-90,6
p=95,41 v=-51,57
p=18,53 v=55,-84
p=100,20 v=-20,-56
p=49,26 v=-17,34
p=31,62 v=92,-86
p=69,2 v=-81,82
p=76,43 v=-71,97
p=23,15 v=-62,97
p=26,23 v=-87,40
p=67,48 v=34,16
p=64,11 v=-54,85
p=85,58 v=8,-49
p=80,25 v=57,-6
p=45,35 v=49,-9
p=96,65 v=-20,-25
p=91,49 v=68,16
p=8,62 v=29,33
p=97,50 v=69,-85
p=52,53 v=-2,70
p=70,68 v=44,83
p=65,7 v=-17,39
p=45,14 v=-87,-34
p=94,47 v=-93,-46
p=29,84 v=70,11
p=70,73 v=-23,-6
p=100,51 v=45,18
p=21,2 v=-13,-19
p=67,32 v=-95,-82
p=61,2 v=-54,64
p=17,12 v=65,35
p=67,54 v=-74,-89
p=2,6 v=5,-92
p=26,77 v=-12,-28
p=39,77 v=12,-86
p=70,57 v=84,-83
p=8,88 v=-60,13
p=19,37 v=-38,-89
p=0,14 v=6,-2
p=24,59 v=-24,-82
p=5,13 v=-11,-47
p=21,27 v=88,23
p=89,75 v=-20,83
p=68,66 v=19,1
p=34,72 v=-74,25
p=27,70 v=14,-90
p=89,9 v=-44,2
p=5,67 v=-61,-36
p=52,13 v=-53,-84
p=50,21 v=-90,-9
p=21,16 v=2,64
p=69,21 v=-18,-88
p=64,85 v=-80,34
p=31,70 v=50,95
p=15,8 v=-23,52
p=97,52 v=28,41
p=85,6 v=8,-15
p=9,33 v=-74,52
p=46,59 v=90,96
p=71,50 v=-93,98
p=15,74 v=-24,-82
p=54,87 v=-15,-36
p=37,25 v=-15,7
p=92,13 v=86,78
p=90,14 v=20,-68
p=68,37 v=-5,4
p=58,56 v=48,-99
p=27,16 v=-36,-32
p=4,49 v=-58,65
p=5,50 v=-60,98
p=13,31 v=-48,-91
p=58,75 v=46,8
p=66,88 v=-6,-98
p=95,16 v=32,23
p=86,21 v=-57,-55
p=19,65 v=-32,-98
p=83,57 v=-46,-95
p=37,10 v=38,64
p=87,33 v=46,8
p=45,54 v=-53,-58
p=35,95 v=-39,-7
p=89,65 v=58,-45
p=82,80 v=-82,-65
p=35,7 v=25,76
p=66,92 v=-16,-44
p=75,89 v=-92,66
p=48,84 v=98,42
p=70,84 v=-30,-44
p=49,51 v=-92,28
p=27,85 v=62,-36
p=31,21 v=3,-64
p=61,101 v=-15,88
p=56,44 v=90,68
p=83,49 v=-95,-83
p=69,38 v=8,-92
p=34,13 v=-32,43
p=0,51 v=-75,25
p=39,36 v=76,69
p=66,59 v=70,-96
p=78,42 v=-31,-62
p=5,5 v=-33,-22
p=54,74 v=-12,44
p=25,26 v=25,85
p=74,88 v=-39,56
p=65,83 v=33,-28
p=87,90 v=95,30
p=71,20 v=-29,93
p=66,9 v=83,-96
p=38,51 v=50,41
p=66,87 v=44,46
p=30,31 v=-49,-14
p=70,32 v=73,28
p=0,94 v=95,26
p=87,80 v=-83,46
p=92,70 v=-58,99
p=48,67 v=-1,41
p=43,74 v=49,34
p=87,51 v=43,8
p=23,63 v=39,-86
p=2,77 v=48,7
p=32,60 v=-63,-37
p=99,3 v=-21,31
p=82,55 v=57,8
p=5,68 v=-46,-41
p=32,77 v=-38,88
p=84,0 v=6,-64
p=20,95 v=52,26
p=29,98 v=-16,83
p=44,81 v=-27,-73
p=43,40 v=-41,-42
p=24,73 v=-88,-49
p=99,45 v=-97,8
p=37,9 v=-31,-57
p=70,11 v=8,-39
p=0,11 v=96,57
p=83,70 v=70,75
p=65,71 v=-40,-65
p=82,66 v=73,-80
p=31,41 v=52,-96
p=19,72 v=65,75
p=24,4 v=-86,54
p=75,85 v=85,30
p=2,83 v=17,-7
p=9,87 v=-22,59
p=24,3 v=-12,21
p=5,74 v=-34,46
p=22,90 v=-37,-11
p=20,84 v=4,95
p=95,10 v=-96,-55
p=52,9 v=23,-14
p=20,51 v=-63,-75
p=64,27 v=24,48
p=50,2 v=-90,-68
p=54,47 v=23,70
p=26,22 v=51,-51
p=4,49 v=-72,-54
p=53,47 v=2,-86
p=21,29 v=-37,13
p=37,70 v=38,-40
p=6,41 v=43,-20
p=88,23 v=-38,-68
p=67,20 v=79,-71
p=37,7 v=24,25

80
2024/d14/ex2/ex2.py Executable file
View file

@ -0,0 +1,80 @@
#!/usr/bin/env python
import dataclasses
import functools
import itertools
import sys
from typing import Literal, NamedTuple
class Point(NamedTuple):
x: int
y: int
@dataclasses.dataclass
class Robot:
pos: Point
vel: Point
def step(self, dims: Point, delta: int = 1) -> "Robot":
x, y = self.pos.x + self.vel.x * delta, self.pos.y + self.vel.y * delta
return Robot(
Point(x % dims.x, y % dims.y),
self.vel,
)
def solve(input: str) -> int:
def parse_robot(input: str) -> Robot:
pos, vel = map(lambda s: s.split("=")[1], input.split(" "))
return Robot(
Point(*map(int, pos.split(","))),
Point(*map(int, vel.split(","))),
)
def parse(input: list[str]) -> list[Robot]:
return [parse_robot(line) for line in input]
def find_tree(robots: list[Robot], dims: Point) -> int:
def compute_positions(step: int) -> list[Point]:
return [robot.step(dims, step).pos for robot in robots]
def compute_variance(values: list[int]) -> float:
avg = sum(values) / len(values)
variance = sum((n - avg) ** 2 for n in values) / len(values)
return variance
def cluster_variance(step: int, dimension: Literal["x", "y"]) -> float:
return compute_variance(
[getattr(p, dimension) for p in compute_positions(step)]
)
# The tree should have robots clustered together in X and Y
cluster_x = min(
range(dims.x),
key=functools.partial(cluster_variance, dimension="x"),
)
cluster_y = min(
range(dims.y),
key=functools.partial(cluster_variance, dimension="y"),
)
# And those clusers should repeat modulo each dimension
for i in itertools.count(cluster_x, step=dims.x):
if i % dims.y == cluster_y:
return i
assert False # Sanity check
robots = parse(input.splitlines())
dims = Point(101, 103)
return find_tree(robots, dims)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

500
2024/d14/ex2/input Normal file
View file

@ -0,0 +1,500 @@
p=62,20 v=85,-14
p=88,18 v=-70,97
p=51,21 v=35,-22
p=19,56 v=2,45
p=93,11 v=-87,26
p=90,67 v=44,-13
p=99,34 v=82,57
p=55,42 v=82,22
p=61,22 v=-24,-95
p=100,7 v=18,-29
p=92,56 v=-56,66
p=66,15 v=-6,77
p=62,21 v=68,39
p=8,80 v=-72,-90
p=33,40 v=89,-46
p=28,10 v=-4,-64
p=4,78 v=-55,1
p=87,23 v=-32,-10
p=1,76 v=85,6
p=15,51 v=-35,-75
p=58,98 v=-41,80
p=34,17 v=-25,-47
p=66,81 v=23,50
p=48,97 v=-53,88
p=99,69 v=-97,83
p=25,23 v=-38,31
p=16,54 v=91,37
p=12,65 v=-85,-41
p=13,62 v=51,64
p=54,16 v=-91,-30
p=99,92 v=34,30
p=44,21 v=-50,-9
p=0,55 v=15,-46
p=68,23 v=-53,-51
p=29,51 v=24,-55
p=42,10 v=-98,28
p=76,50 v=-55,-54
p=83,24 v=65,-70
p=13,15 v=-85,64
p=2,53 v=-43,-59
p=8,88 v=-24,34
p=100,50 v=33,-20
p=24,83 v=17,54
p=18,71 v=52,38
p=93,21 v=-33,-18
p=8,78 v=-19,-7
p=23,31 v=61,-46
p=76,60 v=47,46
p=51,26 v=-53,32
p=32,54 v=-76,33
p=66,65 v=-42,62
p=19,3 v=78,-23
p=96,46 v=88,-76
p=53,44 v=12,-13
p=64,56 v=-30,64
p=41,52 v=35,-24
p=49,9 v=-28,35
p=77,18 v=9,-43
p=57,3 v=97,-97
p=81,57 v=-23,27
p=13,73 v=-22,-90
p=97,76 v=-46,-49
p=63,43 v=-80,99
p=90,96 v=-37,-92
p=89,33 v=82,-42
p=79,64 v=-19,-58
p=64,65 v=59,-90
p=84,54 v=17,24
p=95,42 v=18,-13
p=90,43 v=-36,-62
p=83,2 v=32,-97
p=34,69 v=-38,-78
p=91,17 v=18,31
p=42,82 v=74,-94
p=1,33 v=-72,-42
p=97,82 v=-20,-94
p=83,83 v=-23,40
p=56,22 v=85,-22
p=50,42 v=25,-70
p=32,1 v=88,-60
p=63,71 v=-3,-33
p=49,85 v=-67,59
p=18,8 v=-23,39
p=24,60 v=-76,-87
p=34,100 v=-88,-85
p=84,84 v=44,79
p=16,101 v=53,-64
p=44,33 v=88,-25
p=52,22 v=-43,-35
p=30,63 v=-23,-86
p=14,40 v=65,-50
p=56,98 v=-41,88
p=42,11 v=-14,-72
p=72,9 v=-4,-72
p=26,71 v=-47,-62
p=92,18 v=-71,15
p=81,40 v=59,7
p=79,69 v=16,64
p=4,40 v=24,-83
p=17,78 v=65,-32
p=87,85 v=81,-36
p=98,27 v=42,42
p=100,55 v=72,95
p=94,12 v=-80,61
p=73,34 v=96,-38
p=32,30 v=-63,-38
p=45,37 v=-27,-75
p=6,0 v=-72,-68
p=24,58 v=39,41
p=25,74 v=-26,-15
p=99,82 v=80,64
p=88,54 v=-94,-21
p=100,81 v=29,-28
p=84,87 v=56,6
p=71,17 v=-95,-96
p=37,89 v=-9,-18
p=42,30 v=-78,-59
p=92,17 v=-68,14
p=31,55 v=88,66
p=28,10 v=-13,-62
p=30,30 v=29,60
p=89,80 v=8,-42
p=23,75 v=41,-44
p=65,78 v=-55,42
p=1,80 v=-9,19
p=54,78 v=36,83
p=10,40 v=66,-95
p=67,71 v=8,58
p=23,17 v=12,69
p=36,70 v=76,21
p=7,63 v=-60,-65
p=39,96 v=87,41
p=8,56 v=-34,-90
p=64,66 v=9,79
p=2,61 v=4,17
p=64,51 v=28,-6
p=91,25 v=-41,69
p=92,3 v=-85,47
p=61,41 v=-90,57
p=86,61 v=-69,70
p=82,45 v=7,-13
p=23,39 v=-78,-40
p=58,3 v=-30,15
p=87,30 v=87,-25
p=21,84 v=39,34
p=36,26 v=89,-59
p=90,51 v=-83,-91
p=5,39 v=79,-87
p=5,63 v=66,-74
p=71,45 v=21,-21
p=49,40 v=-68,-66
p=68,93 v=96,96
p=67,96 v=46,51
p=72,44 v=-32,82
p=15,90 v=15,2
p=26,78 v=28,-44
p=7,3 v=-87,-39
p=74,101 v=94,-76
p=90,20 v=-6,-46
p=22,17 v=-68,-63
p=12,81 v=-37,14
p=37,84 v=-15,22
p=75,31 v=83,-63
p=48,2 v=-90,-27
p=44,94 v=-63,31
p=73,71 v=-50,22
p=22,101 v=39,51
p=49,94 v=-90,26
p=93,67 v=5,-12
p=57,83 v=-68,80
p=86,82 v=44,-32
p=3,64 v=87,-62
p=43,87 v=-20,-57
p=40,18 v=-8,-56
p=80,46 v=-89,57
p=79,26 v=-18,27
p=3,27 v=-98,77
p=99,44 v=42,-99
p=25,27 v=-72,23
p=98,24 v=43,85
p=54,93 v=-28,-60
p=29,4 v=86,80
p=42,96 v=-75,14
p=75,77 v=54,81
p=96,63 v=-46,-33
p=51,94 v=88,-69
p=31,88 v=51,39
p=75,15 v=-43,-84
p=8,18 v=93,63
p=20,65 v=99,30
p=71,5 v=72,-98
p=31,95 v=63,-19
p=87,70 v=-68,71
p=11,55 v=15,37
p=63,36 v=10,36
p=41,98 v=37,10
p=27,78 v=26,-36
p=53,93 v=30,18
p=78,25 v=-58,-80
p=21,100 v=-73,66
p=36,33 v=25,11
p=65,3 v=-92,-68
p=46,22 v=-64,48
p=49,87 v=-91,38
p=82,37 v=6,16
p=24,94 v=-30,-3
p=14,94 v=94,37
p=28,32 v=39,-1
p=35,19 v=-68,-25
p=3,51 v=-47,70
p=12,6 v=-29,-28
p=28,19 v=15,2
p=75,45 v=95,-67
p=76,4 v=7,-93
p=45,29 v=-63,-37
p=41,22 v=-64,93
p=67,45 v=10,-36
p=51,1 v=21,-74
p=25,84 v=1,-81
p=15,36 v=-47,-29
p=44,98 v=24,-81
p=79,30 v=45,94
p=45,57 v=12,-57
p=12,23 v=65,78
p=65,76 v=-68,17
p=100,100 v=79,23
p=75,22 v=58,-84
p=82,65 v=69,-74
p=76,6 v=-61,-61
p=61,38 v=27,53
p=68,94 v=86,37
p=64,71 v=6,-88
p=21,93 v=-53,-65
p=32,86 v=64,-98
p=11,11 v=-95,-95
p=36,32 v=-38,65
p=23,95 v=91,-65
p=31,33 v=12,-34
p=12,5 v=-99,-72
p=50,3 v=-91,-93
p=74,66 v=33,13
p=22,7 v=-12,-97
p=11,6 v=41,-43
p=14,16 v=-21,60
p=95,76 v=81,-61
p=3,55 v=79,99
p=43,97 v=-1,-60
p=73,66 v=31,-33
p=60,33 v=73,-57
p=63,57 v=71,-95
p=86,11 v=-20,-80
p=50,28 v=86,-34
p=66,5 v=-80,45
p=96,87 v=67,6
p=52,16 v=-53,40
p=31,31 v=38,32
p=96,23 v=-34,-72
p=46,64 v=-91,45
p=14,19 v=-73,60
p=31,85 v=12,-32
p=19,36 v=-36,-46
p=39,21 v=-52,15
p=98,34 v=-10,81
p=96,65 v=-9,1
p=97,75 v=-21,34
p=22,0 v=64,2
p=8,15 v=-24,36
p=67,1 v=61,-89
p=64,76 v=70,34
p=22,29 v=-74,-54
p=73,48 v=-41,-75
p=83,7 v=-82,-72
p=57,6 v=-66,-93
p=31,21 v=-50,81
p=90,21 v=-56,-35
p=79,73 v=54,77
p=62,64 v=60,29
p=51,70 v=-96,-6
p=35,71 v=75,-33
p=9,56 v=53,-58
p=63,48 v=-94,49
p=61,72 v=82,55
p=51,79 v=-66,5
p=2,62 v=46,-46
p=56,2 v=10,-64
p=42,74 v=-64,75
p=0,83 v=17,-61
p=3,59 v=-97,33
p=40,82 v=-15,47
p=89,8 v=94,19
p=76,26 v=-95,-23
p=4,86 v=79,76
p=4,32 v=-77,31
p=35,38 v=-9,-59
p=78,87 v=72,-57
p=72,72 v=-72,67
p=94,33 v=-2,-93
p=59,96 v=37,-19
p=90,24 v=-83,-1
p=88,61 v=69,50
p=67,28 v=35,-66
p=40,63 v=75,29
p=84,27 v=-42,-91
p=40,21 v=-31,-30
p=1,50 v=-34,-95
p=87,59 v=96,-94
p=36,19 v=-78,-68
p=5,43 v=-78,91
p=27,49 v=91,-99
p=61,85 v=11,14
p=89,61 v=-83,-97
p=31,78 v=-86,81
p=76,69 v=33,-82
p=74,28 v=-43,-71
p=23,27 v=-35,86
p=80,74 v=-33,-86
p=99,10 v=43,-10
p=59,55 v=-41,-95
p=89,94 v=58,43
p=72,87 v=7,67
p=68,73 v=-29,-57
p=1,46 v=80,41
p=45,33 v=36,-38
p=24,4 v=46,21
p=18,94 v=-35,5
p=82,45 v=53,74
p=93,75 v=-83,-86
p=14,3 v=51,-80
p=74,30 v=-30,-96
p=70,38 v=-29,-34
p=55,76 v=-94,-13
p=11,82 v=-10,38
p=11,55 v=-35,-4
p=93,76 v=6,-57
p=17,57 v=-80,-42
p=47,82 v=18,94
p=84,70 v=-84,1
p=48,94 v=-90,6
p=95,41 v=-51,57
p=18,53 v=55,-84
p=100,20 v=-20,-56
p=49,26 v=-17,34
p=31,62 v=92,-86
p=69,2 v=-81,82
p=76,43 v=-71,97
p=23,15 v=-62,97
p=26,23 v=-87,40
p=67,48 v=34,16
p=64,11 v=-54,85
p=85,58 v=8,-49
p=80,25 v=57,-6
p=45,35 v=49,-9
p=96,65 v=-20,-25
p=91,49 v=68,16
p=8,62 v=29,33
p=97,50 v=69,-85
p=52,53 v=-2,70
p=70,68 v=44,83
p=65,7 v=-17,39
p=45,14 v=-87,-34
p=94,47 v=-93,-46
p=29,84 v=70,11
p=70,73 v=-23,-6
p=100,51 v=45,18
p=21,2 v=-13,-19
p=67,32 v=-95,-82
p=61,2 v=-54,64
p=17,12 v=65,35
p=67,54 v=-74,-89
p=2,6 v=5,-92
p=26,77 v=-12,-28
p=39,77 v=12,-86
p=70,57 v=84,-83
p=8,88 v=-60,13
p=19,37 v=-38,-89
p=0,14 v=6,-2
p=24,59 v=-24,-82
p=5,13 v=-11,-47
p=21,27 v=88,23
p=89,75 v=-20,83
p=68,66 v=19,1
p=34,72 v=-74,25
p=27,70 v=14,-90
p=89,9 v=-44,2
p=5,67 v=-61,-36
p=52,13 v=-53,-84
p=50,21 v=-90,-9
p=21,16 v=2,64
p=69,21 v=-18,-88
p=64,85 v=-80,34
p=31,70 v=50,95
p=15,8 v=-23,52
p=97,52 v=28,41
p=85,6 v=8,-15
p=9,33 v=-74,52
p=46,59 v=90,96
p=71,50 v=-93,98
p=15,74 v=-24,-82
p=54,87 v=-15,-36
p=37,25 v=-15,7
p=92,13 v=86,78
p=90,14 v=20,-68
p=68,37 v=-5,4
p=58,56 v=48,-99
p=27,16 v=-36,-32
p=4,49 v=-58,65
p=5,50 v=-60,98
p=13,31 v=-48,-91
p=58,75 v=46,8
p=66,88 v=-6,-98
p=95,16 v=32,23
p=86,21 v=-57,-55
p=19,65 v=-32,-98
p=83,57 v=-46,-95
p=37,10 v=38,64
p=87,33 v=46,8
p=45,54 v=-53,-58
p=35,95 v=-39,-7
p=89,65 v=58,-45
p=82,80 v=-82,-65
p=35,7 v=25,76
p=66,92 v=-16,-44
p=75,89 v=-92,66
p=48,84 v=98,42
p=70,84 v=-30,-44
p=49,51 v=-92,28
p=27,85 v=62,-36
p=31,21 v=3,-64
p=61,101 v=-15,88
p=56,44 v=90,68
p=83,49 v=-95,-83
p=69,38 v=8,-92
p=34,13 v=-32,43
p=0,51 v=-75,25
p=39,36 v=76,69
p=66,59 v=70,-96
p=78,42 v=-31,-62
p=5,5 v=-33,-22
p=54,74 v=-12,44
p=25,26 v=25,85
p=74,88 v=-39,56
p=65,83 v=33,-28
p=87,90 v=95,30
p=71,20 v=-29,93
p=66,9 v=83,-96
p=38,51 v=50,41
p=66,87 v=44,46
p=30,31 v=-49,-14
p=70,32 v=73,28
p=0,94 v=95,26
p=87,80 v=-83,46
p=92,70 v=-58,99
p=48,67 v=-1,41
p=43,74 v=49,34
p=87,51 v=43,8
p=23,63 v=39,-86
p=2,77 v=48,7
p=32,60 v=-63,-37
p=99,3 v=-21,31
p=82,55 v=57,8
p=5,68 v=-46,-41
p=32,77 v=-38,88
p=84,0 v=6,-64
p=20,95 v=52,26
p=29,98 v=-16,83
p=44,81 v=-27,-73
p=43,40 v=-41,-42
p=24,73 v=-88,-49
p=99,45 v=-97,8
p=37,9 v=-31,-57
p=70,11 v=8,-39
p=0,11 v=96,57
p=83,70 v=70,75
p=65,71 v=-40,-65
p=82,66 v=73,-80
p=31,41 v=52,-96
p=19,72 v=65,75
p=24,4 v=-86,54
p=75,85 v=85,30
p=2,83 v=17,-7
p=9,87 v=-22,59
p=24,3 v=-12,21
p=5,74 v=-34,46
p=22,90 v=-37,-11
p=20,84 v=4,95
p=95,10 v=-96,-55
p=52,9 v=23,-14
p=20,51 v=-63,-75
p=64,27 v=24,48
p=50,2 v=-90,-68
p=54,47 v=23,70
p=26,22 v=51,-51
p=4,49 v=-72,-54
p=53,47 v=2,-86
p=21,29 v=-37,13
p=37,70 v=38,-40
p=6,41 v=43,-20
p=88,23 v=-38,-68
p=67,20 v=79,-71
p=37,7 v=24,25

103
2024/d15/ex1/ex1.py Executable file
View file

@ -0,0 +1,103 @@
#!/usr/bin/env python
import copy
import enum
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class Direction(enum.StrEnum):
UP = "^"
RIGHT = ">"
DOWN = "v"
LEFT = "<"
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.UP:
dx, dy = -1, 0
case Direction.RIGHT:
dx, dy = 0, 1
case Direction.DOWN:
dx, dy = 1, 0
case Direction.LEFT:
dx, dy = 0, -1
return Point(p.x + dx, p.y + dy)
class Object(enum.StrEnum):
BOX = "O"
WALL = "#"
Maze = dict[Point, Object]
def solve(input: str) -> int:
def parse_maze(input: list[str]) -> tuple[Point, Maze]:
robot: Point | None = None
maze: Maze = {}
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
if c == "@":
robot = Point(x, y)
continue
maze[Point(x, y)] = Object(c)
assert robot is not None # Sanity check
return robot, maze
def parse_directions(input: str) -> list[Direction]:
return [Direction(c) for c in input if c in Direction]
def parse(input: str) -> tuple[Point, Maze, list[Direction]]:
maze_input, directions_input = input.split("\n\n")
robot, maze = parse_maze(maze_input.splitlines())
directions = parse_directions(directions_input)
return robot, maze, directions
def step(robot: Point, maze: Maze, d: Direction) -> tuple[Point, Maze]:
# Maze a tentative step
new_robot = d.step(robot)
new_maze = copy.copy(maze)
# Try to move boxes along
if (blocker := new_robot) in new_maze:
# Try to move boxes up
while blocker in new_maze:
# We hit a wall, abort the movement
if new_maze[blocker] == Object.WALL:
return robot, maze
# Otherwise look at the next space along
blocker = d.step(blocker)
# Out of the loop, we must have found an empty space, so do the push
new_maze[blocker] = new_maze.pop(new_robot)
# Robot moved without hitting a wall
return new_robot, new_maze
def compute_coordinates(maze: Maze) -> int:
return sum(100 * p.x + p.y for p, obj in maze.items() if obj == Object.BOX)
robot, maze, directions = parse(input)
for d in directions:
robot, maze = step(robot, maze, d)
return compute_coordinates(maze)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

71
2024/d15/ex1/input Normal file
View file

@ -0,0 +1,71 @@
##################################################
#......O.O..O......O......O..OO...O..O.O.O..O..O.#
#....O.O..#.O....O#.#.#......O.O#O.O#O#..O.O.....#
#.........O..#O......O...OO..O..O..O#....O.......#
#.O.O......O#.#..#.#.........O...OOO.O..O..O....O#
#..O......O.......O..O.#O......OO.O.O#..O.OO..O..#
#O.O.....O.O......O....O..OO...#.#...O##OO#O.....#
#O..O....OOOO...#.O.O.O#.....##.....O#.##..O.....#
#O..O.O....O.#..O.O.OO#O.#..#.O....O..O.#.....O..#
##..OOOO..O..#O.#.O....O...............OO.....O..#
#O.O#.........OO..O..#..O.....O..O...O#.....O....#
#..#O#O#...#....O...OOOO..O.....#O.......O.......#
#..........O...O.....#OOOO#O..#..O..#O.........O.#
##..O.OO.O......#...#OOO.OO..O.O.O.OO#.#OO..O.OO.#
#....O.O..OO.O.OOO..OO...O...O..O.O.O....O...O...#
#O..#OO.........O#......OOO....O.....O.OO.#.O.##.#
#.O.OOO.....O....O...#O.O.O.#.O.O..........O...OO#
#.OO.OO...O...O..#........O.O...O.O...#OO.O....O.#
#OO...O.OO.#O.....OOO.#O#.O.#......OO.....OO#..O.#
#..O......O.....#...#O.....O.....OOO.....O.#OO...#
#.....#O..O..#...OOO.#O.O..O.O#...#OO.O......O..##
#..OO.OOO#.O.....OO..#.OO......OO.O....O...O.....#
#.O.OO..............#..O.....O.O...OO.....#.O#...#
#......OO.....OOO.O..O#OO...OO..O#..O..O.OO......#
#.#O....O....O..#O..O..O@..#..#...#......O.......#
#.#..O.O.OO...O.O#....O..#..O...OOOOO...#.OOO#...#
##O..O.O....#O....OO#O.#O......O.....O..O...#O...#
#...O...........O.#O..O.#...#.O.O.O...........#.##
#O#O.......O..O.....OO.#O.O.#OOOO#.O.O.O.O.......#
##O.O..OO...#.O..#.O.O..OOO.O.O#.....O.O..#.O.O.O#
#..OO...O..#O.O.#.OOO.....OO........#..OO.#...O.##
#O.#.#..#.O.O...O..O.#O..O.O.OO......O.OO.O...O.##
#.O.OO...OO.........#....O.OO.OO..O#O.#O........##
#.......O.......OO#...#....#.OOO#.#........#.O...#
#...O.O.#.O.O.........OOO.O.O...O....O....#...O#.#
#....O.O.......#.......#..O##.O.O.....O...O.O...O#
#.O.O.O..O#.O.O...##O#O...O.....#OO#O.O....O..O..#
#O.O.O.#..O...O.O.......#.OO..#..........O...O.O.#
#...O...O.....O....##......#..OO....##.O..OO.....#
#..OO..O..O..OOO.....#O..OO.O.OOOO.#.O...O.#.....#
#...O...O.O.O...O.#O.#.O...O#.#......O..OO..O.##O#
#...O.O#......OO.#.O.....OO..O.......#...#.O...#.#
##OO..#O.....OO..............#...O#..O#......OOO.#
##OOOO..O.#..O.O....O....O..O#.O#....O....O.O....#
#.....#......O...OOO.O........O....#O.OO.....OO.O#
#O.#....OO#....OO.O....#O#........#.#.OO.#.O...OO#
#.O.....O.OO.....OO...#O..OOO.O...OO....O.O##O...#
##O..OO.OO..#..O.O.O.##O......O..#....OOO....OO..#
#O..O....O.........OO#.#......OO...##.O.......O..#
##################################################
>v><^>^v^v^^v><><>^><>>v<><<^<><>>v<^><^>><<<^v<>v>^<v>>><<<<^^<<^v>vv><>>v^<^>^^^^>v<<^<<>v<^^>v^v>>^v^v<<vv>^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vv>>v^>vv<><<<^^><v>^^>^^v<^>^^^v<^^>>>^<^<>v<vv<<^^><^^v^vv<v<v^<^v<<v><^^^<v<>v<^<<v><^><><>v^v>>>^vv^<<^v<<><<<><^^^>>^<^v^v<<>v<v<^<^v^<<^<^>^v^v>v><^^>^>>^<<><v^><<^<<<>v^><>><^<v^v>>^<^<^v^<<<^>^<>^^<>>^<^v^v>v^><v^<>v^>>vv>>>^<>vv<><>^>>^><>>v><^>>>^><^v<vv

149
2024/d15/ex2/ex2.py Executable file
View file

@ -0,0 +1,149 @@
#!/usr/bin/env python
import copy
import enum
import sys
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class Direction(enum.StrEnum):
UP = "^"
RIGHT = ">"
DOWN = "v"
LEFT = "<"
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.UP:
dx, dy = -1, 0
case Direction.RIGHT:
dx, dy = 0, 1
case Direction.DOWN:
dx, dy = 1, 0
case Direction.LEFT:
dx, dy = 0, -1
return Point(p.x + dx, p.y + dy)
class Object(enum.StrEnum):
BOX = "O"
WALL = "#"
# Maze always contains the left part of the object
Maze = dict[Point, Object]
# WideMaze maps left and right side of an object to its (left, right) tuple
WideMaze = dict[Point, tuple[Point, Point]]
def solve(input: str) -> int:
def parse_maze(input: list[str]) -> tuple[Point, Maze]:
robot: Point | None = None
maze: Maze = {}
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
if c == "@":
robot = Point(x, y * 2)
continue
maze[Point(x, y * 2)] = Object(c)
assert robot is not None # Sanity check
return robot, maze
def parse_directions(input: str) -> list[Direction]:
return [Direction(c) for c in input if c in Direction]
def parse(input: str) -> tuple[Point, Maze, list[Direction]]:
maze_input, directions_input = input.split("\n\n")
robot, maze = parse_maze(maze_input.splitlines())
directions = parse_directions(directions_input)
return robot, maze, directions
def step(robot: Point, maze: Maze, d: Direction) -> tuple[Point, Maze]:
def widen_maze() -> WideMaze:
res: WideMaze = {}
for p in maze.keys():
right_p = Point(p.x, p.y + 1)
res[p] = (p, right_p)
res[right_p] = (p, right_p)
return res
def boxes_along(wide_maze: WideMaze) -> set[Point] | None:
def helper(current: Point) -> set[Point] | None:
# Return empty set if we hit the air
if current not in wide_maze:
return set()
# Query both sides of the object
left, right = wide_maze[current]
# Return None if we hit a wall
if maze[left] == Object.WALL:
return None
assert right not in maze # Sanity check
# Try to move both sides of the box recursively
res_left: set[Point] = set()
res_right: set[Point] = set()
# Only check next_left if not moving right
if (next_left := d.step(left)) != right:
if (try_left := helper(next_left)) is None:
return None
res_left = try_left
# And only check next_right if not moving left
if (next_right := d.step(right)) != left:
if (try_right := helper(next_right)) is None:
return None
res_right = try_right
# Both sides succeeded, return the set of boxes to move
return {left} | res_left | res_right
return helper(d.step(robot))
def move_boxes(boxes: set[Point]) -> Maze:
new_maze = copy.copy(maze)
# Do the move in two steps to avoid overwriting any values during movement
for box in boxes:
new_maze.pop(box)
for box in boxes:
new_maze[d.step(box)] = maze[box]
return new_maze
new_robot = d.step(robot)
# If we hit a wall, abort the step
if maze.get(new_robot) == Object.WALL:
return robot, maze
# If a box hits a wall, abort the step
if (boxes := boxes_along(widen_maze())) is None:
return robot, maze
# Otherwise move everything along the direction
return new_robot, move_boxes(boxes)
def compute_coordinates(maze: Maze) -> int:
return sum(100 * p.x + p.y for p, obj in maze.items() if obj == Object.BOX)
robot, maze, directions = parse(input)
for d in directions:
robot, maze = step(robot, maze, d)
return compute_coordinates(maze)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

71
2024/d15/ex2/input Normal file
View file

@ -0,0 +1,71 @@
##################################################
#......O.O..O......O......O..OO...O..O.O.O..O..O.#
#....O.O..#.O....O#.#.#......O.O#O.O#O#..O.O.....#
#.........O..#O......O...OO..O..O..O#....O.......#
#.O.O......O#.#..#.#.........O...OOO.O..O..O....O#
#..O......O.......O..O.#O......OO.O.O#..O.OO..O..#
#O.O.....O.O......O....O..OO...#.#...O##OO#O.....#
#O..O....OOOO...#.O.O.O#.....##.....O#.##..O.....#
#O..O.O....O.#..O.O.OO#O.#..#.O....O..O.#.....O..#
##..OOOO..O..#O.#.O....O...............OO.....O..#
#O.O#.........OO..O..#..O.....O..O...O#.....O....#
#..#O#O#...#....O...OOOO..O.....#O.......O.......#
#..........O...O.....#OOOO#O..#..O..#O.........O.#
##..O.OO.O......#...#OOO.OO..O.O.O.OO#.#OO..O.OO.#
#....O.O..OO.O.OOO..OO...O...O..O.O.O....O...O...#
#O..#OO.........O#......OOO....O.....O.OO.#.O.##.#
#.O.OOO.....O....O...#O.O.O.#.O.O..........O...OO#
#.OO.OO...O...O..#........O.O...O.O...#OO.O....O.#
#OO...O.OO.#O.....OOO.#O#.O.#......OO.....OO#..O.#
#..O......O.....#...#O.....O.....OOO.....O.#OO...#
#.....#O..O..#...OOO.#O.O..O.O#...#OO.O......O..##
#..OO.OOO#.O.....OO..#.OO......OO.O....O...O.....#
#.O.OO..............#..O.....O.O...OO.....#.O#...#
#......OO.....OOO.O..O#OO...OO..O#..O..O.OO......#
#.#O....O....O..#O..O..O@..#..#...#......O.......#
#.#..O.O.OO...O.O#....O..#..O...OOOOO...#.OOO#...#
##O..O.O....#O....OO#O.#O......O.....O..O...#O...#
#...O...........O.#O..O.#...#.O.O.O...........#.##
#O#O.......O..O.....OO.#O.O.#OOOO#.O.O.O.O.......#
##O.O..OO...#.O..#.O.O..OOO.O.O#.....O.O..#.O.O.O#
#..OO...O..#O.O.#.OOO.....OO........#..OO.#...O.##
#O.#.#..#.O.O...O..O.#O..O.O.OO......O.OO.O...O.##
#.O.OO...OO.........#....O.OO.OO..O#O.#O........##
#.......O.......OO#...#....#.OOO#.#........#.O...#
#...O.O.#.O.O.........OOO.O.O...O....O....#...O#.#
#....O.O.......#.......#..O##.O.O.....O...O.O...O#
#.O.O.O..O#.O.O...##O#O...O.....#OO#O.O....O..O..#
#O.O.O.#..O...O.O.......#.OO..#..........O...O.O.#
#...O...O.....O....##......#..OO....##.O..OO.....#
#..OO..O..O..OOO.....#O..OO.O.OOOO.#.O...O.#.....#
#...O...O.O.O...O.#O.#.O...O#.#......O..OO..O.##O#
#...O.O#......OO.#.O.....OO..O.......#...#.O...#.#
##OO..#O.....OO..............#...O#..O#......OOO.#
##OOOO..O.#..O.O....O....O..O#.O#....O....O.O....#
#.....#......O...OOO.O........O....#O.OO.....OO.O#
#O.#....OO#....OO.O....#O#........#.#.OO.#.O...OO#
#.O.....O.OO.....OO...#O..OOO.O...OO....O.O##O...#
##O..OO.OO..#..O.O.O.##O......O..#....OOO....OO..#
#O..O....O.........OO#.#......OO...##.O.......O..#
##################################################
>v><^>^v^v^^v><><>^><>>v<><<^<><>>v<^><^>><<<^v<>v>^<v>>><<<<^^<<^v>vv><>>v^<^>^^^^>v<<^<<>v<^^>v^v>>^v^v<<vv>^v^>v^v^^^>>vv<<><^^v<v^v<<<v^<v><<^>>^v<>vv^v<v<vv><<^^vvv<<^^v>^vv>v<v>>v>^v<^<^>^>><>><^>><>^>>v<vv<v^^<>^vv><v^<><>^vv^<<^>><<<>v^>^vv<v<^^^^^^<><v<<^vv^><>^<vv^<>v<>v<v<^<><<>^<v>v><<>^<<<^>vv<<^v^<<v>v<<v^v<v>v>v^<>^v<<v^><^>v^<>vv<v^^>>>>^v<v^><<vv^><v<>v^<^>^>v>>>>^^<<^<<<^^>>^><<v^>>^^^vv>^<<vvv<>v^<v^vv>vvv^<^>v>^<>>vv^^^><v>v<<vv<^<^vv>>>^v>>^>>^^^v<>^vv<<^<>vv>^<vv^>^<>v<^<<^>><>v><>vv<^v^>^v>>><<>^^<<<^><<^^^^>vv^^v^><<v^^v^v>v>^<^^<>v^><v^>^<>^<>>^<><^^<>><>^^^^v^v<<><^><^^v>v>>>>^^^>^^>^>vvv<>^>>v><vv<>^v>>^>^^v^v>^>^v^^>^<<<>v>vv<<<>><^><>><v^<><>>><>>>>>^<v><<>><>^><v><<>>^><^v><v>^<v>>v<vv>>>>vv^^^v^v<<<vv>^>vv^v^^^v><v^<>v<^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v^>^>>v>>><^><<^v><>><><v^<v<<>><^v<^>vv<v^<>v^<<^><<<^^>>v<^>>v>>v>>>^<v^v<v<<>v>^><<vv>vv><^>v>^v<v^v><^<^vv^<vv<^^v>^^v^v<v<>>>>>^v>>^>^>v<>^>^<v^<>>^^v>v<>^<><^^<v<v^><<^v>v><>v>^>^<>><>>^>v^<v>v<<<>^><^v<><v>^^^^v<><^^v^^<^v>^<<v^>^>><^v><><<^^^v>><^^<<^>^vv<<^<>>v<<>>><v>>>^<<v<<><v<^v<v^v<>>^>v<<v^<><<>v<^v^<vv>><vvv>v<^^<<^v<<^v><>^vv>v<><v^><v<^^<<<>v<<<^^v^><^^^^<^^v<<^<>v><>>v<vv<vv<v^v<<>><v^v>^v<><v<><v>v><>><^>^^^<v<<^^>>v<<<<v<<^v^vv>>v^>vv<><<<^^><v>^^>^^v<^>^^^v<^^>>>^<^<>v<vv<<^^><^^v^vv<v<v^<^v<<v><^^^<v<>v<^<<v><^><><>v^v>>>^vv^<<^v<<><<<><^^^>>^<^v^v<<>v<v<^<^v^<<^<^>^v^v>v><^^>^>>^<<><v^><<^<<<>v^><>><^<v^v>>^<^<^v^<<<^>^<>^^<>>^<^v^v>v^><v^<>v^>>vv>>>^<>vv<><>^>>^><>>v><^>>>^><^v<vv

118
2024/d16/ex1/ex1.py Executable file
View file

@ -0,0 +1,118 @@
#!/usr/bin/env python
import enum
import heapq
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class ParsedMaze(NamedTuple):
start: Point
end: Point
blocks: set[Point]
class Direction(enum.IntEnum):
EAST = enum.auto()
WEST = enum.auto()
NORTH = enum.auto()
SOUTH = enum.auto()
def rotations(self) -> tuple["Direction", "Direction"]:
match self:
case Direction.EAST | Direction.WEST:
return (Direction.NORTH, Direction.SOUTH)
case Direction.NORTH | Direction.SOUTH:
return (Direction.EAST, Direction.WEST)
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.EAST:
dx, dy = 0, 1
case Direction.WEST:
dx, dy = 0, -1
case Direction.NORTH:
dx, dy = -1, 0
case Direction.SOUTH:
dx, dy = 1, 0
return Point(p.x + dx, p.y + dy)
Node = tuple[Point, Direction]
def solve(input: str) -> int:
def parse(input: list[str]) -> ParsedMaze:
start: Point | None = None
end: Point | None = None
blocks: set[Point] = set()
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
p = Point(x, y)
if c == "S":
start = p
elif c == "E":
end = p
elif c == "#":
blocks.add(p)
else:
assert False # Sanity check
assert start is not None # Sanity check
assert end is not None # Sanity check
return ParsedMaze(start, end, blocks)
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int:
def next_moves(
pos: Point,
dir: Direction,
) -> Iterator[tuple[int, Point, Direction]]:
transitions = [(1, dir.step(pos), dir)]
for new_dir in dir.rotations():
transitions.append((1000, pos, new_dir))
for cost, pos, dir in transitions:
if pos in blocks:
continue
yield cost, pos, dir
# Priority queue of (distance, point, direction)
queue = [(0, start, Direction.EAST)]
seen: set[Node] = set()
while len(queue) > 0:
cost, p, dir = heapq.heappop(queue)
if p == end:
return cost
# We must have seen (p, dir) with a smaller distance before
if (p, dir) in seen:
continue
# First time encountering (p, dir), must be the smallest distance to it
seen.add((p, dir))
# Add all neighbours to be visited
for n_cost, n, n_dir in next_moves(p, dir):
heapq.heappush(queue, (cost + n_cost, n, n_dir))
assert False # Sanity check
start, end, blocks = parse(input.splitlines())
return djikstra(start, end, blocks)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

141
2024/d16/ex1/input Normal file
View file

@ -0,0 +1,141 @@
#############################################################################################################################################
#.......#...#.....#.......#.........#.#.............#...........#.......#...............#.........#...........#...#.......#.......#.......#E#
#.#####.#.###.#.#.#.#.#.#.#.#.#####.#.#.###.###.###.###.#####.#.###.#.#.#.#####.#######.#.#######.#####.#####.#.#.#.###.#.#.###.#.#.#.###.#.#
#.....#.#.....#.#.#.#.#...#.#.....#...#.#...#...#.#...#.#.....#...#.#.#.....#...#...#...#...#...#.#.....#...#.#.#...#.....#.#...#.#.#.#.....#
#.###.#.#.#####.###.#.#.###.#####.#.###.#.#.#.###.###.###.#######.#.#.#######.###.###.#####.#.#.#.#.#####.#.#.#.#####.#######.#.#.###.#####.#
#.#.................#.#.#...#...#.#.#...#.#.#.#.....#.....#...#...#...#.......#.......#.....#.#.#.#.......#.#.#...#...........#.......#...#.#
#.#.#.#.#####.#######.#.#.###.###.#.#.###.#.#.#.#.#.#######.###.#######.#########.#####.#####.#.#.#######.#.#.###.#.###########.#####.#.#.###
#...#.#...#.#.#...#...#.#.#...#...#.#...#.#.#.#.#...........#...#.......#...................#.#.#.......#.#.#.....#.#.........#.......#.#...#
###.#.###.#.#.#.###.#.#.#.###.#.#######.#.#.#.###.###.###.#.#.#####.#.###.#.###.#.#########.#.#######.#.###.###.#####.#######.#.#####.#.###.#
#...#...#.#...#.#...#...#.#...#...#...#.#.#.#...#...#.#...#...#.....#.....#.....#.......#...#.#.......................#.....#.......#...#.#.#
#.#.###.#.#.###.#.###.#.#.#.#####.#.#.#.#.#.###.#.#.###.#######.#####.#####.###.#######.#.###.#.#.###.#.#.#######.#######.#.#######.#.###.#.#
#.#.....#.#...#.#.........#.....#...#.#.#.........#...#.....#.#.......#...#...#...#.....#.#.#...#...#...#.......#...#.....#.#.............#.#
#.#######.###.#.#####.#.#.###.#.#####.#.#.#######.###.#####.#.#.#####.#.#.###.#.#.#.#####.#.#.#####.#.###.#####.###.#.#.###.#.#.#.###.#.#.#.#
#.....#...#.........#...#.....#.#...#...#.#.....#.#.#.....#.#.....#...#.#.....#.#.#.#.....#.#...#...#.#.......#...#.#.#.#.....#.#...#.#...#.#
#####.#.###.#########.#.#.###.###.#.#.###.###.#.#.#.#####.#.#####.#.#.#.#######.###.#.#.###.###.#.###.#########.###.#.#.#######.###.#.###.#.#
#.....#.#.......#.....#.....#.#...#.#...#...#.#...#.......#.........#.#.#...#.......#.#...#.....#...#.#.......#...#.#.#.#.......#.#.#.......#
#.#####.###.###.#.#########.###.###.#####.#.#.###.###.#.#####.#.#######.#.###.#.#####.###.#########.#.#.#####.#.#.#.#.#.#.#######.#.#.#####.#
#.#.....#...#...#.......#.#.#...#.....#.....#.#.......#.#...#.#...#...#.#...#.#.......#.#.#.....#...#...#...#.#.#...#.#.#.......#.#.#.....#.#
#.###.###.#.#.###.#####.#.#.#.#######.#.#####.#.#######.#.#.#.#.###.#.#.#.#.#.#####.###.#.#.###.#.#######.###.#.#######.#######.#.#.#.###.#.#
#...#...#...#.#...#.....#...#.#...#.#...#...#.#...#...#...#...#.#...#.#.#.#...#...#...#.#.....#.#.......#.#...#.........#.....#.#.#...#.....#
#.#.###.###.#.#####.#####.###.#.#.#.#######.#.###.#.#.#########.#.###.#.#.#####.#.###.#.#######.#.#.###.#.#.###########.###.#.#.#.###.#####.#
#.#...#.....#.......#.........#.#.#.........#...#...#...........#.#.....#...#...#.#...#.#.....#.#.#.#.#.#.#.......#...#...#.#.#.#.#.........#
#####.#.#.#.#########.#######.#.#.###.#########.#.#############.#.#########.#.###.#.###.#.###.#.###.#.#.#.#######.#.#.###.#.#.#.#.#.#.#.#.#.#
#.....#...#...............#...#.#...#.........#.#...#.....#...#.#.......#.#.#.#...#.#...#.#...#.#...#.......#.....#.#.#...#.#.#.#.....#.#.#.#
#.#####.###.#####.###.#.###.#.#.###.###.###.###.###.#.###.#.#.#.#######.#.#.#.#.###.#.###.#.###.#.###########.#####.###.#####.#.#####.#.#.#.#
#.....#...#.....#...#.#...#.#.#...#...#...#...#.....#.#.....#.......#...#.#.#.#...#...#...#.#...#.#.....#...#.....#...#.......#.#...#...#.#.#
#####.#.#.#.###.###.###.#.#.#.###.###.###.###.###.#.###.#.#.#.#####.#.###.#.#.###.###.#.###.#.###.#.###.#.#.#####.###.###.#####.#.#.#.#.#.###
#.....#.......#.#.#...#.#.#...#.....#.#...#.#.#...#.....#...#.#.....#.#...#.#.#.......#.#.#...#...#...#...#.....#...#.....#...#...#.#.#.#...#
#.#####.###.#.#.#.###.###.#.###.#####.#.###.#.#.###########.#.#.#.###.#.###.#.#####.###.#.#####.###.###########.###.#######.#.#.###.#.#.###.#
#...........#.#.....#...#...#...#.#.........#.#...........#...#.#.....#.....#.#...#...#.#.....#...#.#.............#...#.....#.#...#.#...#.#.#
#.#####.###.#######.###.#####.###.#.###.#####.###.#####.#.#.#.###.#####.###.#.#.#.###.#.#####.#.#.#.#.###.###########.#.#####.###.#.#.#.#.#.#
#.#...#...#...........#.....#.....#.#.#.#...#.....#...#...#.#.....#.#...#...#...#.#.#.#.....#.#.#.#.#.#...#.........#...#...#.#...#.....#.#.#
#.###.#.#.#.#############.#.###.###.#.#.#.#.#.#.#.#.#.#.###.#######.#.#####.#.###.#.#.#####.#.#.#.#.#.#.###.#######.#####.#.#.#.#####.#.#.#.#
#...............#.......#.#.....#...#.#.#.#.#.#.#...#.#...#.#...#...#.#.....#.#.#.#.#...#...#...#...#.#...#.................#.#...#.......#.#
#######.#######.#.#.###.#.#######.###.#.#.#.###.#########.#.#.###.#.#.#.#.###.#.#.#.###.#.#########.#.###########.#########.#.###.###.#.###.#
#...#...#.#...#.#.....#.#...#...#...#...#.#...#.....#...#...#.#...#.#.#.#...#...#.#.#...#.#...#...#.#.........#...#.....#...#...#.......#...#
#.#.#.###.#.#.#.#.#.#.#.###.###.###.###.#.###.###.#.#.#.#####.#.###.#.#.###.###.#.#.#.###.#.#.#.#.#######.###.#.###.###.#.#.###.#######.#.###
#.#...#...#.#.#.#.#...#.#.........#...#.#...#...#...#.#.#.....#.#.#...#...#.....#.#.....#...#...#.......#...#.#...#.#.#.#.#.#...#...#...#...#
#.#####.#.#.#.#.###.###.#############.#.###.###.#.#.#.#.#.###.#.#.###.###.#######.#####.#.#############.#.###.###.#.#.#.#.###.#####.#.#.###.#
#.#.....#...#...#...#.#.........#.....#.#.#.#.#...#...#.......#.#...#...........#...#...#...#.....#...#.#.......#...#...#.....#...#...#...#.#
#.#.#############.###.#########.#.#####.#.#.#.#.#.###.#####.###.#.#.#.#######.#.###.#.#####.#####.#.#.#.#.#.#########.#########.#.#.###.#.#.#
#.......#.....#.....#...#.....#.#...#.#...#.....#...#...#...#...#.#...#.......#.....#...#.......#.#.#...#.#.........#...#.......#...........#
#.###.#.#.#.#.#####.#.#.#.#.###.###.#.###.#####.###.###.#.###.#########.###############.#######.#.#.#####.#####.#######.#####.###.#####.#.#.#
#.#...#...#.#...#...#.#...#...#...#.#.#.......#...#...#.#.....#.....#...#.#.....#.....#...#.......#.#.....#...#.......#...#...#...........#.#
#.#.#######.###.#.###.#######.###.#.#.#.#########.###.#.#########.#.#.###.#.###.#.###.###.###.#####.#####.#.#.#####.#####.#.###.#######.###.#
#.#.........#...#.....#.....#.....#.#...#.......#...#.#...#.......#...#.#...#.#...#.#.......#.#...#.....#...#.#...#.....#...#.#...#.........#
#.###########.#####.#.#.###########.#####.###.#####.#.###.#.###########.#.###.#####.#######.###.#.#####.#####.#.#.#####.#####.###.#.###.###.#
#...............#...#.#...........#.....#...#.#.....#...#...#.........#...........#...#...#...#.#...#...#...#...#.#...#.........#...#.....#.#
#.###.#.#####.#.#.###.#####.#.###.###.#.###.#.#.#.#.###.###.#.#######.#####.#####.#.#.#.#.###.#.###.#.#.#.#######.###.#########.#.###.#.###.#
#...#...#.#...#...#.#.....#.#...#...#.#.....#.....#.....#...#.#.....#.....#.#...#.#.#...#.#.....#.#...#.#.......#.....#...............#.#...#
###.#.###.#.#.#####.#####.#####.###.#.#############.#.#######.#.###.#####.###.#.#.#.#.###.#######.#####.#.#.#########.#.#########.###.#.#.###
#...#.....#.#...#.......#.......#.#.....#.....#...#.#.#.....#...#.#.#...#...#.#.#...#...#...#...........#.#...........#...#...........#...#.#
#.#.###.###.#.#.#.#.###.#########.#.###.#.###.#.#.#.#.#.###.###.#.#.#.#.###.#.#.###.#.#####.#######.#.###.#########.#.###.#.#####.#####.###.#
#.........#.#.#.#.#.#.....#.......#.#.#...#...#.#...#.#.#.#...#.....#.#...#...#...#...#.....#.......#.#...#.......#.....#.#.#.........#.#...#
#.#.###.#.#.#.#.#.#.#######.#####.#.#.###.#.###.#.###.#.#.###.#.#####.###.#######.#.###.#####.#######.#.#####.###.#######.#.###.#.#####.#.#.#
#...#...#.#...#...#...#...#...#...#.#.......#...#.#...#...#...#.#...#.#...#.....#.#...#.....#.....#...#.....#...#.#.....#.#.....#.#.....#.#.#
#.###.#.#.###.###.#.#.#.#.###.#.###.#########.###.#.#####.#.###.#.#.#.#.#.#####.#.###.#####.#.###.#.#######.###.###.###.#.#######.#.###.#.#.#
#.....#.#.......#.......#.....#...............#...#...#.#.#.....#.#...#.#.......#...#.#.#...#.#...#...#.........#...#.#...#.#.....#.#.....#.#
#######.#####.#.###.#.#####.#.#################.#.###.#.#.#########.###.#######.#.###.#.#.#####.#######.#########.###.#####.#.###.#.#.#.###.#
#.......#.....#...#.#.#...#...#...............#.#...#.#.#...#.....#.....#.....#.........#.#.....#.......#.....#...#...#.....#...#.#.#.#.....#
#.#####.#.###.#.###.#.#.#########.#.#.###.#.###.#.###.#.###.#.#.#.###.#####.#.#.###.#####.###.###.#######.###.#.###.#.#.#.#####.#.#.#.#.#####
#...#.....#.#.......#.#...........#.#...#.#.........#...#.#.#.#.#...#.....#.#...#.....#...#...#...#.......#.#...#...#...#.#.................#
###.#.#.###.#.#.#####.#.#####.#####.###.#.#.#######.###.#.#.#.#.###.#####.###.###.###.#.###.###.###.#######.#####.#######.#.#######.#.###.#.#
#...#.#...............#.#.....#.....#...#.#.#.......#...#.#.#.#.#.......#...#.#...#.#...#.........#.#.........#...#.......#.#.#.....#.....#.#
#####.#.#####.#########.#.#####.#####.###.#.#.#####.#.###.#.#.#.#######.###.#.#.###.###########.###.#.#.#####.#.###.###.###.#.#.#####.#####.#
#.....#.#.........#.....#.#.#...#.........#.#...#...#.#...#.#.#...#.#...#...#.#.#.........#...#.#...#.#...#...#...#...........#...#.......#.#
#.#####.#.###.###.#######.#.#.#.#.#####.#.###.#.#.###.#.#.#.#####.#.#.###.#####.#.#.#.###.#.#.###.#######.###.###.#.#############.#########.#
#.#...#...#.....#.....#...#.#...#...#...#...#.#.#...#.#.#.#.#.....#.#.....#.....#...#...#.#.#.....#.....#.........#.......#.#...#...#.......#
#.#.#.#####.###.#####.#.###.#.#####.###.###.###.#####.#.###.#.#####.#####.#.###########.#.#.#######.#.#.###.#.###########.#.#.#.###.#.#####.#
#.#.#.........#...#...#.#...#.#...#.#.....#...#...........#.#.....#.......#.#...........#.#.#.......#.#.......#...#...#.....#...#...#.#.#...#
#.#.###########.#.#.###.###.#.#.#.#.#.###.###.#.###.#####.#.#####.#.#######.###.#########.#.#.#####.#.#######.#.#.#.#.#.#####.#.#.###.#.#.###
#.#...#.........#.#.#.....#...#.#...#...#.#...#.#.........#.......#...#...#.#...#...#...#...#.....#.#.........#.#...#...#.....#...#...#...#.#
#.###.#.#########.#.#####.#####.#####.#.#.#.###.#.###############.###.###.#.#.#.#.#.###.###########.###########.#########.#########.#.#.###.#
#...#.#.........#.#.....#.....#.....#.#.#.#.#.....#.....#...#.........#.#...#.....#...#...........#...........#.#.....#...#.........#.#.....#
#.###.#########.#.#####.#####.#####.#.#.#.#.#.#####.###.#.#.#.#.###.#.#.#############.#.#########.###########.#.#.###.#.#.#.#########.#####.#
#.....#.......#.#.................#.#.#.#.#.#.#...#.#.#...#...#...#.#.#...............#...#...#.#.........#...#...#.#...#.#.......#...#...#.#
#.#####.#######.###.###############.#.#.#.#.###.#.#.#.###########.#.#.###.#############.#.#.#.#.#########.#.#.###.#.###.#.#######.#.###.#.###
#.......#.....#...#.#...#...........#.#.#.#.#...#.#.#...#.........#.#.#...#.....#.....#.#...#.#.............#.#.#.....#.#...#...............#
#.#####.#.###.###.#.#.###.#############.#.#.#.###.#.#.#.#.#########.#.#.#.#.###.#.#####.#####.#.#####.#######.#.#.#.#.#.###.###.#.#######.#.#
#.......#...#.#...#...#...#.........#...#.#...#...#.#.#.#...#.#.......#.#.#...#.#.....#.....#.#.#...#...#...#...#.#.#.#.#.#...#.....#...#.#.#
#.#########.#.#.#####.#.#######.###.#.###.#####.###.#.###.#.#.#.#####.#.#####.#.###.#.#####.#.###.#.#####.#.#####.#.###.#.###.#######.#.#.#.#
#.#.....#...#...#...#.#.......#.#.#...#.#.#...#.....#...#.......#.....#.......#...#.#...#...#.#...#...#...#...#...#.....#...#.#.......#.#.#.#
#.#.###.#.#.###.#.#.#.#######.#.#.#####.#.#.#.#######.#.#.###.###.#####.#########.#####.#.###.#.#####.#.#####.#.###.#####.###.#.#######.###.#
#.#.#.....#.#.....#.#.#.........#.#.....#...#.#.....#.#.#...#.....#...#...#...#.#.....#.....#.#.#...#...#...#.#...#.......#...#...#...#.#...#
#.#.#.#######.#####.#.#.#.#######.#.###.#####.#.#####.#.###.###.###.#.###.#.#.#.#####.#####.#.#.###.#.#.###.#.###.###.###.#.#####.#.#.#.#.###
#.......#...#...#.#.#.#.#.........#...#.........#.....#...#...#.#...#...#...#.#.....#...#.#.#.#.....#.......#...#...#.#...#.#.....#.#...#...#
#.#.#####.#.###.#.#.###.###.#.#####.#.#########.#.#.###.#####.#.#.###.#.#####.#.###.###.#.#.#.#####.#####.###.###.#.###.#.#.#.#####.###.#.#.#
#.#.#.....#...#...#.#.......#.#.....#.#.#.......#.#...#.....#...#...#.#...#...#...#.#.#.#.#.#.....#.#.......#.#...#.#...#.#.#.#.......#...#.#
#.###.#######.###.#.#.#####.###.#.###.#.#.#.#.###.#.#.#####.#######.#.###.#.#.###.#.#.#.#.#.#####.#.#.#####.#.#.#.#.#.#.###.#.#.#####.#.###.#
#.....#.....#.....#.....#...#...#.#...#...#.#.#...#.#.....#...#.#...#...#.#.#.....#...#.#...#...#.#.#.#.....#...#.#...#.#...#.#.....#...#...#
#######.#.###############.#.#.###.#.#######.#.#.#####.###.#.#.#.#.#####.#.#.###.#######.#.###.#.#.#.###.#####.###.#####.#.###.#####.###.#.###
#.....#.#.............#...#.#...#.#...#.....#.#.....#.#.#.#.#...#.....#.#.#.....#.......#.#.#.#...#.....#...#.........#.#.#.....#.......#...#
#####.#.#.###.#######.#.#######.#.###.#.#####.#####.#.#.#.#.###.#####.#.#.#####.#.#######.#.#.#######.###.#.#####.#####.#.#.#.#.#######.###.#
#.....#...#...#...#...#.........#...#.#.......#...#...#...#...#.#.....#.#...#.#.#...#...#...#.............#.....#.........#.#.#...#...#.....#
#.###.###.#.###.#.#.#.#############.#.#.#####.#.#.#####.#####.###.#####.###.#.#.###.#.#.###.###########.#######.#########.#.#.###.#.#.#.#####
#...........#...#.#.#.....#...#...#...#.#...#...#...#...#...#...#...#...#.....#.#.#.#.....#.#.....#...#.#...#.#.......#...#.....#...#...#...#
#.#######.#.#.###.#.#####.#.#.#.#.#######.#.#.#####.#.###.#.###.#.###.#########.#.#.#.###.#.#.#####.#.#.#.#.#.#####.#.#.###.#########.#.#.#.#
#.....#...#.#...#.#.......#.#.#.#.........#.#...#...#.....#.#.#...#...#.....#...#.#...#.#.#...#.....#.#...#.#.......#.....#...#.....#.#...#.#
#####.#.#.#.#####.#######.#.#.#.###.#.#####.#####.#########.#.#.###.#.#.###.#.###.#####.#.#####.#####.#####.#######.#.###.#####.###.#.#.###.#
#...#...........#.#...#...#.#...#.#...#.........#.....#.....#.....#.#.#...#.#.#.........#.......#...#.....#.......#.#.....#.....#.#.#.....#.#
#.#.#####.#.#.#.#.#.#.#.###.#####.#.#####.#####.#####.#.#.#####.###.#####.#.#.#.#######.#.#########.#.###.#######.#.#######.#####.#.###.###.#
#.......#.#.#.#.#...#...#.#.#...#.#.....#.....#.......#.#.....#...#.....#.#...#.....#.#.#...........#.#...........#.......#.#...#.....#.....#
#.#####.#.###.#.#.#######.#.#.#.#.#####.#.###.#########.#.###.###.###.###.#########.#.#.#.#####.#####.#.###########.#.###.#.#.#.#####.#.###.#
#.#...#.#.#...#.#.......#.#...#...#...#.#.#.#...........#...#.....#.#.#...#.........#...#.#.#...#.....#...#.......#...#.#.#.#.....#.#.#.#...#
#.#.#.#.#.#.###.#.#####.#.#######.#.#.#.#.#.###############.#####.#.#.#.###.###.#####.#.#.#.#.###.###.###.###.#.#.#.###.#.#.#.###.#.#.#.###.#
#...#...#.#.#.#...#...#...#.......#.#.....#...............#.....#...#...#.#.#...#.....#.#.#.....#.#.#...#...#.#.#...#.....#.#.....#.#.......#
#.#####.#.#.#.#.###.#.###.#.#######.#.#####.#.###########.#.###.#####.###.#.#.###.#####.#.#.#####.#.###.###.###.#####.#####.###.#.#.#.###.#.#
#.#...#...#.#.#.....#...#.#.........#.......#.......#.......#.#.........#...#.#...#.....#.#...#...#.......#...#.#.....#.......#.#.#.#.#...#.#
#.#.#.###.#.#.#########.#.#####.###.#########.#.#####.#####.#.#######.###.###.#.###.#####.#.###.#.#######.###.#.#.#####.#######.#.#.#.#.#####
#.#...........#...#.#...#...#...#...#...#.....#.......#.............#.#...#...#...#.......#.#.....#.........#...#...#...........#.#...#.....#
#.#.#.#######.#.#.#.#.#.###.#.###.###.###.#############.#############.#.###.###.#.#.#########.###.#.#.#####.#######.#.###########.#.#.#.###.#
#...#.#.....#...#.#.#...#...#.#.....#.#...#...........#.#...........#.#.#.#.#.#.#...#.....#...#...#.#.....#...#...#.#.#...#...#...#...#...#.#
#.###.#.#.#######.#.###.#####.#.###.#.#.###.#####.###.###.#####.#.#.#.#.#.#.#.#.#####.###.#.#.#####.#####.#####.#.#.#.#.#.#.###.#####.#####.#
#...#.#.#.......#...#.#.#...#.#.#...#.#...#...#.......#...#.....#.#...#...#.#...#...#.#.....#.#.....#.....#...#.#...#...#...#...#...........#
#####.#.#######.#.#.#.#.#.#.#.#.#.###.###.###.###.#####.#####.###.#####.#.#.###.#.#.#.#########.#####.###.#.#.#.#######.###.#.###############
#.....#.#...#...#...#.#.#.#.....#.#.........#...#.#...#.....#.....#.....#.#...#...#.#.#.........#...#.#...#.#...#...#.....#.#.#.............#
#.###.#.#.#.#.###.###.#.#.#####.#.#########.###.#.#.#.###.#.#######.#.###.###.#####.#.#.###########.#.#####.#######.#.#.###.#.#.###########.#
#...#.#.#.#.#.....#...#.#...#...#.........#.#...#...#...#.#.......#.#.....#.#.#.....#...#.....#.....#.......#.....#...#.#...#.......#.......#
#.#.#.#.#.#########.#.#.###.#############.#.#.#########.#.#######.#.#######.#.###############.#.#.###.#######.###.###.#.#.#########.#.#.#.#.#
#.#.#.#.#...........#.#...#.#...#.......#.#.#.#.....#.#.#.......#.....#.........#...........#...#.#.........#...#...#.#...................#.#
#.#.###.#.#######.###.###.#.#.#.#.#####.#.#.#.#.###.#.#.###.#########.#.###.###.#.#.###.###.#####.#.#####.#.###.#.#.#.#########.#.#.#.#.###.#
#.#.....#.#.....#.#.....#.#.#.#...#...#.#.#.#...#...#.#.#...#.......#...#.#...#...#.....#.#.#...#.......#.#.#...#...#.#.........#.#...#.#...#
#.#######.#.###.#.###.#.#.#.#.#####.###.#.#.#.###.###.#.#.###.#####.#####.###.#####.###.#.#.#.#.#####.###.#.#.###.#####.#########.#######.#.#
#...#.....#.#...#...#...#.#...#...#.....#.#.#...#.#.....#...#.#...#.#...#.........#.#.#.....#.#...........#...#.#.......#.......#.....#...#.#
###.#.#####.#.#####.###.#.#######.#.#####.#.#####.#.#####.###.#.###.###.#.#####.###.#.#.###.#.#############.#.#.#########.#####.#####.#.###.#
#.#.#.....#.#.#...#...#.#...#.....#.#.....#.......#...#...#...#.......#.........#...#.#.#.......#.........#...#.....#.....#.#...#.....#...#.#
#.#.#####.#.#.#.#.###.#####.#.#.#.#.#.#.###########.#.#.###.#########.#######.#.#.###.#.#.#.###.#########.#######.#.#.#####.#.###.#######.#.#
#...#...#.#.#...#.#...#...#.#.#.#.#.#.#.#...#.........#.#...#.....#...#.....#...#...#...#.#...#.#...#.......#.....#...#.......#...#.......#.#
#.#.#.#.#.#######.#.###.#.#.#.#.###.#.#.#.#.#######.#.###.###.###.#.###.###.#######.#.###.#.#.#.#.#.#.#####.#.#########.#######.###.###.###.#
#.#...#.#...#...........#.........................#.....#...............#.#.........#.#...#.#.#...#.#...#.#.#...#.....#.#.......#.....#...#.#
#.#.###.###.#.###.###.###.###########.#.#.#######.#.###.###.###.#.#.#.###.###########.#####.#.###.#.#.#.#.#.###.#.#####.#.#######.#######.#.#
#...#...#...#.#.#.#...#.........#...#.#.#.....#.#.....#...#.#...#.#...#.............#.#.....#...#.#.#.#.#.......#.......#.........#.......#.#
###.#.###.###.#.#.#.#.#.#######.#.#.#.#.#####.#.#####.###.#.#.#.#.#######.#####.#.###.#.#.#.###.#.#.###.#######.#####.#####.###.#.#.#######.#
#...#.#.#.....#...#.#...#.....#.#.#...#.#.........#...#.#.#.....................#...#...#...#.#.#.#...#.....#.#.#...#.......#...#.#...#...#.#
#.#.#.#.#.#####.###.#.###.###.#.#.#######.#######.#.###.#.###.#.###.#.#.###.#.###.#.#######.#.#.#####.#.###.#.#.#.#.#######.#.#######.#.#.#.#
#.....#...#...#...#.#.....#...#.#.........#.....#.#.#.#...#.......#...#...#.#...#.#...........#.....#.#...#.#...#.#.......#.#...#...#...#.#.#
#.#.#######.#.#####.#.#.#####.#.#####.#####.###.###.#.#.###.#.###########.#.###.#.#####.###.#.#####.#.###.#.#####.#######.#.#.#.#.#.#####.#.#
#.#.....#...#.#.....#.#.#...#.#.....#.....#.#.#...#.#.#...#...#.......................#...#...#...#.#...................#.#...#.#.#.#.......#
#.###.#.#.###.#.#####.#.#.#.#######.#######.#.###.#.#.###.###.#.#######.#####.###.#.#.###.#.###.#.#.###.#.#.#.#####.###.#.#####.#.#.#.#####.#
#S....#...#.....#.....#...#.................#.......#...........#.............#.....#...#.......#.....................................#.....#
#############################################################################################################################################

149
2024/d16/ex2/ex2.py Executable file
View file

@ -0,0 +1,149 @@
#!/usr/bin/env python
import enum
import heapq
import sys
from collections import defaultdict
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
class ParsedMaze(NamedTuple):
start: Point
end: Point
blocks: set[Point]
class Direction(enum.IntEnum):
EAST = enum.auto()
WEST = enum.auto()
NORTH = enum.auto()
SOUTH = enum.auto()
def rotations(self) -> tuple["Direction", "Direction"]:
match self:
case Direction.EAST | Direction.WEST:
return (Direction.NORTH, Direction.SOUTH)
case Direction.NORTH | Direction.SOUTH:
return (Direction.EAST, Direction.WEST)
def step(self, p: Point) -> Point:
dx: int
dy: int
match self:
case Direction.EAST:
dx, dy = 0, 1
case Direction.WEST:
dx, dy = 0, -1
case Direction.NORTH:
dx, dy = -1, 0
case Direction.SOUTH:
dx, dy = 1, 0
return Point(p.x + dx, p.y + dy)
Node = tuple[Point, Direction]
def solve(input: str) -> int:
def parse(input: list[str]) -> ParsedMaze:
start: Point | None = None
end: Point | None = None
blocks: set[Point] = set()
for x, line in enumerate(input):
for y, c in enumerate(line):
if c == ".":
continue
p = Point(x, y)
if c == "S":
start = p
elif c == "E":
end = p
elif c == "#":
blocks.add(p)
else:
assert False # Sanity check
assert start is not None # Sanity check
assert end is not None # Sanity check
return ParsedMaze(start, end, blocks)
def count_path_cells(start: Point, end: Point, blocks: set[Point]) -> int:
def next_moves(
pos: Point,
dir: Direction,
) -> Iterator[tuple[int, Point, Direction]]:
transitions = [(1, dir.step(pos), dir)]
for new_dir in dir.rotations():
transitions.append((1000, pos, new_dir))
for cost, pos, dir in transitions:
if pos in blocks:
continue
yield cost, pos, dir
def get_all_predecessors(
predecessors: dict[Node, set[Node]],
) -> set[Point]:
queue = {(end, dir) for dir in Direction}
visited: set[Node] = set()
while queue:
cur = queue.pop()
visited.add(cur)
for pred in predecessors[cur]:
if pred in visited:
continue
queue.add(pred)
return {p for p, _ in visited}
# Priority queue of (distance, point)
queue = [(0, start, Direction.EAST)]
seen: set[Node] = set()
predecessors: dict[Node, set[Node]] = defaultdict(set)
predecessor_cost: dict[Node, int] = {}
# Use an invalid maximum cost to simplify the loop
max_cost: int = -1
while len(queue) > 0:
cost, p, dir = heapq.heappop(queue)
# Did we go past the optimal cost, if so stop the loop
if max_cost > 0 and cost > max_cost:
break
# Otherwise, record the minimum cost
if p == end:
max_cost = cost
# We must have seen (p, dir) with a smaller distance before
if (p, dir) in seen:
continue
# First time encountering (p, dir), must be the smallest distance to it
seen.add((p, dir))
# Add all neighbours to be visited
for n_cost, n, n_dir in next_moves(p, dir):
n_cost += cost
# Record predecessors
if predecessor_cost.setdefault((n, n_dir), n_cost) > n_cost:
predecessor_cost[(n, n_dir)] = n_cost
predecessors[(n, n_dir)] = {(p, dir)}
elif predecessor_cost[(n, n_dir)] == n_cost:
predecessors[(n, n_dir)].add((p, dir))
heapq.heappush(queue, (n_cost, n, n_dir))
# Run back up the tree of predecessors to count all cells
return len(get_all_predecessors(predecessors))
start, end, blocks = parse(input.splitlines())
return count_path_cells(start, end, blocks)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

141
2024/d16/ex2/input Normal file
View file

@ -0,0 +1,141 @@
#############################################################################################################################################
#.......#...#.....#.......#.........#.#.............#...........#.......#...............#.........#...........#...#.......#.......#.......#E#
#.#####.#.###.#.#.#.#.#.#.#.#.#####.#.#.###.###.###.###.#####.#.###.#.#.#.#####.#######.#.#######.#####.#####.#.#.#.###.#.#.###.#.#.#.###.#.#
#.....#.#.....#.#.#.#.#...#.#.....#...#.#...#...#.#...#.#.....#...#.#.#.....#...#...#...#...#...#.#.....#...#.#.#...#.....#.#...#.#.#.#.....#
#.###.#.#.#####.###.#.#.###.#####.#.###.#.#.#.###.###.###.#######.#.#.#######.###.###.#####.#.#.#.#.#####.#.#.#.#####.#######.#.#.###.#####.#
#.#.................#.#.#...#...#.#.#...#.#.#.#.....#.....#...#...#...#.......#.......#.....#.#.#.#.......#.#.#...#...........#.......#...#.#
#.#.#.#.#####.#######.#.#.###.###.#.#.###.#.#.#.#.#.#######.###.#######.#########.#####.#####.#.#.#######.#.#.###.#.###########.#####.#.#.###
#...#.#...#.#.#...#...#.#.#...#...#.#...#.#.#.#.#...........#...#.......#...................#.#.#.......#.#.#.....#.#.........#.......#.#...#
###.#.###.#.#.#.###.#.#.#.###.#.#######.#.#.#.###.###.###.#.#.#####.#.###.#.###.#.#########.#.#######.#.###.###.#####.#######.#.#####.#.###.#
#...#...#.#...#.#...#...#.#...#...#...#.#.#.#...#...#.#...#...#.....#.....#.....#.......#...#.#.......................#.....#.......#...#.#.#
#.#.###.#.#.###.#.###.#.#.#.#####.#.#.#.#.#.###.#.#.###.#######.#####.#####.###.#######.#.###.#.#.###.#.#.#######.#######.#.#######.#.###.#.#
#.#.....#.#...#.#.........#.....#...#.#.#.........#...#.....#.#.......#...#...#...#.....#.#.#...#...#...#.......#...#.....#.#.............#.#
#.#######.###.#.#####.#.#.###.#.#####.#.#.#######.###.#####.#.#.#####.#.#.###.#.#.#.#####.#.#.#####.#.###.#####.###.#.#.###.#.#.#.###.#.#.#.#
#.....#...#.........#...#.....#.#...#...#.#.....#.#.#.....#.#.....#...#.#.....#.#.#.#.....#.#...#...#.#.......#...#.#.#.#.....#.#...#.#...#.#
#####.#.###.#########.#.#.###.###.#.#.###.###.#.#.#.#####.#.#####.#.#.#.#######.###.#.#.###.###.#.###.#########.###.#.#.#######.###.#.###.#.#
#.....#.#.......#.....#.....#.#...#.#...#...#.#...#.......#.........#.#.#...#.......#.#...#.....#...#.#.......#...#.#.#.#.......#.#.#.......#
#.#####.###.###.#.#########.###.###.#####.#.#.###.###.#.#####.#.#######.#.###.#.#####.###.#########.#.#.#####.#.#.#.#.#.#.#######.#.#.#####.#
#.#.....#...#...#.......#.#.#...#.....#.....#.#.......#.#...#.#...#...#.#...#.#.......#.#.#.....#...#...#...#.#.#...#.#.#.......#.#.#.....#.#
#.###.###.#.#.###.#####.#.#.#.#######.#.#####.#.#######.#.#.#.#.###.#.#.#.#.#.#####.###.#.#.###.#.#######.###.#.#######.#######.#.#.#.###.#.#
#...#...#...#.#...#.....#...#.#...#.#...#...#.#...#...#...#...#.#...#.#.#.#...#...#...#.#.....#.#.......#.#...#.........#.....#.#.#...#.....#
#.#.###.###.#.#####.#####.###.#.#.#.#######.#.###.#.#.#########.#.###.#.#.#####.#.###.#.#######.#.#.###.#.#.###########.###.#.#.#.###.#####.#
#.#...#.....#.......#.........#.#.#.........#...#...#...........#.#.....#...#...#.#...#.#.....#.#.#.#.#.#.#.......#...#...#.#.#.#.#.........#
#####.#.#.#.#########.#######.#.#.###.#########.#.#############.#.#########.#.###.#.###.#.###.#.###.#.#.#.#######.#.#.###.#.#.#.#.#.#.#.#.#.#
#.....#...#...............#...#.#...#.........#.#...#.....#...#.#.......#.#.#.#...#.#...#.#...#.#...#.......#.....#.#.#...#.#.#.#.....#.#.#.#
#.#####.###.#####.###.#.###.#.#.###.###.###.###.###.#.###.#.#.#.#######.#.#.#.#.###.#.###.#.###.#.###########.#####.###.#####.#.#####.#.#.#.#
#.....#...#.....#...#.#...#.#.#...#...#...#...#.....#.#.....#.......#...#.#.#.#...#...#...#.#...#.#.....#...#.....#...#.......#.#...#...#.#.#
#####.#.#.#.###.###.###.#.#.#.###.###.###.###.###.#.###.#.#.#.#####.#.###.#.#.###.###.#.###.#.###.#.###.#.#.#####.###.###.#####.#.#.#.#.#.###
#.....#.......#.#.#...#.#.#...#.....#.#...#.#.#...#.....#...#.#.....#.#...#.#.#.......#.#.#...#...#...#...#.....#...#.....#...#...#.#.#.#...#
#.#####.###.#.#.#.###.###.#.###.#####.#.###.#.#.###########.#.#.#.###.#.###.#.#####.###.#.#####.###.###########.###.#######.#.#.###.#.#.###.#
#...........#.#.....#...#...#...#.#.........#.#...........#...#.#.....#.....#.#...#...#.#.....#...#.#.............#...#.....#.#...#.#...#.#.#
#.#####.###.#######.###.#####.###.#.###.#####.###.#####.#.#.#.###.#####.###.#.#.#.###.#.#####.#.#.#.#.###.###########.#.#####.###.#.#.#.#.#.#
#.#...#...#...........#.....#.....#.#.#.#...#.....#...#...#.#.....#.#...#...#...#.#.#.#.....#.#.#.#.#.#...#.........#...#...#.#...#.....#.#.#
#.###.#.#.#.#############.#.###.###.#.#.#.#.#.#.#.#.#.#.###.#######.#.#####.#.###.#.#.#####.#.#.#.#.#.#.###.#######.#####.#.#.#.#####.#.#.#.#
#...............#.......#.#.....#...#.#.#.#.#.#.#...#.#...#.#...#...#.#.....#.#.#.#.#...#...#...#...#.#...#.................#.#...#.......#.#
#######.#######.#.#.###.#.#######.###.#.#.#.###.#########.#.#.###.#.#.#.#.###.#.#.#.###.#.#########.#.###########.#########.#.###.###.#.###.#
#...#...#.#...#.#.....#.#...#...#...#...#.#...#.....#...#...#.#...#.#.#.#...#...#.#.#...#.#...#...#.#.........#...#.....#...#...#.......#...#
#.#.#.###.#.#.#.#.#.#.#.###.###.###.###.#.###.###.#.#.#.#####.#.###.#.#.###.###.#.#.#.###.#.#.#.#.#######.###.#.###.###.#.#.###.#######.#.###
#.#...#...#.#.#.#.#...#.#.........#...#.#...#...#...#.#.#.....#.#.#...#...#.....#.#.....#...#...#.......#...#.#...#.#.#.#.#.#...#...#...#...#
#.#####.#.#.#.#.###.###.#############.#.###.###.#.#.#.#.#.###.#.#.###.###.#######.#####.#.#############.#.###.###.#.#.#.#.###.#####.#.#.###.#
#.#.....#...#...#...#.#.........#.....#.#.#.#.#...#...#.......#.#...#...........#...#...#...#.....#...#.#.......#...#...#.....#...#...#...#.#
#.#.#############.###.#########.#.#####.#.#.#.#.#.###.#####.###.#.#.#.#######.#.###.#.#####.#####.#.#.#.#.#.#########.#########.#.#.###.#.#.#
#.......#.....#.....#...#.....#.#...#.#...#.....#...#...#...#...#.#...#.......#.....#...#.......#.#.#...#.#.........#...#.......#...........#
#.###.#.#.#.#.#####.#.#.#.#.###.###.#.###.#####.###.###.#.###.#########.###############.#######.#.#.#####.#####.#######.#####.###.#####.#.#.#
#.#...#...#.#...#...#.#...#...#...#.#.#.......#...#...#.#.....#.....#...#.#.....#.....#...#.......#.#.....#...#.......#...#...#...........#.#
#.#.#######.###.#.###.#######.###.#.#.#.#########.###.#.#########.#.#.###.#.###.#.###.###.###.#####.#####.#.#.#####.#####.#.###.#######.###.#
#.#.........#...#.....#.....#.....#.#...#.......#...#.#...#.......#...#.#...#.#...#.#.......#.#...#.....#...#.#...#.....#...#.#...#.........#
#.###########.#####.#.#.###########.#####.###.#####.#.###.#.###########.#.###.#####.#######.###.#.#####.#####.#.#.#####.#####.###.#.###.###.#
#...............#...#.#...........#.....#...#.#.....#...#...#.........#...........#...#...#...#.#...#...#...#...#.#...#.........#...#.....#.#
#.###.#.#####.#.#.###.#####.#.###.###.#.###.#.#.#.#.###.###.#.#######.#####.#####.#.#.#.#.###.#.###.#.#.#.#######.###.#########.#.###.#.###.#
#...#...#.#...#...#.#.....#.#...#...#.#.....#.....#.....#...#.#.....#.....#.#...#.#.#...#.#.....#.#...#.#.......#.....#...............#.#...#
###.#.###.#.#.#####.#####.#####.###.#.#############.#.#######.#.###.#####.###.#.#.#.#.###.#######.#####.#.#.#########.#.#########.###.#.#.###
#...#.....#.#...#.......#.......#.#.....#.....#...#.#.#.....#...#.#.#...#...#.#.#...#...#...#...........#.#...........#...#...........#...#.#
#.#.###.###.#.#.#.#.###.#########.#.###.#.###.#.#.#.#.#.###.###.#.#.#.#.###.#.#.###.#.#####.#######.#.###.#########.#.###.#.#####.#####.###.#
#.........#.#.#.#.#.#.....#.......#.#.#...#...#.#...#.#.#.#...#.....#.#...#...#...#...#.....#.......#.#...#.......#.....#.#.#.........#.#...#
#.#.###.#.#.#.#.#.#.#######.#####.#.#.###.#.###.#.###.#.#.###.#.#####.###.#######.#.###.#####.#######.#.#####.###.#######.#.###.#.#####.#.#.#
#...#...#.#...#...#...#...#...#...#.#.......#...#.#...#...#...#.#...#.#...#.....#.#...#.....#.....#...#.....#...#.#.....#.#.....#.#.....#.#.#
#.###.#.#.###.###.#.#.#.#.###.#.###.#########.###.#.#####.#.###.#.#.#.#.#.#####.#.###.#####.#.###.#.#######.###.###.###.#.#######.#.###.#.#.#
#.....#.#.......#.......#.....#...............#...#...#.#.#.....#.#...#.#.......#...#.#.#...#.#...#...#.........#...#.#...#.#.....#.#.....#.#
#######.#####.#.###.#.#####.#.#################.#.###.#.#.#########.###.#######.#.###.#.#.#####.#######.#########.###.#####.#.###.#.#.#.###.#
#.......#.....#...#.#.#...#...#...............#.#...#.#.#...#.....#.....#.....#.........#.#.....#.......#.....#...#...#.....#...#.#.#.#.....#
#.#####.#.###.#.###.#.#.#########.#.#.###.#.###.#.###.#.###.#.#.#.###.#####.#.#.###.#####.###.###.#######.###.#.###.#.#.#.#####.#.#.#.#.#####
#...#.....#.#.......#.#...........#.#...#.#.........#...#.#.#.#.#...#.....#.#...#.....#...#...#...#.......#.#...#...#...#.#.................#
###.#.#.###.#.#.#####.#.#####.#####.###.#.#.#######.###.#.#.#.#.###.#####.###.###.###.#.###.###.###.#######.#####.#######.#.#######.#.###.#.#
#...#.#...............#.#.....#.....#...#.#.#.......#...#.#.#.#.#.......#...#.#...#.#...#.........#.#.........#...#.......#.#.#.....#.....#.#
#####.#.#####.#########.#.#####.#####.###.#.#.#####.#.###.#.#.#.#######.###.#.#.###.###########.###.#.#.#####.#.###.###.###.#.#.#####.#####.#
#.....#.#.........#.....#.#.#...#.........#.#...#...#.#...#.#.#...#.#...#...#.#.#.........#...#.#...#.#...#...#...#...........#...#.......#.#
#.#####.#.###.###.#######.#.#.#.#.#####.#.###.#.#.###.#.#.#.#####.#.#.###.#####.#.#.#.###.#.#.###.#######.###.###.#.#############.#########.#
#.#...#...#.....#.....#...#.#...#...#...#...#.#.#...#.#.#.#.#.....#.#.....#.....#...#...#.#.#.....#.....#.........#.......#.#...#...#.......#
#.#.#.#####.###.#####.#.###.#.#####.###.###.###.#####.#.###.#.#####.#####.#.###########.#.#.#######.#.#.###.#.###########.#.#.#.###.#.#####.#
#.#.#.........#...#...#.#...#.#...#.#.....#...#...........#.#.....#.......#.#...........#.#.#.......#.#.......#...#...#.....#...#...#.#.#...#
#.#.###########.#.#.###.###.#.#.#.#.#.###.###.#.###.#####.#.#####.#.#######.###.#########.#.#.#####.#.#######.#.#.#.#.#.#####.#.#.###.#.#.###
#.#...#.........#.#.#.....#...#.#...#...#.#...#.#.........#.......#...#...#.#...#...#...#...#.....#.#.........#.#...#...#.....#...#...#...#.#
#.###.#.#########.#.#####.#####.#####.#.#.#.###.#.###############.###.###.#.#.#.#.#.###.###########.###########.#########.#########.#.#.###.#
#...#.#.........#.#.....#.....#.....#.#.#.#.#.....#.....#...#.........#.#...#.....#...#...........#...........#.#.....#...#.........#.#.....#
#.###.#########.#.#####.#####.#####.#.#.#.#.#.#####.###.#.#.#.#.###.#.#.#############.#.#########.###########.#.#.###.#.#.#.#########.#####.#
#.....#.......#.#.................#.#.#.#.#.#.#...#.#.#...#...#...#.#.#...............#...#...#.#.........#...#...#.#...#.#.......#...#...#.#
#.#####.#######.###.###############.#.#.#.#.###.#.#.#.###########.#.#.###.#############.#.#.#.#.#########.#.#.###.#.###.#.#######.#.###.#.###
#.......#.....#...#.#...#...........#.#.#.#.#...#.#.#...#.........#.#.#...#.....#.....#.#...#.#.............#.#.#.....#.#...#...............#
#.#####.#.###.###.#.#.###.#############.#.#.#.###.#.#.#.#.#########.#.#.#.#.###.#.#####.#####.#.#####.#######.#.#.#.#.#.###.###.#.#######.#.#
#.......#...#.#...#...#...#.........#...#.#...#...#.#.#.#...#.#.......#.#.#...#.#.....#.....#.#.#...#...#...#...#.#.#.#.#.#...#.....#...#.#.#
#.#########.#.#.#####.#.#######.###.#.###.#####.###.#.###.#.#.#.#####.#.#####.#.###.#.#####.#.###.#.#####.#.#####.#.###.#.###.#######.#.#.#.#
#.#.....#...#...#...#.#.......#.#.#...#.#.#...#.....#...#.......#.....#.......#...#.#...#...#.#...#...#...#...#...#.....#...#.#.......#.#.#.#
#.#.###.#.#.###.#.#.#.#######.#.#.#####.#.#.#.#######.#.#.###.###.#####.#########.#####.#.###.#.#####.#.#####.#.###.#####.###.#.#######.###.#
#.#.#.....#.#.....#.#.#.........#.#.....#...#.#.....#.#.#...#.....#...#...#...#.#.....#.....#.#.#...#...#...#.#...#.......#...#...#...#.#...#
#.#.#.#######.#####.#.#.#.#######.#.###.#####.#.#####.#.###.###.###.#.###.#.#.#.#####.#####.#.#.###.#.#.###.#.###.###.###.#.#####.#.#.#.#.###
#.......#...#...#.#.#.#.#.........#...#.........#.....#...#...#.#...#...#...#.#.....#...#.#.#.#.....#.......#...#...#.#...#.#.....#.#...#...#
#.#.#####.#.###.#.#.###.###.#.#####.#.#########.#.#.###.#####.#.#.###.#.#####.#.###.###.#.#.#.#####.#####.###.###.#.###.#.#.#.#####.###.#.#.#
#.#.#.....#...#...#.#.......#.#.....#.#.#.......#.#...#.....#...#...#.#...#...#...#.#.#.#.#.#.....#.#.......#.#...#.#...#.#.#.#.......#...#.#
#.###.#######.###.#.#.#####.###.#.###.#.#.#.#.###.#.#.#####.#######.#.###.#.#.###.#.#.#.#.#.#####.#.#.#####.#.#.#.#.#.#.###.#.#.#####.#.###.#
#.....#.....#.....#.....#...#...#.#...#...#.#.#...#.#.....#...#.#...#...#.#.#.....#...#.#...#...#.#.#.#.....#...#.#...#.#...#.#.....#...#...#
#######.#.###############.#.#.###.#.#######.#.#.#####.###.#.#.#.#.#####.#.#.###.#######.#.###.#.#.#.###.#####.###.#####.#.###.#####.###.#.###
#.....#.#.............#...#.#...#.#...#.....#.#.....#.#.#.#.#...#.....#.#.#.....#.......#.#.#.#...#.....#...#.........#.#.#.....#.......#...#
#####.#.#.###.#######.#.#######.#.###.#.#####.#####.#.#.#.#.###.#####.#.#.#####.#.#######.#.#.#######.###.#.#####.#####.#.#.#.#.#######.###.#
#.....#...#...#...#...#.........#...#.#.......#...#...#...#...#.#.....#.#...#.#.#...#...#...#.............#.....#.........#.#.#...#...#.....#
#.###.###.#.###.#.#.#.#############.#.#.#####.#.#.#####.#####.###.#####.###.#.#.###.#.#.###.###########.#######.#########.#.#.###.#.#.#.#####
#...........#...#.#.#.....#...#...#...#.#...#...#...#...#...#...#...#...#.....#.#.#.#.....#.#.....#...#.#...#.#.......#...#.....#...#...#...#
#.#######.#.#.###.#.#####.#.#.#.#.#######.#.#.#####.#.###.#.###.#.###.#########.#.#.#.###.#.#.#####.#.#.#.#.#.#####.#.#.###.#########.#.#.#.#
#.....#...#.#...#.#.......#.#.#.#.........#.#...#...#.....#.#.#...#...#.....#...#.#...#.#.#...#.....#.#...#.#.......#.....#...#.....#.#...#.#
#####.#.#.#.#####.#######.#.#.#.###.#.#####.#####.#########.#.#.###.#.#.###.#.###.#####.#.#####.#####.#####.#######.#.###.#####.###.#.#.###.#
#...#...........#.#...#...#.#...#.#...#.........#.....#.....#.....#.#.#...#.#.#.........#.......#...#.....#.......#.#.....#.....#.#.#.....#.#
#.#.#####.#.#.#.#.#.#.#.###.#####.#.#####.#####.#####.#.#.#####.###.#####.#.#.#.#######.#.#########.#.###.#######.#.#######.#####.#.###.###.#
#.......#.#.#.#.#...#...#.#.#...#.#.....#.....#.......#.#.....#...#.....#.#...#.....#.#.#...........#.#...........#.......#.#...#.....#.....#
#.#####.#.###.#.#.#######.#.#.#.#.#####.#.###.#########.#.###.###.###.###.#########.#.#.#.#####.#####.#.###########.#.###.#.#.#.#####.#.###.#
#.#...#.#.#...#.#.......#.#...#...#...#.#.#.#...........#...#.....#.#.#...#.........#...#.#.#...#.....#...#.......#...#.#.#.#.....#.#.#.#...#
#.#.#.#.#.#.###.#.#####.#.#######.#.#.#.#.#.###############.#####.#.#.#.###.###.#####.#.#.#.#.###.###.###.###.#.#.#.###.#.#.#.###.#.#.#.###.#
#...#...#.#.#.#...#...#...#.......#.#.....#...............#.....#...#...#.#.#...#.....#.#.#.....#.#.#...#...#.#.#...#.....#.#.....#.#.......#
#.#####.#.#.#.#.###.#.###.#.#######.#.#####.#.###########.#.###.#####.###.#.#.###.#####.#.#.#####.#.###.###.###.#####.#####.###.#.#.#.###.#.#
#.#...#...#.#.#.....#...#.#.........#.......#.......#.......#.#.........#...#.#...#.....#.#...#...#.......#...#.#.....#.......#.#.#.#.#...#.#
#.#.#.###.#.#.#########.#.#####.###.#########.#.#####.#####.#.#######.###.###.#.###.#####.#.###.#.#######.###.#.#.#####.#######.#.#.#.#.#####
#.#...........#...#.#...#...#...#...#...#.....#.......#.............#.#...#...#...#.......#.#.....#.........#...#...#...........#.#...#.....#
#.#.#.#######.#.#.#.#.#.###.#.###.###.###.#############.#############.#.###.###.#.#.#########.###.#.#.#####.#######.#.###########.#.#.#.###.#
#...#.#.....#...#.#.#...#...#.#.....#.#...#...........#.#...........#.#.#.#.#.#.#...#.....#...#...#.#.....#...#...#.#.#...#...#...#...#...#.#
#.###.#.#.#######.#.###.#####.#.###.#.#.###.#####.###.###.#####.#.#.#.#.#.#.#.#.#####.###.#.#.#####.#####.#####.#.#.#.#.#.#.###.#####.#####.#
#...#.#.#.......#...#.#.#...#.#.#...#.#...#...#.......#...#.....#.#...#...#.#...#...#.#.....#.#.....#.....#...#.#...#...#...#...#...........#
#####.#.#######.#.#.#.#.#.#.#.#.#.###.###.###.###.#####.#####.###.#####.#.#.###.#.#.#.#########.#####.###.#.#.#.#######.###.#.###############
#.....#.#...#...#...#.#.#.#.....#.#.........#...#.#...#.....#.....#.....#.#...#...#.#.#.........#...#.#...#.#...#...#.....#.#.#.............#
#.###.#.#.#.#.###.###.#.#.#####.#.#########.###.#.#.#.###.#.#######.#.###.###.#####.#.#.###########.#.#####.#######.#.#.###.#.#.###########.#
#...#.#.#.#.#.....#...#.#...#...#.........#.#...#...#...#.#.......#.#.....#.#.#.....#...#.....#.....#.......#.....#...#.#...#.......#.......#
#.#.#.#.#.#########.#.#.###.#############.#.#.#########.#.#######.#.#######.#.###############.#.#.###.#######.###.###.#.#.#########.#.#.#.#.#
#.#.#.#.#...........#.#...#.#...#.......#.#.#.#.....#.#.#.......#.....#.........#...........#...#.#.........#...#...#.#...................#.#
#.#.###.#.#######.###.###.#.#.#.#.#####.#.#.#.#.###.#.#.###.#########.#.###.###.#.#.###.###.#####.#.#####.#.###.#.#.#.#########.#.#.#.#.###.#
#.#.....#.#.....#.#.....#.#.#.#...#...#.#.#.#...#...#.#.#...#.......#...#.#...#...#.....#.#.#...#.......#.#.#...#...#.#.........#.#...#.#...#
#.#######.#.###.#.###.#.#.#.#.#####.###.#.#.#.###.###.#.#.###.#####.#####.###.#####.###.#.#.#.#.#####.###.#.#.###.#####.#########.#######.#.#
#...#.....#.#...#...#...#.#...#...#.....#.#.#...#.#.....#...#.#...#.#...#.........#.#.#.....#.#...........#...#.#.......#.......#.....#...#.#
###.#.#####.#.#####.###.#.#######.#.#####.#.#####.#.#####.###.#.###.###.#.#####.###.#.#.###.#.#############.#.#.#########.#####.#####.#.###.#
#.#.#.....#.#.#...#...#.#...#.....#.#.....#.......#...#...#...#.......#.........#...#.#.#.......#.........#...#.....#.....#.#...#.....#...#.#
#.#.#####.#.#.#.#.###.#####.#.#.#.#.#.#.###########.#.#.###.#########.#######.#.#.###.#.#.#.###.#########.#######.#.#.#####.#.###.#######.#.#
#...#...#.#.#...#.#...#...#.#.#.#.#.#.#.#...#.........#.#...#.....#...#.....#...#...#...#.#...#.#...#.......#.....#...#.......#...#.......#.#
#.#.#.#.#.#######.#.###.#.#.#.#.###.#.#.#.#.#######.#.###.###.###.#.###.###.#######.#.###.#.#.#.#.#.#.#####.#.#########.#######.###.###.###.#
#.#...#.#...#...........#.........................#.....#...............#.#.........#.#...#.#.#...#.#...#.#.#...#.....#.#.......#.....#...#.#
#.#.###.###.#.###.###.###.###########.#.#.#######.#.###.###.###.#.#.#.###.###########.#####.#.###.#.#.#.#.#.###.#.#####.#.#######.#######.#.#
#...#...#...#.#.#.#...#.........#...#.#.#.....#.#.....#...#.#...#.#...#.............#.#.....#...#.#.#.#.#.......#.......#.........#.......#.#
###.#.###.###.#.#.#.#.#.#######.#.#.#.#.#####.#.#####.###.#.#.#.#.#######.#####.#.###.#.#.#.###.#.#.###.#######.#####.#####.###.#.#.#######.#
#...#.#.#.....#...#.#...#.....#.#.#...#.#.........#...#.#.#.....................#...#...#...#.#.#.#...#.....#.#.#...#.......#...#.#...#...#.#
#.#.#.#.#.#####.###.#.###.###.#.#.#######.#######.#.###.#.###.#.###.#.#.###.#.###.#.#######.#.#.#####.#.###.#.#.#.#.#######.#.#######.#.#.#.#
#.....#...#...#...#.#.....#...#.#.........#.....#.#.#.#...#.......#...#...#.#...#.#...........#.....#.#...#.#...#.#.......#.#...#...#...#.#.#
#.#.#######.#.#####.#.#.#####.#.#####.#####.###.###.#.#.###.#.###########.#.###.#.#####.###.#.#####.#.###.#.#####.#######.#.#.#.#.#.#####.#.#
#.#.....#...#.#.....#.#.#...#.#.....#.....#.#.#...#.#.#...#...#.......................#...#...#...#.#...................#.#...#.#.#.#.......#
#.###.#.#.###.#.#####.#.#.#.#######.#######.#.###.#.#.###.###.#.#######.#####.###.#.#.###.#.###.#.#.###.#.#.#.#####.###.#.#####.#.#.#.#####.#
#S....#...#.....#.....#...#.................#.......#...........#.............#.....#...#.......#.....................................#.....#
#############################################################################################################################################

107
2024/d17/ex1/ex1.py Executable file
View file

@ -0,0 +1,107 @@
#!/usr/bin/env python
import dataclasses
import enum
import sys
@dataclasses.dataclass
class Registers:
reg_a: int
reg_b: int
reg_c: int
class Instruction(enum.IntEnum):
ADV = 0
BXL = 1
BST = 2
JNZ = 3
BXC = 4
OUT = 5
BDV = 6
CDV = 7
@dataclasses.dataclass
class Computer:
registers: Registers
program: list[int]
ip: int = 0
def _resolve_combo_operand(self, operand: int) -> int:
assert operand != 7 # Sanity check
if 0 <= operand <= 3:
return operand
if operand == 4:
return self.registers.reg_a
if operand == 5:
return self.registers.reg_b
if operand == 6:
return self.registers.reg_c
assert False # Sanity check
# Returns False if the computer is halted
# `output` is an out parameter
def step(self, output: list[int]) -> bool:
# NOTE: also accounting for operand in overflow check here
if (self.ip + 1) >= len(self.program):
return False
instr, literal_operand = (
Instruction(self.program[self.ip]),
self.program[self.ip + 1],
)
combo_operand = self._resolve_combo_operand(literal_operand)
ip_delta = 2
match instr:
case Instruction.ADV:
self.registers.reg_a //= 2**combo_operand
case Instruction.BXL:
self.registers.reg_b ^= literal_operand
case Instruction.BST:
self.registers.reg_b = combo_operand % 8
case Instruction.JNZ:
if self.registers.reg_a != 0:
self.ip = literal_operand
ip_delta = 0
case Instruction.BXC:
self.registers.reg_b ^= self.registers.reg_c
case Instruction.OUT:
output.append(combo_operand % 8)
case Instruction.BDV:
self.registers.reg_b = self.registers.reg_a // 2**combo_operand
case Instruction.CDV:
self.registers.reg_c = self.registers.reg_a // 2**combo_operand
self.ip += ip_delta
return True
def solve(input: str) -> str:
def parse_registers(input: list[str]) -> Registers:
def parse_register(input: str) -> int:
return int(input.split(": ")[1])
return Registers(*map(parse_register, input))
def parse(input: str) -> Computer:
registers, program_str = input.split("\n\n")
program = list(map(int, program_str.removeprefix("Program: ").split(",")))
return Computer(parse_registers(registers.splitlines()), program)
computer = parse(input)
output: list[int] = []
while computer.step(output):
pass
return ",".join(str(n) for n in output)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

5
2024/d17/ex1/input Normal file
View file

@ -0,0 +1,5 @@
Register A: 30886132
Register B: 0
Register C: 0
Program: 2,4,1,1,7,5,0,3,1,4,4,4,5,5,3,0

135
2024/d17/ex2/ex2.py Executable file
View file

@ -0,0 +1,135 @@
#!/usr/bin/env python
import copy
import dataclasses
import enum
import sys
@dataclasses.dataclass
class Registers:
reg_a: int
reg_b: int
reg_c: int
class Instruction(enum.IntEnum):
ADV = 0
BXL = 1
BST = 2
JNZ = 3
BXC = 4
OUT = 5
BDV = 6
CDV = 7
@dataclasses.dataclass
class Computer:
registers: Registers
program: list[int]
ip: int = 0
def _resolve_combo_operand(self, operand: int) -> int:
assert operand != 7 # Sanity check
if 0 <= operand <= 3:
return operand
if operand == 4:
return self.registers.reg_a
if operand == 5:
return self.registers.reg_b
if operand == 6:
return self.registers.reg_c
assert False # Sanity check
# Returns False if the computer is halted
# `output` is an out parameter
def step(self, output: list[int]) -> bool:
# NOTE: also accounting for operand in overflow check here
if (self.ip + 1) >= len(self.program):
return False
instr, literal_operand = (
Instruction(self.program[self.ip]),
self.program[self.ip + 1],
)
combo_operand = self._resolve_combo_operand(literal_operand)
ip_delta = 2
match instr:
case Instruction.ADV:
self.registers.reg_a //= 2**combo_operand
case Instruction.BXL:
self.registers.reg_b ^= literal_operand
case Instruction.BST:
self.registers.reg_b = combo_operand % 8
case Instruction.JNZ:
if self.registers.reg_a != 0:
self.ip = literal_operand
ip_delta = 0
case Instruction.BXC:
self.registers.reg_b ^= self.registers.reg_c
case Instruction.OUT:
output.append(combo_operand % 8)
case Instruction.BDV:
self.registers.reg_b = self.registers.reg_a // 2**combo_operand
case Instruction.CDV:
self.registers.reg_c = self.registers.reg_a // 2**combo_operand
self.ip += ip_delta
return True
def solve(input: str) -> int:
def parse_registers(input: list[str]) -> Registers:
def parse_register(input: str) -> int:
return int(input.split(": ")[1])
return Registers(*map(parse_register, input))
def parse(input: str) -> Computer:
registers, program_str = input.split("\n\n")
program = list(map(int, program_str.removeprefix("Program: ").split(",")))
return Computer(parse_registers(registers.splitlines()), program)
# Rely on the shape of the input, which reads 3 bits of reg_a at a time
def find_quine(computer: Computer) -> int:
def is_quine(a: int, n_outputs: int) -> bool:
if n_outputs == 0:
return True
tmp = copy.deepcopy(computer)
tmp.registers.reg_a = a
output: list[int] = []
while tmp.step(output):
pass
return output[-n_outputs:] == computer.program[-n_outputs:]
def helper(a: int, n_outputs: int) -> int | None:
# If not a quine of the correct length, abandon this candidate
if not is_quine(a, n_outputs):
return None
# If we've found all digits, return the candidate
if n_outputs == len(computer.program):
return a
# Try to find a longer quine, starting from this candidate
for next_a in range(a * 8, a * 8 + 8):
# We found a full quine, guaranteed to be the smallest value
if (res := helper(next_a, n_outputs + 1)) is not None:
return res
return None
res = helper(0, 0)
assert res is not None # Sanity check
return res
computer = parse(input)
return find_quine(computer)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

5
2024/d17/ex2/input Normal file
View file

@ -0,0 +1,5 @@
Register A: 30886132
Register B: 0
Register C: 0
Program: 2,4,1,1,7,5,0,3,1,4,4,4,5,5,3,0

66
2024/d18/ex1/ex1.py Executable file
View file

@ -0,0 +1,66 @@
#!/usr/bin/env python
import heapq
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
DIMS = Point(70, 70)
def solve(input: str) -> int:
def parse(input: list[str]) -> list[Point]:
return [Point(*map(int, line.split(","))) for line in input]
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Point] = set()
while len(queue) > 0:
cost, p = heapq.heappop(queue)
if p == end:
return cost
# We must have seen p with a smaller distance before
if p in seen:
continue
# First time encountering p, must be the smallest distance to it
seen.add(p)
# Add all neighbours to be visited
for n in p.neighbours():
if p in blocks:
continue
if not 0 <= p.x <= DIMS.x:
continue
if not 0 <= p.y <= DIMS.y:
continue
heapq.heappush(queue, (cost + 1, n))
assert False # Sanity check
coords = parse(input.splitlines())
return djikstra(Point(0, 0), DIMS, set(coords[:1024]))
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

3450
2024/d18/ex1/input Normal file

File diff suppressed because it is too large Load diff

78
2024/d18/ex2/ex2.py Executable file
View file

@ -0,0 +1,78 @@
#!/usr/bin/env python
import heapq
import sys
from collections.abc import Iterator
from typing import NamedTuple
class Point(NamedTuple):
x: int
y: int
def neighbours(self) -> Iterator["Point"]:
for dx, dy in (
(-1, 0),
(1, 0),
(0, -1),
(0, 1),
):
yield Point(self.x + dx, self.y + dy)
DIMS = Point(70, 70)
def solve(input: str) -> str:
def parse(input: list[str]) -> list[Point]:
return [Point(*map(int, line.split(","))) for line in input]
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int | None:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Point] = set()
while len(queue) > 0:
cost, p = heapq.heappop(queue)
if p == end:
return cost
# We must have seen p with a smaller distance before
if p in seen:
continue
# First time encountering p, must be the smallest distance to it
seen.add(p)
# Add all neighbours to be visited
for n in p.neighbours():
if p in blocks:
continue
if not 0 <= p.x <= DIMS.x:
continue
if not 0 <= p.y <= DIMS.y:
continue
heapq.heappush(queue, (cost + 1, n))
return None
def bisect_cutoff(start: Point, end: Point, blocks: list[Point]) -> Point:
# Cutting off the path is monotonic: once cut-off, it's never uncut
low, high = 0, len(blocks)
while low < high:
mid = low + (high - low) // 2
if djikstra(start, end, set(blocks[: mid + 1])) is None:
high = mid
else:
low = mid + 1
return blocks[low]
coords = parse(input.splitlines())
byte = bisect_cutoff(Point(0, 0), DIMS, coords)
return f"{byte.x},{byte.y}"
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

3450
2024/d18/ex2/input Normal file

File diff suppressed because it is too large Load diff

32
2024/d19/ex1/ex1.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import functools
import sys
def solve(input: str) -> int:
def parse(input: str) -> tuple[frozenset[str], list[str]]:
towels, patterns = input.split("\n\n")
return frozenset(towels.split(", ")), patterns.splitlines()
@functools.cache
def is_possible(pattern: str, towels: frozenset[str]) -> bool:
if pattern == "":
return True
return any(
is_possible(pattern.removeprefix(towel), towels)
for towel in towels
if pattern.startswith(towel)
)
towels, patterns = parse(input)
return sum(is_possible(pattern, towels) for pattern in patterns)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

402
2024/d19/ex1/input Normal file
View file

@ -0,0 +1,402 @@
wwubu, guw, uguggg, bgr, rgbrg, bbrb, rwgru, bwgr, uwwbuw, rwrbrgb, ggbrbuur, bb, ugu, grurrr, gbwbwb, rgbrb, bgrwrbu, bgb, wrwu, rwwr, wubr, bug, wu, brwu, w, grbw, uwbgg, gggwrggb, rurgr, uuw, bbw, wbg, bgw, ugw, brb, uww, buww, uuwgr, buu, rrbugw, ggggbgug, wwwrbbr, rgbbr, ugrr, wgwrg, bwuubub, uugg, bbrgg, bbugw, wuuwb, uwr, bugww, rwrrbbr, ugwrrrb, ubbr, rrwbgg, wb, wgr, gbrb, gwgg, rbg, bub, brg, bubr, ugggw, uuugbbb, grbug, rbww, rg, wgwwwwg, wgb, brugbbb, wgrww, bbrgrurg, ruu, brr, grgwg, wurbb, bww, ubwgr, bburwurb, urrrrbb, rgg, wwww, gbgw, rbrb, buw, wur, ruugugb, uwugg, rgrrugub, ggg, ggr, wrurr, bgg, uuru, brbg, rrbb, bbr, gbbu, grug, rwrrug, ggubub, ggrgg, uu, grb, rrrwwbg, ubbg, wgwwrgbr, rbug, rwrgwbrb, wubwgu, rrw, ruw, rbwubwgr, wwugg, bbbu, wgwr, rwgb, ruwg, rrrb, ubw, rwgw, wbr, uwgrb, rbwrrrru, guwbwg, rgbwr, wbu, ubgu, uruug, urbuuruw, rug, wg, gugbw, brw, wgrb, rbwu, wrw, bgggr, rubu, ur, uggrur, ggwbbuwu, gggr, gwu, bbwb, rrru, rubgb, wub, rgb, rbur, wuwbb, rbb, bwb, wwr, wubrwb, bwwwg, wwbwww, ugrrurw, grg, gwuw, uwwww, ubgb, gwr, gwuurgg, grwuu, gbru, rbbrrg, r, rgbrrg, ugrrubr, bw, wwbwbg, brbwbwr, rrrbg, rggb, bgwu, rrgrwwb, wrgrrb, grw, ubu, wgrugw, bbrugug, wubuwrb, gbrr, rrbg, bbg, bgrwg, urwu, uug, gruruwb, bur, rbwrguw, gbbuw, wubbr, gwurrw, rurr, gwrubb, wwwrw, wrwrbbr, ubbru, gbr, rwg, rrgwgr, ugrwwg, wwbgbr, wwubuwu, uwbb, gggbb, bru, uwb, bgru, wgu, gbrgr, urrwb, ub, u, bgrug, rrwr, bguug, gwbb, uuu, brubwg, bwrwbu, ruggur, gggww, rgu, ug, gur, wgurgwb, uuwwb, wbwgr, gbrg, rru, uuwurrr, rbgbw, ubgwgw, wgwbgu, brbwgg, uwwgw, rgww, buuu, uwu, wrgug, gug, rr, gggwb, bgu, grwg, wrwr, uub, gbuwwrwr, bgug, bwg, ubg, urrb, bbgggw, uuurb, ggw, wgrbwrg, bguw, brrrb, gwrbr, brbw, ggrrbu, uru, wrrbg, ubr, ggrr, ww, wwbgwwr, bgrr, wugbrwg, rrrrg, rww, wrbg, ubur, gwb, rgw, bubgbw, gbb, buuuuur, wwu, uubwww, buwg, ugbg, wgrwbub, wurwuu, bbu, wuru, ggu, wguwgr, gbw, gub, grr, rubgw, urrurb, wbubrr, grgwwb, gbwwru, urb, ruuw, urr, gu, bwrbwg, wrr, wru, wug, wbuwwwwg, guugu, brwurrb, brruuw, wuuuu, rbu, gwg, bgwg, rgr, bbrw, bu, gbbg, bbub, bwr, buur, wrgg, wwuurbug, bgbu, ruburubr, bwurbr, rbr, wgw, gwwug, rruu, wubgg, bwwg, wgwbwu, gwrr, wbbrrb, rwbgbbbr, gr, rwuw, rggbur, gbu, uggb, gwgr, guggbuu, gugw, brgww, wuw, rbubgbu, wgwbrb, g, urbb, gb, gbwu, uuug, ggrbbw, wbrrww, wbw, ugb, gbg, ugr, ggwww, rwr, rbrbw, wrg, wwbr, uggu, rrg, gwguuuuu, bbwuur, rgru, bburww, bbbg, wbb, uuugww, bwgg, bgggw, rugbr, wugrbwr, urw, bwu, uur, gggwrw, buwr, rrr, wwb, wgbw, urg, uwgbw, gru, bgbgurw, rwrrgbub, rwrw, buuug, wggbrgw, guu, bruuubw, gw, wuu, rrb, uuuwg, uwbugu, ugbbrr, wr, uw, ruwbw, wwg, ubru, guub, wrrwg, www, bbuuuw, guruub, wwbrwu, rwgbuu, rguruww, bgggrwr, bg, uwuwr, ugwub, ubgbu, ubbur, rub, gww, rw, urrbbbbu, urrbb, wuwu, ubuggww, bbbwg, ubugg, grgb, rwu, rugbug, ugg, wgg, gg, ru, wruw, wrrwuw, rubg, rbw, rwgwr, uuruu, ubb, ggb
uwgwguuguruwggwbrbwurruwgwwwurgbgwggwwbbubgugguuurgugugwu
gwwggrgbwbbguwgbguubbwrbgurgbburrgbwruwgurgwgguwbwgbgrr
rgggbwgwgwuubwbwrrbrrrurwuwurgubuwrbwrbbbbr
rguruururrwbbrgrbgrbwggrubbggbrbrugrgugggurubrbuuw
rruggbrruruggubguwrubwbwuwgrwrguuurbrrbbbggbrwg
wbwurbbrggubugbrgrrbuuwubwurrwururgbgbwurubbuuwbuw
brbwrrruwrrrubrwuugrbuuwuuwrwrbrrgububwurugbwwrb
rbbbuurubwubbuguggrgwgwgurburugugwbgbuwbwwrrgugg
wrbbugrwgwubgugwrruggwwggurrwuugrwrwbrwgrww
gbwbugwgrubbbbburrbwugbwuugrbbwrrwbgrwubgwgbbb
urgrwbruurbbururwrwwbbubgwbwurbwguguwgrbrgugugwrburb
wubuubwggrgwgbgububrwgwbbubgwgbwwwuubrbbbuwbr
wrrrrurbwubwuuggwguuwwwububrwrruwurrbbbuubggwgrgwugwu
brurwwrbbuwgugbruurgrrgbuuwrbwrugurrwrurrrbbwrwbrrgrwuwg
urgwuwwbwwrbbwbwgwgrrbrwgubbrbgwububbwurggbrgrggbrggrrrwgg
uugwrbwguuwwgbwwwburburbwburwgwguwggwggwbbbuburrubgbbguugg
wbwbguuuuubwwbwgrwbwgguguwgbbggwwwurgrwgrgbgggurbuwugwrbu
uubwuwuuwggbbruwuwbwbgwbwrrguwurubbguwwgbug
bwwgwwubbrrrrwuubwbwrruurrwwwwggbgbrwububwwurbggwuwbgu
bruwgrwwbrwbgruubwbbbugwrbbgwguuwguurbrwrb
grbgwuwwrbgrwgrwurrwbbuwwwwwbrbburrbrwbuggrgwbwrb
wgggrubbbwwgwgggwruururugbrguburrwuwwurgggubrbwwgrwrb
wurbwrwwugrgrgruruuggbbggubwrurbrgrbwwrbrrw
uubuwwurrrrurubbbrrugugubgbruubbrwbuwugrwwgwrrbrwggwrb
ggbuwrwwwbbrgruugrrbrbuurwgurwgubrggguwbubrrbbwgwrb
ugwgurwrwwbrrbwrrrruwbgrwrurrrrrgugurwbuuubbubwwbgrrrbwrb
urwrbbrbwgurbuwrgrurgwggubbwubuggrgbuwgurbbwwbbwwubwrurgrw
bbugbwrwrrrwbgugbgguuwwbrwbbwgurubrgugrgwurrbb
uburggbrbuurrbbggububwbuuubgwrruugbrrbuuwb
rrwuwubggwrwruwrgrrwrwubwwrbbbuggbrggurubwubwbuggwu
rwwuuubguwgwuwgwwwggwbwrubbrguuubrurbwuggubwbruwrb
ruugbuurwwwwrwuwurrrbrubugubwrwwwgbwbrbgbwb
wrurbuuruwrbwgrbgbbwgwrwrrrwgwrurbrbuwrwwgbgwgrwgu
bbruguugubrrgrgurwwggwurwbgwbwbbuugwwrbwubwgrwrb
bbwgrrugwgrbgwbbugugwuubrbrbrbbrrrggurgbbwwuwrbbuwbgw
rbgbwburggggrbwubbrrrrggbuwbguggrrbuwbgugbbrgwrb
ubgwuwbbgbubrgbububwuwbbbburwurbwbbuburwrb
bbgubwgruwbuwbwrwrurbrbrubuwbgrugwbbggbwgrwrburguggwwg
uwuubwuwgbuurbugubbgguburbugugrrwbrrurgwrwgrgbb
wwuuugrwuwurbgwwbrbwguwugbgrbgwwbgrgbubrrgrbbgwrggwgrwgruu
bbbwurgwwbwurwubbugrwbwbgbwrbwrwububbgbgurwwruwrwrrggrugr
bubuwbbwrgrwuggbgrgwbbwruubggubuwguwgrbrrguwgwubbbbubugw
wbwbguwgbrgwgwrrurwwrrrgbrwubrgwbwguwbwwuwgugwgrbbubgru
bwbrbwbrbubbwwbgwwuwgwwgggrrgwbubbubwwwugrgwgr
wgwwwwurwubuugruwbrrguwgubwwbuuwruugbwrubr
rgbbbwrgburwuwwbwubwruubgguwbrbwbwrwurbggbwbrugwgrubrgbbur
gguwwggubgrgrgrwuubruuurubrbrruwgrrwrwuwgrwwburwuwrg
uwbgrrwbbggrwwgguwbbgbbrugruugbgrbuwgbugwrb
guurgurbwbbrugrbuugbgruwgburwrwwrbgbrrrgbwbuwrb
uuwuggwrwgbgbuguruwrgbrbrubgrgugwbrugwrgubbrwuwrb
rwgguuubwrbbrbubbgwwgrgbbrrrgggbururgwgbwgugwgbgbrbbb
grwwrwbbruwubgbwuuubwgubguruugubbwggrgurrbwurgubbggwb
bwuwbggbwbgwbruuggruurrwrwgubbwrrubrwwbgubguwrb
rbwbbrgrwgbgwgbwrrurgbrwgwurrwbrwwuwrgugrbgrugrgubbwrb
wbbgwgbwrubuwgurwbwbugwguwwwgbuwgruguwbgbgbuubwuwgwubgrbww
uwwbwrbubgbwwuwwubbgbgubwwwgwugrgugrwwwgwbubrguggbrgrbrgg
wbwuwgrwwguwgurwwurwubgwuwugrbbggbrruuwbgurrru
gbugwgrurugwrrggbrbubrugggwggbubwbwrubububgbwrgwuurugwrb
gugrgwugubwuwbbbuurrwwrubbwwwguguwwbbruuugbrwwwuwuw
rwbbgbugrgburrggrgwgubggwwruuggubururggrbwrb
rgggggrbbrgrrugwwwgwbwbbrrbrburbwbwwrrgrbuugrruwbbuwrb
ubbuurgrwwwuwbwwbgguurbbbgwbuugwgwuggrrbugguruwwrgbgggbbuwrb
bwuruwwubgubbggrruwgbbgggwrruubgurbrbuuubrgbwub
rbubbggrbwbgwwrrbbggubwwurwgrgwubgrgrrbwrb
gwwbgwubrububgwrurwgurbbuuubwugggbrrwuuwru
wguggrbbbwgrbrwwggrurwbggwgbrgggrwggugbrgwgg
uuguuwwrguwrrggugbwwgwuwrguwbguwuurbwbwrggwguwrubwrb
ruuubbgrgrrrgbbrbgbrbubgbubwguububuugubgrugbgrgwrgwrwruggw
ruurrbwrbgubbuwggguwbwububrbwgrubbwgugwrb
bbgbugbrubwggbrrwwuwrwwwwrwbgbbggrrwbguwrbwrb
brbugwrwrbwwwguwrgrrrggugwwruwburugurrgrurbguwguwwbrubu
wbwubgbubwwgrrggrbbgwruwrrugwwrwuuggbuuwburbrugbguwrwrb
uugbuuwwburgbgruuruguuuwrbwurwggbbwrrbgrurbwub
grrwguwurwwuwgguuugurwrgurrwgrgugrurururwrb
wwrbuwwwwrbbgwgwbgrurburbbwbgwuugbuwuuwwuuwbbuww
gggrbrwrugrrurwugwgbgugrruwrrruurbwuubbuuruuub
rwuguwurugbrububbrggrwrwururwuwuwbrwwgurwgrrrrbrururrwbgbwrb
rwbbgrbbwgbrbbgugggwwububugrbrgwgubbggwgrgrbrrbrgwwuwg
wururwgrruuwrgrrrwbruubuuwgbrrwbgrrbbbgugbgrrguugwg
uruwurbgrwrgwbrbbggwwbgwbgwrbrgrrugwbwrwwbggbrgrugwrb
wrubuwbugurguuurugburubbrgrurgwugwwbbwuwrb
bwrwgbwwbuuwbwgbwbbbrbwgwrugbubbgubuwrrwguurgrurwwwbwrb
rrwuuwbruwugwguurgubwrgwgwgburbrwwwgbubwrwrgggrwugurbrrbu
rrwgrgwwubwgwbrubwurbbrgbuguwbuggbrwrururrubbwburw
uubrgrrbgguggwrbwbwwwguwugugbbuubgugrrbugbruggrwubu
uwrrubgbrrgrbgrrrgbrwgwgrwbwgugguwwwgruwbuwwrb
wbgubgrbrrrwbgrbrwrggugruuguugubbwrrwugbbrubrrbuubbwrbwrgw
gubggguubrrguwrwurubwwubbugrwugwugguugguugbuwwwwubgwgbwwuu
gwguwggwgwbrugwbgbgruwbrwgbgrwbgubbbgwgwbggrw
wwwburgwwurgubugwrubrggbgbrrbgbwgggwrggbwbbbbubrbuuw
gggggubgburbgrguurbruuruguwubrrrbruruuguwwwgggu
bggruubuugbbubugwrrbuuwrguggrwrwurubgbwwwbuuuwgubguruw
gwgbrgburrbbgrwgrurguuwrrwgggrbgbbgwbbbwrgggwbrbrgwur
wbbbbrggurwuugbruubrbwgwgurbwuwbrbwrbwgruwrwwgrwurwuruwrb
bbggrguugwrguwbgruwrwbggurbguuuubgrurwbbgurrbgguggubw
uwrrwbwubbgwbuwwuwurgwurbrruruwuwguggrwbwwurwwurgbgu
ubuubuwrgrwugguuubwwgwrruwwbuwggbbwwrrwbrgbuugugwwr
rwwbbugwrwggwwwuwwbgwwrrrbggruruburubrrubggrgwrb
bbgbrwgwrgguwwrubgwbgubuuurbwwbbbbuggbrgbwrb
ubugbuwbrguwwbrgwrgguwwburgbuubwwgbgrbrubgbgr
rubwrrgurbuwbrggwgbgwbggwuwrbuwgbgubrrrgrrwgbbg
ubrbrrgurwbgbbbrrrugbrwwgwugbrgbugugugrbbggrwbgubbbuuub
wuwgububguurguugwuwbuwubgruwbwuwbubuwburbgg
wwrbgwrgwubwrgruuggwbwwbrbggurburgrggubgwrrgrgrgbbrbgwwuuwrb
gbgrrbugugwrrbuwrubwuwwgggwrbwwrugbgbgrgrrruw
bwwgwruwugwrgwwburrwrgwgubbrgurgubrwwrggrggbwwgrguuwww
rbbwurrgrwrbuwruwuwuuwrgugbwrgrgruubwburbrgbrubgrgrwguur
gwwuurbugbgwuggwwwwwbwgrrbbgrgwwbwgrggrwrbugwrwrb
ugwrbrgrggwbwwuubrwubuuwwurbbbbwgggwgurbggw
bbwggbubgwwuurbuguruwwbgggurgwbgrgrggwurrrrurgbrrugrgwgww
uugwuwubrurururbggrrgurwgwgrrgwwgrwurwrwurwgruu
uwgbwurruruwwuwgbbgwwrrwrwbwgrrbwbrwgwbbwubrgruwub
guugbrrubwbrbgwrwwrurrwwgbbgwgwrbuggurgruuwgrub
gbgurwuuwubrrugwrrugwbbbrwbrwuggrwrrugrwbgu
bwguugwwwuruguwrrwwbbuguugbggbwbubbwgwrgbbguguruwguwuru
bbwrbrguwrwbrgruguuggbgrbrruguubbuwwgrbbuwrwwgrbwb
buwbwbbrurrbubrwgrgwwwbgburbruruwbbbubwrbuuwgwwbwu
urgrrrurgwrggugwbrwubgguguuruurubbwrrrwrb
bburwruuwbugrbwruuuwguubrbuwuwbgbgrbubuwbgr
rbgrugguurbrrbbwruuuuwgwrggwwurbbrggwrruuuurgggbrbrbrb
rguwurugbwbwrbbggrgbgrgbwwuwrbbubugrwrgrrrbbbrburgubgurggwrb
gwuwuuwugwgguubruwwrubrurwrgwrbbgruuuubwwurrugwuuugwubg
bgubgwwbrbrwruugbbbbbwrbguwbgwgubgbbgbbgurgrurgggugbbwbr
gruwwbwwgbbwwbwgwgwwubwwbwubwrwrgurwuwgrbbrurgwg
guguwggbbbgbggbrbrgwbgbrwbgrgruurwurbwggbuwug
rbrbbuurgbgbgbgggbrrwuwuwgwbwbwwuwbgubbbbwr
bgbuwugbugrwwwwgrbbgguwbrbwuuwgrgggrrbgwbwgruggggwwubbwrb
ggwuurgbwurbwubbrgbbubgrwguwbrwbrruwgwgbrwgrrurggwub
gggruuubuwrrugggruuguubbrbbgbruubuwrurwbrwggbrgrrburwggw
rrugwrwbrgbbwrgwgbbbrwrgbburubggugrwggrbrbwubrgurgbwrb
grbrubguwruuwggbwugwwgwuwwggubuwuwwrggbrbuurwubwbbwrb
uwbwuwwbbrguburrwrugburgrwuruwugbburubwguugwwru
uuwwrubggwwwuugrgwbwgbbwrrbburuguurbrbwuwwrbggurbbwguuw
ubugbwrguwrrwurwuwbrbbubbbwbgugwgbrbwruwwwrububgur
ggrrburgrgburuwrrubububrrbgruuguuuwwwgwwrgbruub
ggbuugwurgbgrwggurugubwggbbbubrgurrwwburuggrrrgbbbbwg
ggbrgrwuuwwbwbuwwwwgguwbbuwuwuwuwrwgwwubwwuwrb
wrbrgugwrbwrwguggrrggbguwrguuwbwwrrubgbbbuwwrrbrg
gbwbwrgrbwurwuggwwrwwgwrbbwrwwrbrrrrbuwuurrburruu
bgugggbbburbbbrguurbgrugwwgggurugbuubuugubwrwr
wrgbrrrbwwurbgbgbwbuuwbwwbugbgbugrwgwuuubugwrggwwbbbwggwgwrb
wwbwbbrwrbruwrurwurwggwwbrbuugbugbrwgubggrr
brbubbburuwgrbuwwuwrurrwwubrwugwbgburgwrggbwuwrguwgwuu
rwurrbrggrrgbbgbuububrrwbguwrgbwruwgrrruburuurwwrwbuwgbbr
bwggbuggrwuubrrwubuwrgwrbuwwurugrbbguuwrrugbgburggububww
gruuwburbbgbrbwgugwgwuurgububuwugguwuwwrbw
grrbgwbwrbrwgwrwuugwbbgrrggggwuwgwugbbgugwbrugwbwu
rugruggwruburugwugrgwbugwwugwuwrrgrgrggubrgbwgwwwg
urubrbgbgrgwwgwbrgbbwbrruuruuruuururggubwr
burbwguggwrggrwggubuurrgwbgwggwrugwwuubgrbwbgrrbug
wwbwgrrwbwwbrugrbgwgwgrwwggwbrbwbgggguuubwbgbburguggub
urrbbbburgwbwbbwrgubbggrwbbubuwrgggubggwrb
ggugrbggurrbggrwruwgrbrwgwbuurrgrwwwgugurrrbwgbbrbbggwrb
bwgubwruwrgbrbwgbwbbgbwbgrbbruubbuugwburwrb
gwrbbrwugurrbugrbgruwruwrwwguwubwubwbrwgrruggrr
rwgubrrugrwwwubrwwwrbrwwrbgruwgrubbgwgrwrb
brrbwgwgwggugbgrrrrgggubbwwwuururbgbrwugwbrbrbwuuwru
urbrurgrbgguguguuruwurgugwwgrubggbgbwwwgrbugubwggr
rbgruguwrurwbgwgurrwrrrggugrwwbrbrbwgubuwubruubwrurrgwbgbwrb
ggbwuuuwggggrububwwrurgbrbrubbwgbbbgbbbgbwuwwgggbwrbuwrb
rbbbburwggwurrrrbggwgwwrurubwbgbrbruguwwrwrgggrugubw
rgwgwwrgbrgrwgrrbrburwbwuugbgrwwwggrwrbbwrb
ubgrwwwuubwwwwgbbrurbuuruuurrbuwggbbuurgrrwrgwb
wgwwuruurbgwruugrwgrbugrbbwbgwwgguubrwrrbr
bwrwubggwgrrubgrrwuwuuugruuuubuwbrbbwrrbgrwugwgwugrguwrb
rguwgwugururbwwgwwwgwgwbugubbrbrgwrwgguguwbwruwrrrbgbu
wuuuugurbwrgbuugbrrwgggwwwrwrrrrgwrwggwrbb
wwbwbugrwbbuwwwrwrrrubrbgwwwburwgbgbwwbuwrwugguurbg
ubgbuubgrrwruwugwbwbwbwwgbwbuurwwuwbubwrbug
uubgrgrrugubggggwgrbgbrwrwbrgrwbbwgrburrbr
gbwwugwbgggrbguurbrburbwwrugguwbugwwugbuwwbguu
wuwgrgrgwgrbuwgrbgburuuwrbwguuwuruwgbwwubwwbururbw
wwrwgugurwrbbbrwbwubggguuwrwbuurbwbwubggbbuurrwwbubuwrg
bburgruburubrbwrwwwbrgrbuwgwrwggurburubrgwgbbruw
ubrwbwubbbbwbwgruwuuwbrgbuwwuwuurrrwrrrwgb
wwwwrbrrguwugugbgrggrubbrgrurggbgbuwwbrgggwuguwugbrwg
rbrbbuwrubbbugbgwgurggrgbwrrurbburwrwggruwrubgbgwwuuu
wuuugbgwgggburrrrgwbubbbgrubbgburwrbugbbwbwggrgrg
rugwgubuwurrguwbwwurrggrgrurgwbbwbubwwgbgrubruuuwwbu
bgburwubrrwburrbwgwuwwwwurwuuwbgbgrwggubuwubwwggrwrb
uurbururruggwrwuwbguwwwbbwrbbwrggwrgbwwugwrwuwrw
bburugbugwwwwggggwruwwggrwwrbrrbwgbbbuwgwgbwwwubgrgbwrw
rgggubrrbgugguwwuuwurgubgwrbuwubwburwuubrgb
rwrgwbrbbwrbuwwuurgwuwwbrbrwuububrgubbrbwrguruuub
uuugrguwruwwuwuuwgbbrrwwgruuwbbgwguwwruuwrb
bubbubgwwuurgwrbuuurrwrwwrurwgbwugguwgbbggggww
uwruwuguubrrbbggbgrbwrwwwbwwwggggruuuguuugbwrwwrgw
gururwuubwbbugububgwugbugguwuwgwrugbrwrwrb
wrrbwuuwbwbubgwrruwgguwgrbggubrgbgugrrgrubwwwbwbr
rbgwbgwububrrrwbuwwwwgrurwrbwrgurwruggguggurrrubbbwrwgww
wggbrggbrrgbrrgrggwbbwurbbrgugugrbrgrwwbrgubwrwuuruubwugwrb
rrgbggurbrwuwrgrbbwwubguwgurugurwurwbgwrrbbwwuwwbg
wbbggrwrgruwgrbrgburwggrrbbbguurgubbuwbruwwrggrbr
wubugrwrrwuuugwuubgrubbbbgurguwgrwgruwwruguburwuwu
wbwuggubbrwugwbwrrwurgubuurrrubrgwbruugrgbrrbrugbwrruwuubwrb
rrbuwruwguburwgugrwgwuguwuubgurggrbuugbuwrb
wrrbuwggurrggwubgwwuggbwuuwwurrrwwrwurrburgwbwugrgbuwwrwrb
grrurwggwgruwrrbbwuugrwgrgggbrgubggbugugrwrb
wwwrwbuuwgbugbwurrgwuwbuuwrbuurugurwbuuuburrurwrb
ruruggbgwbggrwwrwrbrrgwuguwwrwurrguwugurbbruwbrwuu
uwuuggwurgbwrrrbruwrrwrurgrwrbrwugrwbbburwurbwbru
rrbwuwgrwuugwguugbrwgubrbubgguwrugrwbwrrbggbgrrrugrbbgr
rgggrbugbubburuwwbrrrbuubrrwubuuuwgbgguuuurrubrwwuwwugrbwrb
urrgwwwrgwrrgurrgwbbrggwrgubwgwwwugruuubuuwggbuur
gbuguuwwrbggrwrrubwwgrbwrurugrwrguuuugwgwrrrgubgbwb
gwugrrwrgubuwggwrrguubugwrbururwgbwgbbugwwwrb
bruuwuwbgrbrwbwwubrbbwrgwubgggwugbuwgbrwbbwruubgwbbrwwwubg
wwgurbbbbbwbwwrwguwbrururbwurgbgwurrurbgur
wwrgwuurruwuwugbbrwbwrbbbuwgwwububrwwgggbguwrgwrwrrub
gugwrrrwugugruuwrguwbwwubbggrwbgbwrugbuwrb
rgubwgbggwbbwggwgggrrrgggbuwwrgrwggggrrgwr
gbgrbggbgggggbgugwgubggwrwwwrwgrbrguwuwgwrbbrbuwwgrwuwrb
wwbgrrggrbgrbwbrrrbwrwrwbwrbrrwbwuugggwrb
wbbwbwbgrbwwwuguubbwgugrugbbrbbggrwwurururwggw
uguwrggruugrgwwuubbrbbbgbbgugurruwruwbugwrugubwwbgbwg
ruwbwbrubggruwbrwrurbrrrbgrrwrrgbubbrwrwurwuubwbrruburwuwrb
ugrrbgbbugruruwbgbbbgwbuwgbwugurbrwbgurggbubwwrbb
wbbwrwrwgurubwgbrgwgrgggrguruubburrubwugggrrwgbbrugw
uugwubrgwuuwbrrrbgruuwruwwbuuubgwuwwwuwbruguuuwgrbrwrb
gugubrrggwbuugubrbgwgbubwwgrrurubwwrbbwbrgrr
wrggwguuguuwbgburwwgwgwbruwrgrrwuwwrgbgugurwggbbg
wwuugbgggubwwwgrgrbguguwgwwwgbuwgbugwgwwguwrug
uwuurugbwgbrrbgbbuuwuggbrbrwubwbrggwbgrubbrrggbuubu
gwggubgwgubguwrbggbwwgbuurbbuubuwwugbubwbgbbruu
bbubugbuwwgbgubrbrguwggbbugggbuwuubbwgrwgwg
rrrrwugwuurrrbggrbwbrbrugbrbubugrbubbrguwwwwwrrgwgbuugbu
wrurguruugbwrwbgguggbwruwgbbwgguurwbgubwruuwru
rwbbwbrbwuwrubgbgwrbbuwbgubrgbwrrwwuwgbrwgurgubburuug
ggwubrwwuggrrwbuuubwwgbbgwurwgrgwwuwubbrgruurugwuguggurg
bbrugurbrurbgrbubwurrubbrbbgugwbbbwuuuwrb
wwgwwbruuuruwggbbwuuuubgwbubrbgwbwwuruuguw
gburwbwbgrbwbgrugbuwubgrrbrrggbuwwrwrwbguuuu
uwuwgrbggbrwgwggwwgbrrwburuuguwbbwwwrgurbgurrwgwurguwrbwu
rbwrbuwrwgbbwwggrbwbwwggrwguwggbwrgbrrubgubgugwbrruwwrb
bbuggbgbwgwrrrggbubrggrurugubuwbwuguwbugrrggwuwbwrggbwb
ugggrbwgwuubwwggggwuwwwruuugrrguwwbwubrrwugwrrurwgbg
bwgrgbubgbuurggguubwwrwgbubgrrgrgugwrguwruwbrbwrwbbwbbbb
wrrrbgrbggruggbbuwwuubrruwgbuuubgwbguurrubbubb
rbwrrrrubruuwgrgrbgwwwurwurgwbugrbbwwgggugbu
ugbggrgrguwwwggbruuruubwwgbwuggwbrwbwwbrbwubrubgbrrgwuwrwrb
rwrbrubwbburrurbuwgrrrgurwgrwbrgwgwwrbwgbrwr
wbwrbruubggrgwbbrbgrbuwwrrrbwwburwgwguubuwguwbrgubbwrbrbwrb
rgrrbwrgwbbuuuruuwbrubbbuburguuburrbgrwbgruwru
gwrgrrbubrwgurwgruwguurgruruubgubguggbbwwrb
wgbbuwurburbwwurgbgbwgggruggwurbwuwbubrwrrwbburbgrwgug
ubugbggwuwguwwwuwugwbwgwwuuuggrrrrubwwubwbwrwrrugwbwrgwuu
rubggguguuwgbuwggrruwrwrgruruguurrubwuwrgruwwgrrurbwuw
wurbburwrubbwbwrruwrbrbuuugurbwuwwgrbrbggwwbgugubrrg
gugruugwruwuwrugbgurguguuwwbbrwrurrgubwbwbrgbwrb
wugrbrbgwbbuuwrrgrbwgwrruuuubrbruwggurgbrg
rurwugugguurgubwbuuuurrrwbrrurbwruurwugrubrgubwrub
rubgwwrrwwwgguuggbwuruwwggbrubwbrwgubrrgrwwbuwggbbburwurbwrb
wbbbggwuwbwwgguruwguwbugwgruwwrwrgggurwwuwbbwubgu
bgbwbbwruuugugbrwburuwwrwbbbuggugbwubrrwgwugbwguguuuwru
rbrwwwwwgbruwguuuuubruuurgbuubrwbrbrwurgburbub
grruruwbrwwrbgrgbgrwuwrgwwuwbbwgrrrrrrrrrggbbbwbbbbu
urrwbbbrwuggrggbgububbrbubuwggwuugwurbbbwbbrwrb
rwwubggwrrbuurwwrrruuuruwggggwbbuwurrurugg
bgrbrruwrrgrwbwruwbwbguugbrrggrbgububwbuubrububggugg
rwruuwbuwruuwrrwgbwwrbwwwbwwrwwuuggbggwbbrbbbwwg
rrgwrgwubgwrwugbuurgruburburuwwwbwwwwrgwwrgwrgrgg
wgwrrgwwurrrubwgwrgbrbwgbbubrrrgugwwguubuwrbbb
gurggwuurwwurwrggugwugrbwubggwwwugrbubwrubbuw
uruuwurrggwbgrugrrbbubwbwwggbuuugwgrwbuuuugrrwbr
wbbguguuwuubwwrbrbbrugwrwuuwgrggbbwurrubrrgwwrb
rruuugbgbgrrwwrwgrbugburbubuuggurguugbwgggwrwwbubb
brbgwwbgrugurrgurbbwbrwubbrbrrwugwrwugrwwrb
buurubwuubrwbugwbbrrgwbgubrggubwurggwbrwwrrurubwrgrrg
wbrbrrrgrrbwubwgrwubgrgrwuubbgwwwugbwruwugwwgubww
uwrgbrubwbuubuurrrbwuguwbggurbubuwgwbwrggbggbwruwuggguwbw
gwbwgbwbgrwbgbbbrwwggbgrurgrwguwgrbruuwbugwrbuwwbwrb
guwbwbrwgbgrrrbbrbruwwbbuwwggbwrrbuubugwbrwrb
wrubrurubbbuguurrbguugwurwuuuwgubrwbbgguwwbbbwwwrbwgwuwgr
rurgbrrbwwbgwbubuggwugrubbgwwwrubuuwbgwgbgwugrrugrub
rwugwrwwbuggwbugbbwrbwwruggbgrwuugruurgrbwwbuwwurubgbr
bwbwuuubbgurgrgrbggrubuuwrugwgwuwggwrggbrbwubwgwguwwrb
urrgurwuwwggrubgrrwrugbbgbbbgwrguggrbuggrgrgwrb
wuwurrrrwbwgwwggurwuwbrrgrburggbwgrggbgrbrrggburrggwwrb
ubugrbugubbwgbbbwwgwgwgbguwwbrgbrgwubbwgwwruubgrgrrrb
gurwwrggbbbburwbgububbrwrggbuwgbwrbrrugburgrgbu
ubgbbrrbubrrubbggrbgwbwrbrwubwuurgwbburwwgr
gwbrrgwgubbbbrrubwgrguguggwwrbggrwrwuuururwrwguwgrbuwbuuwrb
ggbubbbbwruuggrwwuuwbbwubgbururrggrbbwgwrb
rgbbrgrwgrruwrwbuurgugbrububrugbgwruwbrurbrwwuwbbrgbbrugr
urruuurggrwgugbgrwgubrbbbbwuwrrwgrubrurgrbuwrgwu
bbwwwwrbbuwubgrrgurbbruwrbrwguwrbwrurwwwbbuwgruubwwwrb
rbrggubbuwguwbggbrrbbwrrurrrbuuuggugububbbbwrrwb
ugwgwwwrwruugwrwrbuggwuuwgbubwgrbrwwgrggrrgrbrbgbbwgwrb
ggugburbbrgrrwgwbwbwruuwugrbrrrurgwrbrrbrwubr
ububbrggggrbruugrubrwrbgbwggwrbrwubggubgggrrgbubrrgrwrb
rrgwwwrugrurwuggggwrbbwugwwwwububgbrbguwwwguwguwrb
uuwwwrbgrrbwgwuwrwwwgwwwrbbrbuggwwuguurwgwrb
gurrrubbgwubwuggrrwwbbubbrgbgubruwrgubggrwgrburrrrg
uwugubuuwurruwruubgbgbwwggbrwgwgrbbuwugwrb
wwwrbwrbwwgbrbrwbrggrgwrurrbrbwuruuburbubguwwugggrbwgwgb
wbgugurgwrrbbwugwbrwuwrwruruwrrugrruugwuggggw
rwbrwwgrgwwgrwgwbgwrwrwguubuwwbguwggubwggwwbww
rggrruwggwrrgggbrruwrgbuggbbgbwbwgurwrugwbgwwwr
gbbwrgwwrwgguurbggrbgbwggbbbuuwururrgrgwgbgg
wbgruwwwubrbugwbuwuubwgrubguwgwbrubrgwwwgwbgwwrrugbgbub
ugbwugubwgwbuggrurguwwubwrrurrbrgurrbrubwuwrwwwwwgwwgrwwbw
wrwubuguggbrrbugwbwwwrguuuguubwuruugwbgwbguurgwwbggrwwbuwrb
uuugbgrgwrugwguuuuurwgggrburwwgbwrurwbgrrwrb
wbgwguuwbbuwggubrrwbgrgbwuwrgbubruwggbrrubbwg
ubuwbrwbbbwbguuwgugrbuwwrgugwubgrburbgbbrrgrubbbbbu
ugbubrurbgwgwwgrurbwugbwwwbbgbugbbbuggrwgrbugbgwwbuwrbuwrb
wgrwwuugurbgrrgwwbwrubrgrrwwubgbuggwbbuwubu
gbuwrwbrrrwrwbwwrgbugrbugbrurrgggrgwgwgrrbgubrr
wugbuggubuggbrggubwgggbgbgbgurrgwwbrwwwwrb
grgugwubbugurgbguwbgbrugwbugbrrwubwrwuwrgbrugrgwrwrb
guruwwrurwurwugbbrbwwwwubuwrwuuwwugwruwbggbbb
bguruwbbggggbgugrbgrrrgubbbrubwrrwrwubrwgrurw
wbbrbbrgbbgguwbruuguwbbbrbrgrubgugwrgbrrgrwruguwrb
wgrbrgbrgwurggggurwwwggubbggrrrgrubugwuggb
bbwuwwrwrrubruuggwwbrurbgwururwggwwrrrurrww
ubwuugrgwuuuwururbrguurgrbwwwrrwbwruwrgwururbugrwrru
rgbbrwbbguggwbrwwbbgrburwbbwwgbrbwbbubwwrb
uuwuuubgurwwggwwbbbgbgbwbrrgbrrwrbbuwwwgubgggbbrwbrr
gbuurwggrrggbbrgbuuwrgrggrwgwwrwugugwbgwwbrr
bwbrgwbrgwwubrgubbbuwbrubwrbgbrrbbbbwrwbgwguuuuubrgrgrw
guwguururgwuwuuwgwbruguwbbubuwbrggwwugrwruruuugrwrb
grgwuuwrbbgrrgggbwrugbgwbbbrwuuwuwgbwugwruurrrbbuggrwwwru
buwggggwrrrruburwbrugrwrrgwuguwggwbwbgugrgugwwurbbburrggw
ugrwgbbwwwbbgruubgguuruuuururwwbuugbgwwrgubrrbuwwugggw
wbrbbugwgburbgrbgrurrbwwwrbwbwubbgrurrurwwrrbwgbugugw
ugugwbwwgrrgrgbuubwrwbrrurrgbubggwrgbugwrgbggubbruubgw
bwwubbgwwrrwruuruguugugrwgwubbguburuurwguwbwrwrb
brrbwugubgwrgurrrgrbbrwrurugrugwuggwrgrbrwggwbbuwurrwwruwrb
rwbbrbgwgbwguwgbgwurgrbuurugrrgwuwuurubrbgr
uwwbuuwgbwgggwrububuugrwurgggwgbwbubuurgbwrrwbbrwuruwrrrb
bbgwbwrrruurwwugbggbbguggguurrbbbbuubbwbwrwbrwurrbuwgrb
gwgwbwgguwwrwugugwuuwurwgwgbuwgbgbwwuurwwggrubb
rgburwwwuurrgbuwrgwrbugwwgguwwwgbubuuggrwbgubrwrgwugwbuwb
gurrbwgburruggbrbuguugbguruwurbuugbrgbguguuuubwggrwgrrwbwwrb
ruggwuwgbgguwwuburgruwrbgbubbwwugrbwuwwbrbrrwbg
wwbrrgguwbbguubbuuuuugwbbrwrrgrruwrgwwrbbbbwgrgw
bwbrwbwwrwwuugugugbrbrbrrbwrwrruguwuwwubbugwgurrr
wggrwwubuwruwgugrguggugwbbggugruuggrwbggrwbbw
gbgubgbwgurbwrrrgbuwwguwrrwwbwuwuwbgburrbgwbgwr
grrububuwruwrubrgwwbrrgrbwugrggwbrgbwwrb
uguuggrrwubrgrwggububbwgbbwgrwurwwwgwbubbbruggrwbrbgwrb
brgurrbwwugubrrgurrbbrbuubbwwwwguwwgrwwugubgruruu
wrwubrrwburuwbrgwwuggurwrrwbbruruuwuwuwubbubuuu
bwbugbrrbwugbwrubuwbuwwubbbguwbrgwwurbgugrgrwgwuwwbwubgwrwrb
bwguwgurgurrrbgbbbwbrrrwuwbrwubruuwrbwrb
rbubgwbubuwwbubbrgwwgubgwwrrgbubrwbbrwwrbwwuwgbbwrb
wrbbgwburwwwrgwggggrrbubbggrbgbggwurwruburwubrubrgr
rggurrwwgururrgrwwwgrugwwbguurbbwbuwrwurrrbrggbbbbrwwr
ugwwgwrgrgugrbbbbubrwrubrbguwbrwubgrwgrrgbgggwugw
uwgrgbugbwbbggrgrbbgrwrbggrrwbbwbugwrwbrrwwuuwrb
bguubugwggwguuggbguuwbgwbwruggwrbgbrrbwbrrbgwrbggwrbrrbu
rgwwbubbbbuugubwbrwuwwrrruuwggrbbrbwguwruuubgbwwgwurbgbubg
uuwbwbrwwubbrwuuuwuwwgggwwubburgwgwbrurrwbrbgbbburwgb
wwrrbbwwbruwbgbggbrbbgrugubggwgggugrbuurgrbbgbuwu
ugrbwbwwgggwrgbbguugrgggwrggbuuwuwubrgbruwbwrb
ubggwbwguugbbubbgbbguubwuubrbwubrubrwguwwwrb
rugburrbwruuwrwwgwrwggrubgwbuuubugbwuurgbg
ggrwrruwggbubrurubgwrbwrgbwgwuwrbbbwbuugwubrubwuwbrbgbgubg
grgwugwuwbgwuuwuugrgwwguwbburuubbbgubbuwgwg
ruwrwrwwrwgwwrgbubgbrbrwwbgurrwrrgbruuwgrgrrrgurugugu
brbwrgurrwgwrruwubrwwwrggbuururgrguwggwbbgrgubrw
bbuwggrbugbbgbguugwuuwuubgwgbbrgugbgbwbrubbbgugwrgrgrgruuwrb
wgbgbubuwrurbuuwgrugwrgrbrwrgwuwbbgwrrrrwrb
wgwrgbbbuurubgwwrgwguururrubgbgwrbgwwwwwggggbrurgrr
uwggrggrbrruwuruwbuwurrrwwwwbuggbguwuubwuwbubrrwrb
ugubbwurwurgwwrburwuugrurguuwruwwrwbgruggwbwwwgwbb
ubwgwbbgbrugguwrggubbrgrbgruuwugbgruuwggrbgwugugwugrrwwg
wggrgugugubgrrrbugbbbwrrrwbwguuruugrwwrb
bwgwwbrwbbubgwubrwwwgurbwbrwbubgbwbubwgbbggrrwbbgbwrbbrr
gurwrbbbrbrurbrrbugrrrguurwwbbwugwbubuwrwbrgbgrwrbuuwrbuuw
gwwwwuuubuguwwurubwwrggguwgbrbbbgbububgwrbwbubbruwbb
uwwwbbggwrgbrgrubrurwrgugrbubuwwruugbwbgubugbuguuuuurbrgr
rrbubwbuwrgrrugubbbuuuwwbwgurrwwgwburubwrwrb
rurrbbgurbuuruwuuwrurrwbbggrrrgguwgwrurgrurubwrwwrb
ugbugurrgggrgrbuuwgbuugrrgbuuwugbrwrrgbubbbbburuuuwww
wuwgugruburwguwrwgwbwrbubbrbgwbrgbwruruwbbuwwwugurwgurwrbbb
wugwbruwuggrruggrbgrgubuubgurbrrrruwrguububruubwugwwbbwbu
grubuwwurrbbggwbwwwruuuuubwgwubwuubuuwrrrwgrururbggbbggw
gwgrwbuwuwgwrubbgbugrgwbgrbwbuwgrggbwrrubbuggwbgrwgbggg
uruwrwuwbrbrwwruwgurrugrbwguuubwrwwurubgrbgrgwwur
rguubrwwgubuwwruruwbuggbrburgrgurugwwwwrb
uuubuubggrugbgbgwgbbgburuwggrrggwrwruwgbuwwbrgu
gwgrgugwgbwbuwbgwgbrguuguguugrrgrbuugugbrgu
urgrwwwrgurwwrwwwggbgubbrgwwwruwubgbrgurguurwugrgwrb
rubgwbrwbgrruuwbruwrgwbwbguwururubrgwrurbuubww
brurbguurgbggwbbgwwwugbrbgwrwbrwrrbrwbugwuguwrbwru
rwrbbguggugwwgrbrrwrbgruwrwwuugbrgurbwuguwwubgbgg
wgrgbgbwbbggrwgrbbbrrwubgrbrbgwwururguwugbgrgrrug
gwuurwubwwguggwwbbwwugrwgggwwurrrgrrrburguwwrrb
guggrruwrbrugwrwgrbgurbgbrgwugwwwwbbbwwrwuwug
uwgrrgrbbgwrggrwwwgbgbrbbrbuuburbbrbrugwurugwbburgbb
wwwbbbwbbbrbgubrwbbrubugbrgrrrruuwgurrwwwruwgwrguw
uuubuwgwrwugrbggggbruugbrruwuurubwwgwbwgurbgbuubbgwbuww
wbrrwgbuwggubuggrugbwwbbbbwgwrrbgggrrrwrbgrbgg
gbbbrwwggbugrbrrwrgbuwgbrrrwgwgubrruruurwguwb
rrbbuwrbruwruwurbggburwwbwuuwrurbbwrbuurubggwrb
rrubbuurrrgbrwwuwrbwgruuwbbwugrgubgbwwruwbburgbwb
wrwugbbgrbgurubrwwwwwbbbruubwgrgburbwbrgbwbgwb
wwrwugwbbrubugbrrgrwwbwbuwwwuugbbwguruggwgwrwgwrggwrgrgwgwrb
bguwgugwbgwgubwwbwwrwubrrwubbwgrbwgggwuuwgrbgwgwgrwwggrb

32
2024/d19/ex2/ex2.py Executable file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
import functools
import sys
def solve(input: str) -> int:
def parse(input: str) -> tuple[frozenset[str], list[str]]:
towels, patterns = input.split("\n\n")
return frozenset(towels.split(", ")), patterns.splitlines()
@functools.cache
def count_ways(pattern: str, towels: frozenset[str]) -> int:
if pattern == "":
return 1
return sum(
count_ways(pattern.removeprefix(towel), towels)
for towel in towels
if pattern.startswith(towel)
)
towels, patterns = parse(input)
return sum(count_ways(pattern, towels) for pattern in patterns)
def main() -> None:
input = sys.stdin.read()
print(solve(input))
if __name__ == "__main__":
main()

402
2024/d19/ex2/input Normal file
View file

@ -0,0 +1,402 @@
wwubu, guw, uguggg, bgr, rgbrg, bbrb, rwgru, bwgr, uwwbuw, rwrbrgb, ggbrbuur, bb, ugu, grurrr, gbwbwb, rgbrb, bgrwrbu, bgb, wrwu, rwwr, wubr, bug, wu, brwu, w, grbw, uwbgg, gggwrggb, rurgr, uuw, bbw, wbg, bgw, ugw, brb, uww, buww, uuwgr, buu, rrbugw, ggggbgug, wwwrbbr, rgbbr, ugrr, wgwrg, bwuubub, uugg, bbrgg, bbugw, wuuwb, uwr, bugww, rwrrbbr, ugwrrrb, ubbr, rrwbgg, wb, wgr, gbrb, gwgg, rbg, bub, brg, bubr, ugggw, uuugbbb, grbug, rbww, rg, wgwwwwg, wgb, brugbbb, wgrww, bbrgrurg, ruu, brr, grgwg, wurbb, bww, ubwgr, bburwurb, urrrrbb, rgg, wwww, gbgw, rbrb, buw, wur, ruugugb, uwugg, rgrrugub, ggg, ggr, wrurr, bgg, uuru, brbg, rrbb, bbr, gbbu, grug, rwrrug, ggubub, ggrgg, uu, grb, rrrwwbg, ubbg, wgwwrgbr, rbug, rwrgwbrb, wubwgu, rrw, ruw, rbwubwgr, wwugg, bbbu, wgwr, rwgb, ruwg, rrrb, ubw, rwgw, wbr, uwgrb, rbwrrrru, guwbwg, rgbwr, wbu, ubgu, uruug, urbuuruw, rug, wg, gugbw, brw, wgrb, rbwu, wrw, bgggr, rubu, ur, uggrur, ggwbbuwu, gggr, gwu, bbwb, rrru, rubgb, wub, rgb, rbur, wuwbb, rbb, bwb, wwr, wubrwb, bwwwg, wwbwww, ugrrurw, grg, gwuw, uwwww, ubgb, gwr, gwuurgg, grwuu, gbru, rbbrrg, r, rgbrrg, ugrrubr, bw, wwbwbg, brbwbwr, rrrbg, rggb, bgwu, rrgrwwb, wrgrrb, grw, ubu, wgrugw, bbrugug, wubuwrb, gbrr, rrbg, bbg, bgrwg, urwu, uug, gruruwb, bur, rbwrguw, gbbuw, wubbr, gwurrw, rurr, gwrubb, wwwrw, wrwrbbr, ubbru, gbr, rwg, rrgwgr, ugrwwg, wwbgbr, wwubuwu, uwbb, gggbb, bru, uwb, bgru, wgu, gbrgr, urrwb, ub, u, bgrug, rrwr, bguug, gwbb, uuu, brubwg, bwrwbu, ruggur, gggww, rgu, ug, gur, wgurgwb, uuwwb, wbwgr, gbrg, rru, uuwurrr, rbgbw, ubgwgw, wgwbgu, brbwgg, uwwgw, rgww, buuu, uwu, wrgug, gug, rr, gggwb, bgu, grwg, wrwr, uub, gbuwwrwr, bgug, bwg, ubg, urrb, bbgggw, uuurb, ggw, wgrbwrg, bguw, brrrb, gwrbr, brbw, ggrrbu, uru, wrrbg, ubr, ggrr, ww, wwbgwwr, bgrr, wugbrwg, rrrrg, rww, wrbg, ubur, gwb, rgw, bubgbw, gbb, buuuuur, wwu, uubwww, buwg, ugbg, wgrwbub, wurwuu, bbu, wuru, ggu, wguwgr, gbw, gub, grr, rubgw, urrurb, wbubrr, grgwwb, gbwwru, urb, ruuw, urr, gu, bwrbwg, wrr, wru, wug, wbuwwwwg, guugu, brwurrb, brruuw, wuuuu, rbu, gwg, bgwg, rgr, bbrw, bu, gbbg, bbub, bwr, buur, wrgg, wwuurbug, bgbu, ruburubr, bwurbr, rbr, wgw, gwwug, rruu, wubgg, bwwg, wgwbwu, gwrr, wbbrrb, rwbgbbbr, gr, rwuw, rggbur, gbu, uggb, gwgr, guggbuu, gugw, brgww, wuw, rbubgbu, wgwbrb, g, urbb, gb, gbwu, uuug, ggrbbw, wbrrww, wbw, ugb, gbg, ugr, ggwww, rwr, rbrbw, wrg, wwbr, uggu, rrg, gwguuuuu, bbwuur, rgru, bburww, bbbg, wbb, uuugww, bwgg, bgggw, rugbr, wugrbwr, urw, bwu, uur, gggwrw, buwr, rrr, wwb, wgbw, urg, uwgbw, gru, bgbgurw, rwrrgbub, rwrw, buuug, wggbrgw, guu, bruuubw, gw, wuu, rrb, uuuwg, uwbugu, ugbbrr, wr, uw, ruwbw, wwg, ubru, guub, wrrwg, www, bbuuuw, guruub, wwbrwu, rwgbuu, rguruww, bgggrwr, bg, uwuwr, ugwub, ubgbu, ubbur, rub, gww, rw, urrbbbbu, urrbb, wuwu, ubuggww, bbbwg, ubugg, grgb, rwu, rugbug, ugg, wgg, gg, ru, wruw, wrrwuw, rubg, rbw, rwgwr, uuruu, ubb, ggb
uwgwguuguruwggwbrbwurruwgwwwurgbgwggwwbbubgugguuurgugugwu
gwwggrgbwbbguwgbguubbwrbgurgbburrgbwruwgurgwgguwbwgbgrr
rgggbwgwgwuubwbwrrbrrrurwuwurgubuwrbwrbbbbr
rguruururrwbbrgrbgrbwggrubbggbrbrugrgugggurubrbuuw
rruggbrruruggubguwrubwbwuwgrwrguuurbrrbbbggbrwg
wbwurbbrggubugbrgrrbuuwubwurrwururgbgbwurubbuuwbuw
brbwrrruwrrrubrwuugrbuuwuuwrwrbrrgububwurugbwwrb
rbbbuurubwubbuguggrgwgwgurburugugwbgbuwbwwrrgugg
wrbbugrwgwubgugwrruggwwggurrwuugrwrwbrwgrww
gbwbugwgrubbbbburrbwugbwuugrbbwrrwbgrwubgwgbbb
urgrwbruurbbururwrwwbbubgwbwurbwguguwgrbrgugugwrburb
wubuubwggrgwgbgububrwgwbbubgwgbwwwuubrbbbuwbr
wrrrrurbwubwuuggwguuwwwububrwrruwurrbbbuubggwgrgwugwu
brurwwrbbuwgugbruurgrrgbuuwrbwrugurrwrurrrbbwrwbrrgrwuwg
urgwuwwbwwrbbwbwgwgrrbrwgubbrbgwububbwurggbrgrggbrggrrrwgg
uugwrbwguuwwgbwwwburburbwburwgwguwggwggwbbbuburrubgbbguugg
wbwbguuuuubwwbwgrwbwgguguwgbbggwwwurgrwgrgbgggurbuwugwrbu
uubwuwuuwggbbruwuwbwbgwbwrrguwurubbguwwgbug
bwwgwwubbrrrrwuubwbwrruurrwwwwggbgbrwububwwurbggwuwbgu
bruwgrwwbrwbgruubwbbbugwrbbgwguuwguurbrwrb
grbgwuwwrbgrwgrwurrwbbuwwwwwbrbburrbrwbuggrgwbwrb
wgggrubbbwwgwgggwruururugbrguburrwuwwurgggubrbwwgrwrb
wurbwrwwugrgrgruruuggbbggubwrurbrgrbwwrbrrw
uubuwwurrrrurubbbrrugugubgbruubbrwbuwugrwwgwrrbrwggwrb
ggbuwrwwwbbrgruugrrbrbuurwgurwgubrggguwbubrrbbwgwrb
ugwgurwrwwbrrbwrrrruwbgrwrurrrrrgugurwbuuubbubwwbgrrrbwrb
urwrbbrbwgurbuwrgrurgwggubbwubuggrgbuwgurbbwwbbwwubwrurgrw
bbugbwrwrrrwbgugbgguuwwbrwbbwgurubrgugrgwurrbb
uburggbrbuurrbbggububwbuuubgwrruugbrrbuuwb
rrwuwubggwrwruwrgrrwrwubwwrbbbuggbrggurubwubwbuggwu
rwwuuubguwgwuwgwwwggwbwrubbrguuubrurbwuggubwbruwrb
ruugbuurwwwwrwuwurrrbrubugubwrwwwgbwbrbgbwb
wrurbuuruwrbwgrbgbbwgwrwrrrwgwrurbrbuwrwwgbgwgrwgu
bbruguugubrrgrgurwwggwurwbgwbwbbuugwwrbwubwgrwrb
bbwgrrugwgrbgwbbugugwuubrbrbrbbrrrggurgbbwwuwrbbuwbgw
rbgbwburggggrbwubbrrrrggbuwbguggrrbuwbgugbbrgwrb
ubgwuwbbgbubrgbububwuwbbbburwurbwbbuburwrb
bbgubwgruwbuwbwrwrurbrbrubuwbgrugwbbggbwgrwrburguggwwg
uwuubwuwgbuurbugubbgguburbugugrrwbrrurgwrwgrgbb
wwuuugrwuwurbgwwbrbwguwugbgrbgwwbgrgbubrrgrbbgwrggwgrwgruu
bbbwurgwwbwurwubbugrwbwbgbwrbwrwububbgbgurwwruwrwrrggrugr
bubuwbbwrgrwuggbgrgwbbwruubggubuwguwgrbrrguwgwubbbbubugw
wbwbguwgbrgwgwrrurwwrrrgbrwubrgwbwguwbwwuwgugwgrbbubgru
bwbrbwbrbubbwwbgwwuwgwwgggrrgwbubbubwwwugrgwgr
wgwwwwurwubuugruwbrrguwgubwwbuuwruugbwrubr
rgbbbwrgburwuwwbwubwruubgguwbrbwbwrwurbggbwbrugwgrubrgbbur
gguwwggubgrgrgrwuubruuurubrbrruwgrrwrwuwgrwwburwuwrg
uwbgrrwbbggrwwgguwbbgbbrugruugbgrbuwgbugwrb
guurgurbwbbrugrbuugbgruwgburwrwwrbgbrrrgbwbuwrb
uuwuggwrwgbgbuguruwrgbrbrubgrgugwbrugwrgubbrwuwrb
rwgguuubwrbbrbubbgwwgrgbbrrrgggbururgwgbwgugwgbgbrbbb
grwwrwbbruwubgbwuuubwgubguruugubbwggrgurrbwurgubbggwb
bwuwbggbwbgwbruuggruurrwrwgubbwrrubrwwbgubguwrb
rbwbbrgrwgbgwgbwrrurgbrwgwurrwbrwwuwrgugrbgrugrgubbwrb
wbbgwgbwrubuwgurwbwbugwguwwwgbuwgruguwbgbgbuubwuwgwubgrbww
uwwbwrbubgbwwuwwubbgbgubwwwgwugrgugrwwwgwbubrguggbrgrbrgg
wbwuwgrwwguwgurwwurwubgwuwugrbbggbrruuwbgurrru
gbugwgrurugwrrggbrbubrugggwggbubwbwrubububgbwrgwuurugwrb
gugrgwugubwuwbbbuurrwwrubbwwwguguwwbbruuugbrwwwuwuw
rwbbgbugrgburrggrgwgubggwwruuggubururggrbwrb
rgggggrbbrgrrugwwwgwbwbbrrbrburbwbwwrrgrbuugrruwbbuwrb
ubbuurgrwwwuwbwwbgguurbbbgwbuugwgwuggrrbugguruwwrgbgggbbuwrb
bwuruwwubgubbggrruwgbbgggwrruubgurbrbuuubrgbwub
rbubbggrbwbgwwrrbbggubwwurwgrgwubgrgrrbwrb
gwwbgwubrububgwrurwgurbbuuubwugggbrrwuuwru
wguggrbbbwgrbrwwggrurwbggwgbrgggrwggugbrgwgg
uuguuwwrguwrrggugbwwgwuwrguwbguwuurbwbwrggwguwrubwrb
ruuubbgrgrrrgbbrbgbrbubgbubwguububuugubgrugbgrgwrgwrwruggw
ruurrbwrbgubbuwggguwbwububrbwgrubbwgugwrb
bbgbugbrubwggbrrwwuwrwwwwrwbgbbggrrwbguwrbwrb
brbugwrwrbwwwguwrgrrrggugwwruwburugurrgrurbguwguwwbrubu
wbwubgbubwwgrrggrbbgwruwrrugwwrwuuggbuuwburbrugbguwrwrb
uugbuuwwburgbgruuruguuuwrbwurwggbbwrrbgrurbwub
grrwguwurwwuwgguuugurwrgurrwgrgugrurururwrb
wwrbuwwwwrbbgwgwbgrurburbbwbgwuugbuwuuwwuuwbbuww
gggrbrwrugrrurwugwgbgugrruwrrruurbwuubbuuruuub
rwuguwurugbrububbrggrwrwururwuwuwbrwwgurwgrrrrbrururrwbgbwrb
rwbbgrbbwgbrbbgugggwwububugrbrgwgubbggwgrgrbrrbrgwwuwg
wururwgrruuwrgrrrwbruubuuwgbrrwbgrrbbbgugbgrrguugwg
uruwurbgrwrgwbrbbggwwbgwbgwrbrgrrugwbwrwwbggbrgrugwrb
wrubuwbugurguuurugburubbrgrurgwugwwbbwuwrb
bwrwgbwwbuuwbwgbwbbbrbwgwrugbubbgubuwrrwguurgrurwwwbwrb
rrwuuwbruwugwguurgubwrgwgwgburbrwwwgbubwrwrgggrwugurbrrbu
rrwgrgwwubwgwbrubwurbbrgbuguwbuggbrwrururrubbwburw
uubrgrrbgguggwrbwbwwwguwugugbbuubgugrrbugbruggrwubu
uwrrubgbrrgrbgrrrgbrwgwgrwbwgugguwwwgruwbuwwrb
wbgubgrbrrrwbgrbrwrggugruuguugubbwrrwugbbrubrrbuubbwrbwrgw
gubggguubrrguwrwurubwwubbugrwugwugguugguugbuwwwwubgwgbwwuu
gwguwggwgwbrugwbgbgruwbrwgbgrwbgubbbgwgwbggrw
wwwburgwwurgubugwrubrggbgbrrbgbwgggwrggbwbbbbubrbuuw
gggggubgburbgrguurbruuruguwubrrrbruruuguwwwgggu
bggruubuugbbubugwrrbuuwrguggrwrwurubgbwwwbuuuwgubguruw
gwgbrgburrbbgrwgrurguuwrrwgggrbgbbgwbbbwrgggwbrbrgwur
wbbbbrggurwuugbruubrbwgwgurbwuwbrbwrbwgruwrwwgrwurwuruwrb
bbggrguugwrguwbgruwrwbggurbguuuubgrurwbbgurrbgguggubw
uwrrwbwubbgwbuwwuwurgwurbrruruwuwguggrwbwwurwwurgbgu
ubuubuwrgrwugguuubwwgwrruwwbuwggbbwwrrwbrgbuugugwwr
rwwbbugwrwggwwwuwwbgwwrrrbggruruburubrrubggrgwrb
bbgbrwgwrgguwwrubgwbgubuuurbwwbbbbuggbrgbwrb
ubugbuwbrguwwbrgwrgguwwburgbuubwwgbgrbrubgbgr
rubwrrgurbuwbrggwgbgwbggwuwrbuwgbgubrrrgrrwgbbg
ubrbrrgurwbgbbbrrrugbrwwgwugbrgbugugugrbbggrwbgubbbuuub
wuwgububguurguugwuwbuwubgruwbwuwbubuwburbgg
wwrbgwrgwubwrgruuggwbwwbrbggurburgrggubgwrrgrgrgbbrbgwwuuwrb
gbgrrbugugwrrbuwrubwuwwgggwrbwwrugbgbgrgrrruw
bwwgwruwugwrgwwburrwrgwgubbrgurgubrwwrggrggbwwgrguuwww
rbbwurrgrwrbuwruwuwuuwrgugbwrgrgruubwburbrgbrubgrgrwguur
gwwuurbugbgwuggwwwwwbwgrrbbgrgwwbwgrggrwrbugwrwrb
ugwrbrgrggwbwwuubrwubuuwwurbbbbwgggwgurbggw
bbwggbubgwwuurbuguruwwbgggurgwbgrgrggwurrrrurgbrrugrgwgww
uugwuwubrurururbggrrgurwgwgrrgwwgrwurwrwurwgruu
uwgbwurruruwwuwgbbgwwrrwrwbwgrrbwbrwgwbbwubrgruwub
guugbrrubwbrbgwrwwrurrwwgbbgwgwrbuggurgruuwgrub
gbgurwuuwubrrugwrrugwbbbrwbrwuggrwrrugrwbgu
bwguugwwwuruguwrrwwbbuguugbggbwbubbwgwrgbbguguruwguwuru
bbwrbrguwrwbrgruguuggbgrbrruguubbuwwgrbbuwrwwgrbwb
buwbwbbrurrbubrwgrgwwwbgburbruruwbbbubwrbuuwgwwbwu
urgrrrurgwrggugwbrwubgguguuruurubbwrrrwrb
bburwruuwbugrbwruuuwguubrbuwuwbgbgrbubuwbgr
rbgrugguurbrrbbwruuuuwgwrggwwurbbrggwrruuuurgggbrbrbrb
rguwurugbwbwrbbggrgbgrgbwwuwrbbubugrwrgrrrbbbrburgubgurggwrb
gwuwuuwugwgguubruwwrubrurwrgwrbbgruuuubwwurrugwuuugwubg
bgubgwwbrbrwruugbbbbbwrbguwbgwgubgbbgbbgurgrurgggugbbwbr
gruwwbwwgbbwwbwgwgwwubwwbwubwrwrgurwuwgrbbrurgwg
guguwggbbbgbggbrbrgwbgbrwbgrgruurwurbwggbuwug
rbrbbuurgbgbgbgggbrrwuwuwgwbwbwwuwbgubbbbwr
bgbuwugbugrwwwwgrbbgguwbrbwuuwgrgggrrbgwbwgruggggwwubbwrb
ggwuurgbwurbwubbrgbbubgrwguwbrwbrruwgwgbrwgrrurggwub
gggruuubuwrrugggruuguubbrbbgbruubuwrurwbrwggbrgrrburwggw
rrugwrwbrgbbwrgwgbbbrwrgbburubggugrwggrbrbwubrgurgbwrb
grbrubguwruuwggbwugwwgwuwwggubuwuwwrggbrbuurwubwbbwrb
uwbwuwwbbrguburrwrugburgrwuruwugbburubwguugwwru
uuwwrubggwwwuugrgwbwgbbwrrbburuguurbrbwuwwrbggurbbwguuw
ubugbwrguwrrwurwuwbrbbubbbwbgugwgbrbwruwwwrububgur
ggrrburgrgburuwrrubububrrbgruuguuuwwwgwwrgbruub
ggbuugwurgbgrwggurugubwggbbbubrgurrwwburuggrrrgbbbbwg
ggbrgrwuuwwbwbuwwwwgguwbbuwuwuwuwrwgwwubwwuwrb
wrbrgugwrbwrwguggrrggbguwrguuwbwwrrubgbbbuwwrrbrg
gbwbwrgrbwurwuggwwrwwgwrbbwrwwrbrrrrbuwuurrburruu
bgugggbbburbbbrguurbgrugwwgggurugbuubuugubwrwr
wrgbrrrbwwurbgbgbwbuuwbwwbugbgbugrwgwuuubugwrggwwbbbwggwgwrb
wwbwbbrwrbruwrurwurwggwwbrbuugbugbrwgubggrr
brbubbburuwgrbuwwuwrurrwwubrwugwbgburgwrggbwuwrguwgwuu
rwurrbrggrrgbbgbuububrrwbguwrgbwruwgrrruburuurwwrwbuwgbbr
bwggbuggrwuubrrwubuwrgwrbuwwurugrbbguuwrrugbgburggububww
gruuwburbbgbrbwgugwgwuurgububuwugguwuwwrbw
grrbgwbwrbrwgwrwuugwbbgrrggggwuwgwugbbgugwbrugwbwu
rugruggwruburugwugrgwbugwwugwuwrrgrgrggubrgbwgwwwg
urubrbgbgrgwwgwbrgbbwbrruuruuruuururggubwr
burbwguggwrggrwggubuurrgwbgwggwrugwwuubgrbwbgrrbug
wwbwgrrwbwwbrugrbgwgwgrwwggwbrbwbgggguuubwbgbburguggub
urrbbbburgwbwbbwrgubbggrwbbubuwrgggubggwrb
ggugrbggurrbggrwruwgrbrwgwbuurrgrwwwgugurrrbwgbbrbbggwrb
bwgubwruwrgbrbwgbwbbgbwbgrbbruubbuugwburwrb
gwrbbrwugurrbugrbgruwruwrwwguwubwubwbrwgrruggrr
rwgubrrugrwwwubrwwwrbrwwrbgruwgrubbgwgrwrb
brrbwgwgwggugbgrrrrgggubbwwwuururbgbrwugwbrbrbwuuwru
urbrurgrbgguguguuruwurgugwwgrubggbgbwwwgrbugubwggr
rbgruguwrurwbgwgurrwrrrggugrwwbrbrbwgubuwubruubwrurrgwbgbwrb
ggbwuuuwggggrububwwrurgbrbrubbwgbbbgbbbgbwuwwgggbwrbuwrb
rbbbburwggwurrrrbggwgwwrurubwbgbrbruguwwrwrgggrugubw
rgwgwwrgbrgrwgrrbrburwbwuugbgrwwwggrwrbbwrb
ubgrwwwuubwwwwgbbrurbuuruuurrbuwggbbuurgrrwrgwb
wgwwuruurbgwruugrwgrbugrbbwbgwwgguubrwrrbr
bwrwubggwgrrubgrrwuwuuugruuuubuwbrbbwrrbgrwugwgwugrguwrb
rguwgwugururbwwgwwwgwgwbugubbrbrgwrwgguguwbwruwrrrbgbu
wuuuugurbwrgbuugbrrwgggwwwrwrrrrgwrwggwrbb
wwbwbugrwbbuwwwrwrrrubrbgwwwburwgbgbwwbuwrwugguurbg
ubgbuubgrrwruwugwbwbwbwwgbwbuurwwuwbubwrbug
uubgrgrrugubggggwgrbgbrwrwbrgrwbbwgrburrbr
gbwwugwbgggrbguurbrburbwwrugguwbugwwugbuwwbguu
wuwgrgrgwgrbuwgrbgburuuwrbwguuwuruwgbwwubwwbururbw
wwrwgugurwrbbbrwbwubggguuwrwbuurbwbwubggbbuurrwwbubuwrg
bburgruburubrbwrwwwbrgrbuwgwrwggurburubrgwgbbruw
ubrwbwubbbbwbwgruwuuwbrgbuwwuwuurrrwrrrwgb
wwwwrbrrguwugugbgrggrubbrgrurggbgbuwwbrgggwuguwugbrwg
rbrbbuwrubbbugbgwgurggrgbwrrurbburwrwggruwrubgbgwwuuu
wuuugbgwgggburrrrgwbubbbgrubbgburwrbugbbwbwggrgrg
rugwgubuwurrguwbwwurrggrgrurgwbbwbubwwgbgrubruuuwwbu
bgburwubrrwburrbwgwuwwwwurwuuwbgbgrwggubuwubwwggrwrb
uurbururruggwrwuwbguwwwbbwrbbwrggwrgbwwugwrwuwrw
bburugbugwwwwggggwruwwggrwwrbrrbwgbbbuwgwgbwwwubgrgbwrw
rgggubrrbgugguwwuuwurgubgwrbuwubwburwuubrgb
rwrgwbrbbwrbuwwuurgwuwwbrbrwuububrgubbrbwrguruuub
uuugrguwruwwuwuuwgbbrrwwgruuwbbgwguwwruuwrb
bubbubgwwuurgwrbuuurrwrwwrurwgbwugguwgbbggggww
uwruwuguubrrbbggbgrbwrwwwbwwwggggruuuguuugbwrwwrgw
gururwuubwbbugububgwugbugguwuwgwrugbrwrwrb
wrrbwuuwbwbubgwrruwgguwgrbggubrgbgugrrgrubwwwbwbr
rbgwbgwububrrrwbuwwwwgrurwrbwrgurwruggguggurrrubbbwrwgww
wggbrggbrrgbrrgrggwbbwurbbrgugugrbrgrwwbrgubwrwuuruubwugwrb
rrgbggurbrwuwrgrbbwwubguwgurugurwurwbgwrrbbwwuwwbg
wbbggrwrgruwgrbrgburwggrrbbbguurgubbuwbruwwrggrbr
wubugrwrrwuuugwuubgrubbbbgurguwgrwgruwwruguburwuwu
wbwuggubbrwugwbwrrwurgubuurrrubrgwbruugrgbrrbrugbwrruwuubwrb
rrbuwruwguburwgugrwgwuguwuubgurggrbuugbuwrb
wrrbuwggurrggwubgwwuggbwuuwwurrrwwrwurrburgwbwugrgbuwwrwrb
grrurwggwgruwrrbbwuugrwgrgggbrgubggbugugrwrb
wwwrwbuuwgbugbwurrgwuwbuuwrbuurugurwbuuuburrurwrb
ruruggbgwbggrwwrwrbrrgwuguwwrwurrguwugurbbruwbrwuu
uwuuggwurgbwrrrbruwrrwrurgrwrbrwugrwbbburwurbwbru
rrbwuwgrwuugwguugbrwgubrbubgguwrugrwbwrrbggbgrrrugrbbgr
rgggrbugbubburuwwbrrrbuubrrwubuuuwgbgguuuurrubrwwuwwugrbwrb
urrgwwwrgwrrgurrgwbbrggwrgubwgwwwugruuubuuwggbuur
gbuguuwwrbggrwrrubwwgrbwrurugrwrguuuugwgwrrrgubgbwb
gwugrrwrgubuwggwrrguubugwrbururwgbwgbbugwwwrb
bruuwuwbgrbrwbwwubrbbwrgwubgggwugbuwgbrwbbwruubgwbbrwwwubg
wwgurbbbbbwbwwrwguwbrururbwurgbgwurrurbgur
wwrgwuurruwuwugbbrwbwrbbbuwgwwububrwwgggbguwrgwrwrrub
gugwrrrwugugruuwrguwbwwubbggrwbgbwrugbuwrb
rgubwgbggwbbwggwgggrrrgggbuwwrgrwggggrrgwr
gbgrbggbgggggbgugwgubggwrwwwrwgrbrguwuwgwrbbrbuwwgrwuwrb
wwbgrrggrbgrbwbrrrbwrwrwbwrbrrwbwuugggwrb
wbbwbwbgrbwwwuguubbwgugrugbbrbbggrwwurururwggw
uguwrggruugrgwwuubbrbbbgbbgugurruwruwbugwrugubwwbgbwg
ruwbwbrubggruwbrwrurbrrrbgrrwrrgbubbrwrwurwuubwbrruburwuwrb
ugrrbgbbugruruwbgbbbgwbuwgbwugurbrwbgurggbubwwrbb
wbbwrwrwgurubwgbrgwgrgggrguruubburrubwugggrrwgbbrugw
uugwubrgwuuwbrrrbgruuwruwwbuuubgwuwwwuwbruguuuwgrbrwrb
gugubrrggwbuugubrbgwgbubwwgrrurubwwrbbwbrgrr
wrggwguuguuwbgburwwgwgwbruwrgrrwuwwrgbgugurwggbbg
wwuugbgggubwwwgrgrbguguwgwwwgbuwgbugwgwwguwrug
uwuurugbwgbrrbgbbuuwuggbrbrwubwbrggwbgrubbrrggbuubu
gwggubgwgubguwrbggbwwgbuurbbuubuwwugbubwbgbbruu
bbubugbuwwgbgubrbrguwggbbugggbuwuubbwgrwgwg
rrrrwugwuurrrbggrbwbrbrugbrbubugrbubbrguwwwwwrrgwgbuugbu
wrurguruugbwrwbgguggbwruwgbbwgguurwbgubwruuwru
rwbbwbrbwuwrubgbgwrbbuwbgubrgbwrrwwuwgbrwgurgubburuug
ggwubrwwuggrrwbuuubwwgbbgwurwgrgwwuwubbrgruurugwuguggurg
bbrugurbrurbgrbubwurrubbrbbgugwbbbwuuuwrb
wwgwwbruuuruwggbbwuuuubgwbubrbgwbwwuruuguw
gburwbwbgrbwbgrugbuwubgrrbrrggbuwwrwrwbguuuu
uwuwgrbggbrwgwggwwgbrrwburuuguwbbwwwrgurbgurrwgwurguwrbwu
rbwrbuwrwgbbwwggrbwbwwggrwguwggbwrgbrrubgubgugwbrruwwrb
bbuggbgbwgwrrrggbubrggrurugubuwbwuguwbugrrggwuwbwrggbwb
ugggrbwgwuubwwggggwuwwwruuugrrguwwbwubrrwugwrrurwgbg
bwgrgbubgbuurggguubwwrwgbubgrrgrgugwrguwruwbrbwrwbbwbbbb
wrrrbgrbggruggbbuwwuubrruwgbuuubgwbguurrubbubb
rbwrrrrubruuwgrgrbgwwwurwurgwbugrbbwwgggugbu
ugbggrgrguwwwggbruuruubwwgbwuggwbrwbwwbrbwubrubgbrrgwuwrwrb
rwrbrubwbburrurbuwgrrrgurwgrwbrgwgwwrbwgbrwr
wbwrbruubggrgwbbrbgrbuwwrrrbwwburwgwguubuwguwbrgubbwrbrbwrb
rgrrbwrgwbbuuuruuwbrubbbuburguuburrbgrwbgruwru
gwrgrrbubrwgurwgruwguurgruruubgubguggbbwwrb
wgbbuwurburbwwurgbgbwgggruggwurbwuwbubrwrrwbburbgrwgug
ubugbggwuwguwwwuwugwbwgwwuuuggrrrrubwwubwbwrwrrugwbwrgwuu
rubggguguuwgbuwggrruwrwrgruruguurrubwuwrgruwwgrrurbwuw
wurbburwrubbwbwrruwrbrbuuugurbwuwwgrbrbggwwbgugubrrg
gugruugwruwuwrugbgurguguuwwbbrwrurrgubwbwbrgbwrb
wugrbrbgwbbuuwrrgrbwgwrruuuubrbruwggurgbrg
rurwugugguurgubwbuuuurrrwbrrurbwruurwugrubrgubwrub
rubgwwrrwwwgguuggbwuruwwggbrubwbrwgubrrgrwwbuwggbbburwurbwrb
wbbbggwuwbwwgguruwguwbugwgruwwrwrgggurwwuwbbwubgu
bgbwbbwruuugugbrwburuwwrwbbbuggugbwubrrwgwugbwguguuuwru
rbrwwwwwgbruwguuuuubruuurgbuubrwbrbrwurgburbub
grruruwbrwwrbgrgbgrwuwrgwwuwbbwgrrrrrrrrrggbbbwbbbbu
urrwbbbrwuggrggbgububbrbubuwggwuugwurbbbwbbrwrb
rwwubggwrrbuurwwrrruuuruwggggwbbuwurrurugg
bgrbrruwrrgrwbwruwbwbguugbrrggrbgububwbuubrububggugg
rwruuwbuwruuwrrwgbwwrbwwwbwwrwwuuggbggwbbrbbbwwg
rrgwrgwubgwrwugbuurgruburburuwwwbwwwwrgwwrgwrgrgg
wgwrrgwwurrrubwgwrgbrbwgbbubrrrgugwwguubuwrbbb
gurggwuurwwurwrggugwugrbwubggwwwugrbubwrubbuw
uruuwurrggwbgrugrrbbubwbwwggbuuugwgrwbuuuugrrwbr
wbbguguuwuubwwrbrbbrugwrwuuwgrggbbwurrubrrgwwrb
rruuugbgbgrrwwrwgrbugburbubuuggurguugbwgggwrwwbubb
brbgwwbgrugurrgurbbwbrwubbrbrrwugwrwugrwwrb
buurubwuubrwbugwbbrrgwbgubrggubwurggwbrwwrrurubwrgrrg
wbrbrrrgrrbwubwgrwubgrgrwuubbgwwwugbwruwugwwgubww
uwrgbrubwbuubuurrrbwuguwbggurbubuwgwbwrggbggbwruwuggguwbw
gwbwgbwbgrwbgbbbrwwggbgrurgrwguwgrbruuwbugwrbuwwbwrb
guwbwbrwgbgrrrbbrbruwwbbuwwggbwrrbuubugwbrwrb
wrubrurubbbuguurrbguugwurwuuuwgubrwbbgguwwbbbwwwrbwgwuwgr
rurgbrrbwwbgwbubuggwugrubbgwwwrubuuwbgwgbgwugrrugrub
rwugwrwwbuggwbugbbwrbwwruggbgrwuugruurgrbwwbuwwurubgbr
bwbwuuubbgurgrgrbggrubuuwrugwgwuwggwrggbrbwubwgwguwwrb
urrgurwuwwggrubgrrwrugbbgbbbgwrguggrbuggrgrgwrb
wuwurrrrwbwgwwggurwuwbrrgrburggbwgrggbgrbrrggburrggwwrb
ubugrbugubbwgbbbwwgwgwgbguwwbrgbrgwubbwgwwruubgrgrrrb
gurwwrggbbbburwbgububbrwrggbuwgbwrbrrugburgrgbu
ubgbbrrbubrrubbggrbgwbwrbrwubwuurgwbburwwgr
gwbrrgwgubbbbrrubwgrguguggwwrbggrwrwuuururwrwguwgrbuwbuuwrb
ggbubbbbwruuggrwwuuwbbwubgbururrggrbbwgwrb
rgbbrgrwgrruwrwbuurgugbrububrugbgwruwbrurbrwwuwbbrgbbrugr
urruuurggrwgugbgrwgubrbbbbwuwrrwgrubrurgrbuwrgwu
bbwwwwrbbuwubgrrgurbbruwrbrwguwrbwrurwwwbbuwgruubwwwrb
rbrggubbuwguwbggbrrbbwrrurrrbuuuggugububbbbwrrwb
ugwgwwwrwruugwrwrbuggwuuwgbubwgrbrwwgrggrrgrbrbgbbwgwrb
ggugburbbrgrrwgwbwbwruuwugrbrrrurgwrbrrbrwubr
ububbrggggrbruugrubrwrbgbwggwrbrwubggubgggrrgbubrrgrwrb
rrgwwwrugrurwuggggwrbbwugwwwwububgbrbguwwwguwguwrb
uuwwwrbgrrbwgwuwrwwwgwwwrbbrbuggwwuguurwgwrb
gurrrubbgwubwuggrrwwbbubbrgbgubruwrgubggrwgrburrrrg
uwugubuuwurruwruubgbgbwwggbrwgwgrbbuwugwrb
wwwrbwrbwwgbrbrwbrggrgwrurrbrbwuruuburbubguwwugggrbwgwgb
wbgugurgwrrbbwugwbrwuwrwruruwrrugrruugwuggggw
rwbrwwgrgwwgrwgwbgwrwrwguubuwwbguwggubwggwwbww
rggrruwggwrrgggbrruwrgbuggbbgbwbwgurwrugwbgwwwr
gbbwrgwwrwgguurbggrbgbwggbbbuuwururrgrgwgbgg
wbgruwwwubrbugwbuwuubwgrubguwgwbrubrgwwwgwbgwwrrugbgbub
ugbwugubwgwbuggrurguwwubwrrurrbrgurrbrubwuwrwwwwwgwwgrwwbw
wrwubuguggbrrbugwbwwwrguuuguubwuruugwbgwbguurgwwbggrwwbuwrb
uuugbgrgwrugwguuuuurwgggrburwwgbwrurwbgrrwrb
wbgwguuwbbuwggubrrwbgrgbwuwrgbubruwggbrrubbwg
ubuwbrwbbbwbguuwgugrbuwwrgugwubgrburbgbbrrgrubbbbbu
ugbubrurbgwgwwgrurbwugbwwwbbgbugbbbuggrwgrbugbgwwbuwrbuwrb
wgrwwuugurbgrrgwwbwrubrgrrwwubgbuggwbbuwubu
gbuwrwbrrrwrwbwwrgbugrbugbrurrgggrgwgwgrrbgubrr
wugbuggubuggbrggubwgggbgbgbgurrgwwbrwwwwrb
grgugwubbugurgbguwbgbrugwbugbrrwubwrwuwrgbrugrgwrwrb
guruwwrurwurwugbbrbwwwwubuwrwuuwwugwruwbggbbb
bguruwbbggggbgugrbgrrrgubbbrubwrrwrwubrwgrurw
wbbrbbrgbbgguwbruuguwbbbrbrgrubgugwrgbrrgrwruguwrb
wgrbrgbrgwurggggurwwwggubbggrrrgrubugwuggb
bbwuwwrwrrubruuggwwbrurbgwururwggwwrrrurrww
ubwuugrgwuuuwururbrguurgrbwwwrrwbwruwrgwururbugrwrru
rgbbrwbbguggwbrwwbbgrburwbbwwgbrbwbbubwwrb
uuwuuubgurwwggwwbbbgbgbwbrrgbrrwrbbuwwwgubgggbbrwbrr
gbuurwggrrggbbrgbuuwrgrggrwgwwrwugugwbgwwbrr
bwbrgwbrgwwubrgubbbuwbrubwrbgbrrbbbbwrwbgwguuuuubrgrgrw
guwguururgwuwuuwgwbruguwbbubuwbrggwwugrwruruuugrwrb
grgwuuwrbbgrrgggbwrugbgwbbbrwuuwuwgbwugwruurrrbbuggrwwwru
buwggggwrrrruburwbrugrwrrgwuguwggwbwbgugrgugwwurbbburrggw
ugrwgbbwwwbbgruubgguuruuuururwwbuugbgwwrgubrrbuwwugggw
wbrbbugwgburbgrbgrurrbwwwrbwbwubbgrurrurwwrrbwgbugugw
ugugwbwwgrrgrgbuubwrwbrrurrgbubggwrgbugwrgbggubbruubgw
bwwubbgwwrrwruuruguugugrwgwubbguburuurwguwbwrwrb
brrbwugubgwrgurrrgrbbrwrurugrugwuggwrgrbrwggwbbuwurrwwruwrb
rwbbrbgwgbwguwgbgwurgrbuurugrrgwuwuurubrbgr
uwwbuuwgbwgggwrububuugrwurgggwgbwbubuurgbwrrwbbrwuruwrrrb
bbgwbwrrruurwwugbggbbguggguurrbbbbuubbwbwrwbrwurrbuwgrb
gwgwbwgguwwrwugugwuuwurwgwgbuwgbgbwwuurwwggrubb
rgburwwwuurrgbuwrgwrbugwwgguwwwgbubuuggrwbgubrwrgwugwbuwb
gurrbwgburruggbrbuguugbguruwurbuugbrgbguguuuubwggrwgrrwbwwrb
ruggwuwgbgguwwuburgruwrbgbubbwwugrbwuwwbrbrrwbg
wwbrrgguwbbguubbuuuuugwbbrwrrgrruwrgwwrbbbbwgrgw
bwbrwbwwrwwuugugugbrbrbrrbwrwrruguwuwwubbugwgurrr
wggrwwubuwruwgugrguggugwbbggugruuggrwbggrwbbw
gbgubgbwgurbwrrrgbuwwguwrrwwbwuwuwbgburrbgwbgwr
grrububuwruwrubrgwwbrrgrbwugrggwbrgbwwrb
uguuggrrwubrgrwggububbwgbbwgrwurwwwgwbubbbruggrwbrbgwrb
brgurrbwwugubrrgurrbbrbuubbwwwwguwwgrwwugubgruruu
wrwubrrwburuwbrgwwuggurwrrwbbruruuwuwuwubbubuuu
bwbugbrrbwugbwrubuwbuwwubbbguwbrgwwurbgugrgrwgwuwwbwubgwrwrb
bwguwgurgurrrbgbbbwbrrrwuwbrwubruuwrbwrb
rbubgwbubuwwbubbrgwwgubgwwrrgbubrwbbrwwrbwwuwgbbwrb
wrbbgwburwwwrgwggggrrbubbggrbgbggwurwruburwubrubrgr
rggurrwwgururrgrwwwgrugwwbguurbbwbuwrwurrrbrggbbbbrwwr
ugwwgwrgrgugrbbbbubrwrubrbguwbrwubgrwgrrgbgggwugw
uwgrgbugbwbbggrgrbbgrwrbggrrwbbwbugwrwbrrwwuuwrb
bguubugwggwguuggbguuwbgwbwruggwrbgbrrbwbrrbgwrbggwrbrrbu
rgwwbubbbbuugubwbrwuwwrrruuwggrbbrbwguwruuubgbwwgwurbgbubg
uuwbwbrwwubbrwuuuwuwwgggwwubburgwgwbrurrwbrbgbbburwgb
wwrrbbwwbruwbgbggbrbbgrugubggwgggugrbuurgrbbgbuwu
ugrbwbwwgggwrgbbguugrgggwrggbuuwuwubrgbruwbwrb
ubggwbwguugbbubbgbbguubwuubrbwubrubrwguwwwrb
rugburrbwruuwrwwgwrwggrubgwbuuubugbwuurgbg
ggrwrruwggbubrurubgwrbwrgbwgwuwrbbbwbuugwubrubwuwbrbgbgubg
grgwugwuwbgwuuwuugrgwwguwbburuubbbgubbuwgwg
ruwrwrwwrwgwwrgbubgbrbrwwbgurrwrrgbruuwgrgrrrgurugugu
brbwrgurrwgwrruwubrwwwrggbuururgrguwggwbbgrgubrw
bbuwggrbugbbgbguugwuuwuubgwgbbrgugbgbwbrubbbgugwrgrgrgruuwrb
wgbgbubuwrurbuuwgrugwrgrbrwrgwuwbbgwrrrrwrb
wgwrgbbbuurubgwwrgwguururrubgbgwrbgwwwwwggggbrurgrr
uwggrggrbrruwuruwbuwurrrwwwwbuggbguwuubwuwbubrrwrb
ugubbwurwurgwwrburwuugrurguuwruwwrwbgruggwbwwwgwbb
ubwgwbbgbrugguwrggubbrgrbgruuwugbgruuwggrbgwugugwugrrwwg
wggrgugugubgrrrbugbbbwrrrwbwguuruugrwwrb
bwgwwbrwbbubgwubrwwwgurbwbrwbubgbwbubwgbbggrrwbbgbwrbbrr
gurwrbbbrbrurbrrbugrrrguurwwbbwugwbubuwrwbrgbgrwrbuuwrbuuw
gwwwwuuubuguwwurubwwrggguwgbrbbbgbububgwrbwbubbruwbb
uwwwbbggwrgbrgrubrurwrgugrbubuwwruugbwbgubugbuguuuuurbrgr
rrbubwbuwrgrrugubbbuuuwwbwgurrwwgwburubwrwrb
rurrbbgurbuuruwuuwrurrwbbggrrrgguwgwrurgrurubwrwwrb
ugbugurrgggrgrbuuwgbuugrrgbuuwugbrwrrgbubbbbburuuuwww
wuwgugruburwguwrwgwbwrbubbrbgwbrgbwruruwbbuwwwugurwgurwrbbb
wugwbruwuggrruggrbgrgubuubgurbrrrruwrguububruubwugwwbbwbu
grubuwwurrbbggwbwwwruuuuubwgwubwuubuuwrrrwgrururbggbbggw
gwgrwbuwuwgwrubbgbugrgwbgrbwbuwgrggbwrrubbuggwbgrwgbggg
uruwrwuwbrbrwwruwgurrugrbwguuubwrwwurubgrbgrgwwur
rguubrwwgubuwwruruwbuggbrburgrgurugwwwwrb
uuubuubggrugbgbgwgbbgburuwggrrggwrwruwgbuwwbrgu
gwgrgugwgbwbuwbgwgbrguuguguugrrgrbuugugbrgu
urgrwwwrgurwwrwwwggbgubbrgwwwruwubgbrgurguurwugrgwrb
rubgwbrwbgrruuwbruwrgwbwbguwururubrgwrurbuubww
brurbguurgbggwbbgwwwugbrbgwrwbrwrrbrwbugwuguwrbwru
rwrbbguggugwwgrbrrwrbgruwrwwuugbrgurbwuguwwubgbgg
wgrgbgbwbbggrwgrbbbrrwubgrbrbgwwururguwugbgrgrrug
gwuurwubwwguggwwbbwwugrwgggwwurrrgrrrburguwwrrb
guggrruwrbrugwrwgrbgurbgbrgwugwwwwbbbwwrwuwug
uwgrrgrbbgwrggrwwwgbgbrbbrbuuburbbrbrugwurugwbburgbb
wwwbbbwbbbrbgubrwbbrubugbrgrrrruuwgurrwwwruwgwrguw
uuubuwgwrwugrbggggbruugbrruwuurubwwgwbwgurbgbuubbgwbuww
wbrrwgbuwggubuggrugbwwbbbbwgwrrbgggrrrwrbgrbgg
gbbbrwwggbugrbrrwrgbuwgbrrrwgwgubrruruurwguwb
rrbbuwrbruwruwurbggburwwbwuuwrurbbwrbuurubggwrb
rrubbuurrrgbrwwuwrbwgruuwbbwugrgubgbwwruwbburgbwb
wrwugbbgrbgurubrwwwwwbbbruubwgrgburbwbrgbwbgwb
wwrwugwbbrubugbrrgrwwbwbuwwwuugbbwguruggwgwrwgwrggwrgrgwgwrb
bguwgugwbgwgubwwbwwrwubrrwubbwgrbwgggwuuwgrbgwgwgrwwggrb