From 99cdd765b1404f75604fff17e1e78f5f91dc53af Mon Sep 17 00:00:00 2001 From: Neil Smith Date: Fri, 9 Dec 2016 18:22:20 +0000 Subject: [PATCH] Day 9 --- advent09.hs | 57 +++++++++++++++++++ advent09.txt | 1 + day09.html | 154 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 212 insertions(+) create mode 100644 advent09.hs create mode 100644 advent09.txt create mode 100644 day09.html diff --git a/advent09.hs b/advent09.hs new file mode 100644 index 0000000..a68ce82 --- /dev/null +++ b/advent09.hs @@ -0,0 +1,57 @@ +module Main(main) where + +import Data.List.Split (splitOn) +import Data.Char (isSpace) + +type Chunk = (Int, String) + +main :: IO () +main = do + textL <- readFile "advent09.txt" + let text = filter (not . isSpace) textL + part1 text + part2 text + +part1 :: String -> IO () +part1 text = do + print $ cLength $ decompress text + +part2 :: String -> IO () +part2 text = do + print $ cLength $ decompress2 text + + +decompress :: String -> [Chunk] +decompress text = + if not (null msuf) + then (1, pre):(num, chunk):drest + else [(1, pre)] + where + (pre, msuf) = span ('(' /= ) text + (marker, suf) = span (')' /= ) msuf + ln = splitOn "x" (tail marker) + len = read (ln!!0) :: Int + num = read (ln!!1) :: Int + (chunk, remainder) = splitAt len (tail suf) + drest = decompress remainder + +decompress2 :: String -> [Chunk] +decompress2 text = + if not (null msuf) + then [(1, pre)] ++ mulDchunks ++ drest + else [(1, pre)] + where + (pre, msuf) = span ('(' /= ) text + (marker, suf) = span (')' /= ) msuf + ln = splitOn "x" (tail marker) + len = read (ln!!0) :: Int + num = read (ln!!1) :: Int + (chunk, remainder) = splitAt len (tail suf) + dchunks = decompress2 chunk + mulDchunks = [(dl * num, ds) | (dl, ds) <- dchunks] + drest = decompress2 remainder + +cLength :: [Chunk] -> Int +cLength = sum . map (clen) + where clen (n, t) = n * (length t) + diff --git a/advent09.txt b/advent09.txt new file mode 100644 index 0000000..3ccde78 --- /dev/null +++ b/advent09.txt @@ -0,0 +1 @@ +ORNXNQJQ(151x7)(5x9)OFIXU(27x3)(21x9)VDCYQELDJQUAFZUHFZVSU(34x15)(12x10)SEDIUUVFPEKY(3x9)NHR(1x11)I(15x6)(9x13)CMNDUYGYR(40x6)(4x7)RMNG(25x8)XPDSEYNCWFQFAKUMITWMBLMIK(7x11)(1x10)N(109x1)(101x15)(28x15)DYKYFCKDLFYAIHXSOAZKTPCPBUTX(18x13)SOZMWOSIQHVNMRZYYM(1x4)W(11x2)AJPKYMFRDJZ(11x11)SYIQBGHBNJL(26x9)(20x7)XLNTFHRYHLOYBBGMRPDH(269x4)(2x9)ZG(79x7)(24x3)UBTEBZLPYEDFINUQEQZUSXWY(3x5)IUH(15x10)LDDUEEJAWVGNRYA(3x5)FAO(6x3)ORDEIO(47x2)(1x10)J(2x13)DW(1x8)V(19x14)IJAAZPPGBZPFERJGOYI(103x9)(60x11)GKYOEUBZWAFDXEGWMPXZEOAQCUFCTJCXROPMNEFMJUWGBOUZRAXKRNHTBXHM(15x15)BTYXPHOQZXSBUVT(9x8)JQLNIDKMH(9x5)(4x4)BQRL(4207x15)(1464x12)(305x10)(159x14)(71x12)(24x14)(9x1)UJXIVHSUD(4x15)MAWK(26x15)(19x15)YFYDUJPUZQCKGVPOXKD(2x1)HN(2x6)GH(20x14)INJNODCLPWICQFIERROI(3x11)JUA(31x14)IUDVEHRATPGIEGELRDOZMBKZQFONCBD(130x14)(28x15)(22x7)(5x11)PHVKR(5x10)KVTDO(88x12)(8x12)POLKYDEX(27x8)(9x14)APMRPIHKQ(6x11)QTLLQU(1x4)R(29x3)(4x8)WBRL(2x15)JU(1x6)Y(1x2)U(1143x9)(364x14)(262x7)(6x9)EEJMXK(100x12)(5x1)RXXSO(5x2)VTESR(6x2)SXXSZL(49x1)OFIFQJKSCOXPXTHVWCUJVQMDBQELBLDYRKIGKHOEWRFNXNRLF(9x1)XRUFFMDVM(29x5)(3x8)VPW(6x3)WWFWRC(5x7)XMJEJ(46x9)ZBWGRECVBOPHVFQYBPOBHTPOMTYQGVZKQMKYEHCJYSNRQY(50x1)(10x5)SFPYPPQKDO(27x10)DNMTTNUGOQNAQLRBKDLNRVGRMLJ(23x12)(10x7)LCQWCIMTSV(1x12)X(15x9)JMJMKCIELUBETER(38x7)KWZVVWPBHKSBWMQWBJKCRHLIEHZSQBRAEOBRHE(130x13)(123x7)(75x10)(9x2)NUSXXITCS(11x2)JWHCFBJNEYD(10x1)QJNBNHNNDF(5x5)RWBYJ(11x10)GRRSDLTEZAW(35x9)EYHPPDLIWUITRPLKHXFBCUIQZZMYCDKWPNX(326x11)(130x1)(76x9)(9x10)TBCYBWJLT(4x8)HTQB(35x8)FUCOLJQAFSWAYTACMFRACVWDLZYRGSUMZAY(5x15)ZWHCN(17x14)CRUBDKGWUQCGGAIOS(10x7)(4x12)RWFL(3x9)TFR(27x13)(1x7)R(2x14)VY(8x2)DZMFRMGO(94x11)(61x15)(1x14)O(25x14)IKECWOPRWQBVRNEDQXWFMVBOI(15x10)QVTWMBNCISLOBJR(20x1)FIVILFBNIPNRXAWXGAMJ(32x8)LNPRYYKSLCXOEXFWZKAXERCQKDACFNYA(10x1)(4x14)WRAN(292x2)(168x7)(10x8)HQSTVLQCNK(89x4)(9x11)XCBGNGENA(22x5)BLUEARYFSAVBWTDGVHYWZP(21x12)KGRSTMCVPYJXIJWXVXREW(12x5)NKTUQMXCLFNL(17x10)UPUPBQDSHOXKHLGCR(10x12)ALIFHIZXQV(10x1)KEFBFHAOCG(100x2)(9x4)(4x9)MKGZ(80x5)(20x3)DQCKBWWUZDJICWUESBKY(14x9)EFXIDIWRKZTVUM(6x15)JRDKSE(2x14)AA(9x9)MJFTTZMTW(5x3)VLDNV(411x4)(397x1)(390x8)(46x4)(18x7)BLBFCJNGQWPSJGPOVU(16x7)(10x2)FFZWESCTXC(6x3)EUNIDH(56x14)(28x5)(2x8)CJ(2x1)EA(9x9)FLKGEMFED(10x9)OLOMVPKTRZ(1x5)R(202x5)(88x9)(6x3)VRZHGK(20x12)KKZGPZHKVMLDUKNRPDLL(7x2)CBDBTRO(3x15)XPR(23x3)EHEWCFLEUPCSTSISPKGXIMK(32x5)(16x12)KENYBOSVRILLLTVM(3x14)DYH(19x4)(7x8)FGHRXWB(1x15)E(39x8)(9x11)XRLWASPXI(17x10)RNFIHAQMBBELSLNCT(49x1)(36x4)(18x2)QKRMYMDFPSVDXUXXCH(7x3)SBFHWUF(2x6)BD(2x6)HN(1047x3)(450x2)(10x4)YQQDOELWCI(48x15)(25x7)(8x5)KUKZDUYU(7x6)(2x1)KQ(1x4)K(6x3)INDERJ(284x5)(92x7)(86x4)(13x1)PSVECPHBPYEPJ(3x15)JEY(35x8)RCTZOHPJAICRPRVAYZZLUKRZPOOPFCBCPAQ(4x9)TETC(2x11)ZV(179x5)(95x6)(8x9)HUGVMXOT(9x10)MFDYGPUWF(12x2)PSBNZPCWSANA(6x1)GICWEI(32x9)JCBCGJIMZTQUSVQDRHWMSYJYUHJIVYIV(71x13)(15x3)SXTGVVIWXDWZTZO(9x2)RASQPEQUN(7x10)TPHSDTV(7x15)EPAHSDZ(5x6)BIOZT(7x4)KYMJLYA(69x11)(63x5)(3x9)XSS(37x9)HTZKRPESNZRIWPGWAPHBOIOWAWFHWMIXWYQQC(7x6)(2x1)FA(273x3)(245x12)(39x9)(8x13)WCKBPVRZ(18x10)(11x10)VHBAIPPIWXD(2x3)XD(1x11)Q(6x15)WCPPQC(167x1)(23x15)DYHQGULKPISILTRIXNEJZAV(65x12)(2x9)FZ(14x9)WWCTYVLVAOZDAG(15x11)CZYGTNAELLIRKYW(10x6)IEXFBJJCLQ(42x4)(9x14)XRPJHVVME(6x8)XAVNCD(10x9)IBVGVWIFUD(11x7)(6x6)LSMIRR(14x4)LFACCTXVWLEDWE(287x5)(280x2)(273x1)(7x14)(1x15)U(109x12)(7x1)TPNMYVS(46x8)TWTINTRPDOQKPDPZNKXIVISRQTZODBXMSPPZKCQFAYCJCS(5x11)AKNKA(18x14)DKSKSQUAUTPZPNHIWP(4x7)DOMY(56x3)(6x6)JBJ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FUCESZDMF(9x15)(4x3)JZSU(7x12)(2x9)UZ(228x2)(220x15)(49x2)(1x10)C(5x9)TCPJZ(6x7)FJSPSS(4x14)FYQF(5x15)XBWKH(75x10)(5x15)KTHBO(12x5)LLZEFONZKCBI(28x5)RGMNFEEHBHZJKTMPVEPHIOJUXOMB(7x9)YWTZNCT(60x14)(3x10)DAN(15x6)BHOSLMFSEQKOGEX(1x4)D(17x11)SULIDVKKLXIWAJXRK(2x7)PX(4x1)TKPO(9x8)QFXUEZUGP(2331x2)(2323x8)(202x13)(10x13)(4x14)GFSR(178x4)(101x11)(21x9)(5x9)SWRRL(6x8)TYXYPJ(68x5)(4x10)QMJZ(19x15)APBTUGYPJQFQODZRNAC(5x13)YIVAO(14x14)QHWPZNQSRZJIEC(63x2)(32x10)(5x4)EVMQL(15x12)SAOYGPDXFSDOBTB(6x8)(1x5)C(7x13)MILUDKF(144x5)(3x8)PLQ(129x7)(27x3)(7x13)QLVZTAJ(9x4)JNLNRKPXA(4x13)EEXX(17x9)(11x9)SYQBWQASJPK(57x8)(29x8)(15x11)CFVXGJKXAAKNRRT(1x15)A(1x4)C(10x5)EFFLNXDEVJ(664x6)(357x6)(82x8)(7x12)LPCKKIX(55x10)(6x4)KXJNIR(2x4)IH(5x6)VIUMV(11x10)TCNXEQRMQJZ(4x7)DREZ(2x8)IV(119x7)(21x13)RHDEMDBNRPLOTSZRKZSHA(47x2)(22x2)ZADHZNUARPTFHKEXJKCWXY(7x6)OACRTYP(1x15)P(31x10)(5x4)VSWJT(7x1)IGAMFHI(4x3)GOCU(26x5)(19x13)(12x15)WGYBKVRPMWJT(15x7)IFUICWKGGCLHCOO(83x12)(62x8)(20x10)TJBGZCIWVKOROYITLBUA(7x11)UDSMGLK(6x3)FWPTWW(6x4)JECWEE(9x13)CUQMJOFWT(292x11)(68x14)(61x13)(28x10)ZRYXMSXXTLGDYHOVDRDVOCFJTCXJ(20x7)HZCFVXJATHXTNPHWFSIS(65x4)(11x6)BETMULBEIND(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ZIVNOIVEHGXDP(19x11)CDJEUHEPCUEYVLGYLTJ(311x11)(165x1)(16x7)MUMPDQFLGFEGIYLU(9x11)(3x11)FNP(1x14)U(60x4)(4x7)KDWX(4x1)LKMS(27x11)MIELWFKZJUSUYBARAGTJAZIBEDH(3x1)LDI(48x15)(10x15)DUUYAIZHKY(5x8)KEMNC(14x10)HZTAHRSCICOTIR(4x13)AUNU(45x2)FRDBNRZYFZLCAIEVZWSAIMLGBCDSBHXFPWRPYJRQHNWUZ(28x8)TCHELUEWWRHMIGBKEUCWBTIEVNCB(37x10)(30x11)(6x9)PLWKRH(2x3)PL(7x2)MAFSJHV(6697x8)(172x15)(164x10)(1x9)N(151x2)(7x2)MOYJQSA(24x4)BSZRAIBTDPFAAHQWOWDJJRCW(34x10)(2x15)QB(1x1)T(4x3)ALVX(6x7)SQFSKZ(2x11)JX(54x2)(47x14)(6x12)HOALAK(28x10)DGCVKLTWNKGAGRGSWPVEUGRDAGWA(2577x12)(88x14)(82x9)(48x2)(41x11)(4x5)KAVK(15x4)LCMPETDQZUWBRCL(6x9)CFZJGS(7x15)PGVNKAY(9x12)(4x4)NHID(827x3)(259x9)(153x12)(27x11)(21x4)PQNSUYEFBRAAVCJFJPPGZ(13x4)(7x10)NNSUBSG(70x11)LOGUFNQNLSWWQXBPQIWNJIEDRFUCRCUAVANHFGDEMQZRGSITBSBLZXVWJGXPPDZEXZQCEU(7x10)DTIEEXA(4x13)DDNZ(44x13)(37x14)(8x14)NIJOMVGP(17x1)MDXVVVWIZSXMSGJMC(4x4)ARFY(31x11)(10x14)RVZUREXEUI(1x7)M(3x5)LXC(170x5)(114x3)(83x3)(19x10)UUCHMGESOOTJCTEJVRM(3x5)ZCP(2x10)IU(25x6)TNLNLUTXNPNDWMXGVVGIPVWJL(4x12)JAAA(13x1)UFQFFPMZGZNNN(1x1)V(27x5)EDPBYCEAMMWAIPWUZODVDAWPWIJ(10x1)(4x10)VJHN(73x13)(66x12)(5x1)TAFQR(11x5)(6x8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)KEYESARBBXHWWQWPQVC(1x11)A(9x12)LMADFIHXJ(6x5)MZVRQU(40x12)TOSAJVXJHKVWJKLTVBIUKKESOFCKFOPSXHYCMDXQ(8x15)XGHEISVJ(68x5)(62x3)(4x7)OOWZ(7x15)QNNVWUX(5x10)GSLOA(14x8)(1x8)B(3x3)HJL(3x11)EIK(450x6)(101x9)(30x8)(2x5)MM(17x8)GHTHOCTDDQAYBUVWP(59x8)(1x5)R(3x11)HYR(21x2)STLZXNENUFTGYWNQJHFUK(10x10)NGMEAWPFBI(28x3)LNDWFXKPRAOWKJHWZZIYLJLOOBKK(110x6)(14x2)SALGMMEIINEJOU(40x7)(4x13)AIMA(5x12)GSAFV(13x7)CSLJJRZIBBUMF(21x1)(15x9)THPSZDCPWASRUYR(2x5)EE(5x7)XDUPK(13x10)(7x13)SFWIYYQ(163x10)(26x15)(13x9)HQJQXZQCIHSAE(1x15)K(4x15)FMWB(9x12)SQVQTEWMD(41x3)(13x1)EEYHHJQCDSYRO(9x2)YCDDFHWTG(3x9)LGW(51x12)(7x14)OITBFQF(8x13)FZVMIWUM(9x8)XTZCNFOTE(4x15)KTHY(221x10)(213x14)(32x3)(26x3)GEUNPCYFYLTFFXOKWXFBDYLBMK(77x1)(41x14)(7x11)XBMCCZD(21x11)KFOJGBJCEHPTKBLUSTERX(10x4)IZWNLBDABA(8x3)IVDWYIMO(50x9)(6x5)(1x1)H(4x8)VDKE(2x5)QE(17x3)(11x7)KGYMJEMQVWS(9x4)EVWJYLBBQ(16x8)XZDDQZQPCOLVIYGD(3001x2)(724x14)(235x12)(227x11)(25x5)(1x10)N(3x4)QSO(5x3)XPKCV(24x8)(11x10)XXOIOGOKIOD(1x8)B(88x4)(1x12)I(10x6)CEIKKPKUJG(1x11)Y(6x8)QAYNKJ(41x7)BGKQCYZZGRQGCNXSGYHAXMWIJOPDKLMAQRKGFRBML(66x9)(14x12)YTKTEIISOWYZWB(3x13)UDK(12x2)PXDYSSCHAFSE(2x2)DA(6x1)UZSORT(309x1)(107x1)(81x11)(23x4)UHLCPASWMUWBQPYJSUHUFEO(5x1)NTMAV(26x7)JDNTOBRNEUELJIISZGKNRYSBRE(4x10)FVKZ(13x8)SBNXXTKLMDHII(138x4)(62x12)(55x12)OMRRSQWFPEAXAXHFHHQBWGCESBLWZBVYEQQKYRGILBNJJCAOXFHDIXU(19x13)(4x5)CVBF(5x9)EBLEV(15x1)(9x13)BATHCHMGP(16x1)BGSXRPQUKQJYDIPV(44x3)(8x1)(3x1)EWQ(7x12)JJIVUYJ(12x7)XJSYYYTSZBHD(7x14)EDHTGLH(144x13)(130x4)(12x7)(6x14)CYDLYL(43x2)(4x10)DOTG(4x8)ELJI(6x6)QGMRSQ(1x4)K(2x9)GS(40x2)(11x10)CDHAMRCSTVC(8x11)WMZDTRTD(2x14)XS(11x4)IXUNDJVBLSO(2x3)CH(7x7)(2x5)NF(1015x9)(204x1)(20x10)GPKSBZZRRZGMFICXNMIX(141x9)(24x9)NXNCFLIWVVVQNVKDRUTQYNJB(3x8)AXD(33x6)MDGPOLEPZEUNBDWGBSAFRPEMTKUXIJDRA(33x11)(2x15)PY(5x1)XYUAI(9x14)UPOUZTFRQ(17x10)YAMBZLTZMBSRFZOUK(5x10)NXKJE(11x15)GNJTBTSXLTN(299x9)(29x1)(22x10)(5x13)FSAYZ(5x14)MWJOX(178x9)(79x14)(21x12)WXTCOEECSKHDITBOAAVSF(6x15)INXWKB(8x11)NTSEQSMQ(19x1)UTQUQGUDXSFROLQWKVZ(76x6)(3x2)QOL(10x15)UIGYPYAWRR(7x7)JEELSVH(13x12)RUBSHAXAWQGYF(12x12)PGQUXPKEKXRN(4x15)BQEB(8x4)(3x1)AVE(59x15)(11x11)QGBFDCZTADF(22x8)(7x7)RJEZNHA(4x11)MMJN(8x7)(3x7)GNT(174x1)(166x12)(17x2)ZDOBQSATWXMNNJDCV(17x13)(10x14)CATNORVTYK(95x10)(9x5)LROSBZBVM(29x2)ZQBDHDVQJGZTGKDBOSHXOCV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GN(491x9)(148x8)(36x3)(2x9)MG(13x11)EDWPZURXZWLML(4x1)VRBX(31x11)(14x8)KBLQBMRGRGKHCT(5x14)PRDLH(3x8)CQB(32x15)(10x15)RLWBNSAEHH(3x3)HPB(2x2)PA(15x2)TKPIZXDBJJMAZDR(133x8)(1x6)B(83x8)(13x10)WNSKNXUSTCDKE(4x8)NMAW(6x6)EJRNHD(4x14)MLJN(27x5)ZQBFSJWECOPVETZPGXQJPPDQZEL(22x1)(16x1)ZSEPLZISVDFRGRJB(4x13)YRXG(39x2)(33x7)(16x9)HMRXYWRBVITBVWTG(6x2)LCYRSW(123x13)(31x12)WVTWWQZUYGBJOSPKLUQTAGWXXURUDLI(34x10)(7x5)ZTTMEQS(2x8)YX(9x13)ROIYTCKSX(28x13)(3x9)WPV(13x14)PQHWCFNXKFFOH(3x15)EUZ(14x7)(8x15)UHHVOLEJ(914x15)(782x12)(448x5)(118x6)(26x12)(4x12)BLTT(10x2)REYZXYJJFQ(39x8)(8x6)XEWKRGZT(3x8)ECB(5x9)GOBWQ(3x2)KKM(34x7)(18x11)QSQRCJXLCKUYJBPSWG(4x9)XOSJ(34x5)CIABSNSBNQQKAARJOOETKSXJIPOFQOMAPK(24x13)(3x7)ADL(10x3)RVSLAIXAJJ(67x7)(52x9)(3x2)AJH(3x6)OGK(4x9)SQFL(1x1)T(14x14)BQZZXEWSTOKEUA(3x13)HBM(171x14)(25x9)YKLMFOEYQHSODISORNEKDIGVY(12x6)(6x13)OFJBKW(53x7)(21x11)GINJQDIXMAWRHIHJLXFIP(19x8)SVTFKYTLPWYEWWFIUPB(16x12)(2x1)PB(4x8)TMWZ(33x15)(5x3)QBMUH(10x5)UHNESLDFMY(2x4)WW(9x2)(4x7)QTKW(94x10)(47x10)UUVWDQXOXQUFEROVLOZRXIHEPHTWRPSGHLNSYGNIVHEDQGV(34x3)(21x4)(7x9)IMCZEIB(4x2)TNMA(2x9)DM(192x6)(2x7)ZF(2x3)VU(6x13)DODXJG(158x15)(1x4)K(42x12)(2x8)RM(4x6)YMIM(5x2)BXKIG(10x1)ZWQMIAOBEY(78x8)(7x1)XHAETJV(28x1)QPKULGVENLMJWWEHOROJEESLKYTA(3x5)XMZ(18x1)FZBLVDOKGEZKOBICEO(13x9)MWICPPUEWVWKH(7x10)KVNGSWM(116x10)(26x3)(20x8)(8x12)SSVBYWJX(1x9)H(77x14)(12x3)OWHWKICESREK(1x11)D(46x3)(11x5)(5x15)ORJRA(1x13)K(16x3)XRJXBYVIUITRPPYRRNHU diff --git a/day09.html b/day09.html new file mode 100644 index 0000000..5938ba0 --- /dev/null +++ b/day09.html @@ -0,0 +1,154 @@ + + + + +Day 9 - Advent of Code 2016 + + + + + + +

Advent of Code

Neil Smith (AoC++) 18*

   var y=2016;

+ + + +
+

--- Day 9: Explosives in Cyberspace ---

Wandering around a secure area, you come across a datalink port to a new part of the network. After briefly scanning it for interesting files, you find one file in particular that catches your attention. It's compressed with an experimental format, but fortunately, the documentation for the format is nearby.

+

The format compresses a sequence of characters. Whitespace is ignored. To indicate that some sequence should be repeated, a marker is added to the file, like (10x2). To decompress this marker, take the subsequent 10 characters and repeat them 2 times. Then, continue reading the file after the repeated data. The marker itself is not included in the decompressed output.

+

If parentheses or other characters appear within the data referenced by a marker, that's okay - treat it like normal data, not a marker, and then resume looking for markers after the decompressed section.

+

For example:

+
    +
  • ADVENT contains no markers and decompresses to itself with no changes, resulting in a decompressed length of 6.
  • +
  • A(1x5)BC repeats only the B a total of 5 times, becoming ABBBBBC for a decompressed length of 7.
  • +
  • (3x3)XYZ becomes XYZXYZXYZ for a decompressed length of 9.
  • +
  • A(2x2)BCD(2x2)EFG doubles the BC and EF, becoming ABCBCDEFEFG for a decompressed length of 11.
  • +
  • (6x1)(1x3)A simply becomes (1x3)A - the (1x3) looks like a marker, but because it's within a data section of another marker, it is not treated any differently from the A that comes after it. It has a decompressed length of 6.
  • +
  • X(8x2)(3x3)ABCY becomes X(3x3)ABC(3x3)ABCY (for a decompressed length of 18), because the decompressed data from the (8x2) marker (the (3x3)ABC) is skipped and not processed further.
  • +
+

What is the decompressed length of the file (your puzzle input)? Don't count whitespace.

+
+

Your puzzle answer was 123908.

--- Part Two ---

Apparently, the file actually uses version two of the format.

+

In version two, the only difference is that markers within decompressed data are decompressed. This, the documentation explains, provides much more substantial compression capabilities, allowing many-gigabyte files to be stored in only a few kilobytes.

+

For example:

+
    +
  • (3x3)XYZ still becomes XYZXYZXYZ, as the decompressed section contains no markers.
  • +
  • X(8x2)(3x3)ABCY becomes XABCABCABCABCABCABCY, because the decompressed data from the (8x2) marker is then further decompressed, thus triggering the (3x3) marker twice for a total of six ABC sequences.
  • +
  • (27x12)(20x12)(13x14)(7x10)(1x12)A decompresses into a string of A repeated 241920 times.
  • +
  • (25x3)(3x3)ABC(2x3)XY(5x2)PQRSTX(18x9)(3x2)TWO(5x7)SEVEN becomes 445 characters long.
  • +
+

Unfortunately, the computer you brought probably doesn't have enough memory to actually decompress the file; you'll have to come up with another way to get its decompressed length.

+

What is the decompressed length of the file using this improved format?

+
+

Your puzzle answer was 10755693147.

Both parts of this puzzle are complete! They provide two gold stars: **

+

At this point, you should return to your advent calendar and try another puzzle.

+

If you still want to see it, you can get your puzzle input.

+

You can also this puzzle.

+
+ + + + + + \ No newline at end of file -- 2.34.1