In [1]:
library(stringr)
In [2]:
input <- "(22x11)(3x5)ICQ(9x5)IYUPTHPKX(127x2)(41x6)(16x9)SIUZCKMFZFXKUYTQ(13x3)YBCVHJPPFAONV(10x14)BTRWBQRUHA(57x4)(12x15)ZUMPYOEOOBFW(5x11)YNLIJ(8x9)GBQFPTOH(9x3)GPFCSAPZD(29x4)(5x15)EFWZC(12x4)(7x5)ERKGRCO(145x10)(4x6)QPQJ(36x5)AXJPYRPXJNUYIMCCYQIFAHELCWHVENPFFUDA(68x9)(14x15)EMRKZDNYNDIJHZ(5x12)CKQKZ(17x8)NBRXQIMACOZLIPEMC(8x7)BBLDSICW(1x11)M(7x11)FLYGTGJ(78x11)(9x6)DHGXUSOKT(22x8)(1x7)X(10x5)KRJUANGDCJ(1x6)V(4x12)VCOH(14x1)WDBRKJHMCVSNVI(9x6)YUGDHWETA(93x12)(8x15)(3x7)SVK(6x13)(1x7)Y(60x10)(15x15)LKKAVGRGFZABIBU(32x3)YOFMNLNRJRINIZCCYLKLUOFWVWXFDXQR(28x15)(22x6)(1x15)X(2x8)WT(3x7)SGS(9154x10)(3069x9)(1176x8)(349x15)(6x10)FHKHUN(50x12)(5x6)IEEKH(4x2)DHEG(1x4)O(18x14)YTXWGQAJVTUHRZHTPY(55x8)(48x10)(1x3)I(3x12)JRS(1x9)F(20x12)HXVRCJMSGSCGSBLAUVJJ(134x14)(57x1)(7x7)SDSUJPL(2x12)JM(3x9)YCW(7x2)ZWLPPDY(11x3)GMQBJDOWHXQ(35x11)(5x9)IIEIX(1x8)S(12x15)AQOUQNNNQMFD(22x12)OTYVCAUYJACBXRRQCQHXNM(71x1)(7x7)WOHKEXX(5x10)LZMIE(2x7)AY(35x4)(17x8)DOPOULZLKOXMLSVNU(7x5)KEKYTGL(2x14)LQ(480x2)(276x15)(197x5)(27x10)JSPSRSOZEKYBVYQLDOHBLZYSXAW(21x4)UMMABURKONXVVCIDVULSI(8x5)VMBUJKXG(16x2)IVRUXQSEFOLCTKOY(94x10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(51x7)(7x11)QSJERFT(11x6)FOHQRGIGNHD(2x2)FO(9x8)FVOSYSGOQ(20x7)RXXISOFDENOWQDLGGWGS(1x2)Q(9x11)QFQVFWUKV(79x3)(4x3)JESH(42x5)(4x10)HLPY(25x10)UOJHBIMVYNSCNYAVXVZFDKFUD(1x12)W(9x13)SWEHSNTYH(365x3)(358x4)(5x8)PSVSY(53x14)(39x13)(11x1)BZVYURTWDXO(8x15)IFLFXMTW(3x7)OWX(2x3)EY(141x2)(55x3)(3x3)GFW(24x3)FAEVVTFKPGLONEZAPTIFWKAY(1x11)A(4x10)LRSZ(37x12)(2x15)MB(2x4)QF(4x3)QTQD(7x14)ITPBCPO(22x15)(1x8)P(10x2)OPYYYSMAZD(2x6)DR(121x4)(24x10)ZDFXFCGIZSAEEISWYLIWOSHV(2x14)IE(75x15)(17x5)JNPVHILACIRBRVFOV(13x8)LKESWWFWMREZR(4x15)FMVW(17x4)UNAKDRSCVCBWOJUAG(7x4)(1x14)F(884x10)(11x13)UIJLAOENTIO(525x6)(198x10)(3x12)VVK(10x13)CDFZVNZRXN(89x14)(29x4)RGMMJYVTUSTNURKJUGAROSPANJDRP(5x4)DDMAL(4x12)ZUFB(13x1)FRZPWDKILEKPW(9x15)HQRFMVQKA(28x2)(12x15)UYMVCFZGVAPZ(4x3)VCFF(35x15)(9x3)SHOEBNTLG(6x2)OEZGQV(5x1)PMPMS(12x8)CJOKQADNVIFP(193x9)(49x13)(11x15)YSUAHEFQFGE(24x13)BFPKROZXMUJAPOPTDUAVPDYA(5x4)JCKOZ(10x7)AKOWVCYMBR(5x1)QVUIE(95x8)(21x9)SPAZDZXRAVUPETVJEHBJT(21x12)PIYCMQYDJNXTWUWLQDMBU(13x5)QYVTFYYKTRFYJ(4x11)UHOG(5x11)YKDQT(95x5)(6x5)SESOZW(6x5)JVUMCD(53x7)(28x1)NPAWZKLFYJRJTBCBORTTCEKCLHNS(12x13)FGHPQQNJCBOH(2x9)YO(2x7)BC(308x6)(32x15)ETOWFJPXZOGWFGJARLBUUVEAFONJOSLW(150x1)(13x14)(7x15)QQXHWPZ(12x3)XXFTSKLVBLNM(2x14)XD(98x5)(10x2)IVITAAHEJC(28x4)NFTTQKTZISTINCJCUPOJRTGMIUDD(13x6)PAEWLFDAREAGA(4x6)SUDT(14x7)UOFNKCCWRMTNKZ(45x9)(9x10)(4x3)YECM(6x3)KKZJLO(13x2)VMSRHSEOJOYII(55x7)(1x4)S(8x3)TYXKBZRQ(18x3)(12x9)VHSESLORJRVL(7x9)DQDGRBE(13x5)ZIZVIPWCIQEMN(3279x13)(58x9)(16x4)AZKZJLWQNHTHGOHO(30x2)ZYSTCIOTDHPKDSMCVNKTZFNYPONYFX(202x6)(194x15)(6x1)PUSNVA(175x15)(14x10)FSZUQBSQQNHKAK(52x8)(39x2)XVEZNBPBBPMDQTHCCGYIJSROSVXTDGCWKQWPLZZ(1x11)U(83x1)(6x5)AUDVOG(7x12)OHICDSF(13x8)NOZKYWMCCDFGM(14x14)AQBYBKHLUTOUUK(13x2)BOUZNPYNVBDSP(2x6)OF(1027x1)(457x1)(151x8)(67x11)(9x7)QWWUQUGBT(16x7)IPKDWITLAMCEHCEE(13x1)DCFKDXBDNFYQF(6x10)RJOSEW(71x4)(1x1)M(5x5)WNKRF(4x7)ALBH(15x14)MKLZDQFGXSAXUFN(18x4)DJKPPRYXFQJZFOKKSS(118x1)(3x11)MTZ(43x12)(22x13)DWYLTBXHWWHFLFPYTMMVAM(9x8)GNPYYJYIV(13x15)TICBWPCYTKQAU(12x12)(6x11)NMPBRP(14x8)NYXDKVLLHESFHE(72x5)(13x10)NYANWHLDADTMX(11x2)CITDQLSHSAW(13x9)(8x5)ZCPOEXBY(3x13)FSP(2x7)OI(89x11)(42x2)(13x2)DXESJUVOVEHKV(1x5)I(3x12)LLZ(3x7)RTR(21x11)(15x5)XCOLHZFLTHCUOQP(8x7)(2x14)OS(339x5)(59x14)(16x1)(10x8)XQSHKLDBFE(8x7)JGLXFOUP(18x8)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VKBQ(34x13)EGASBNYPSJUHFMHPOQBNZNSTQKEWKXPTAG(28x11)VYPAYPUAAURHYLQIQKMLFCTRAVUA(71x7)(2x12)KP(3x6)BGT(12x7)NRADLHJTEXSA(18x7)CCBIEQMPCZRULHIGWK(7x10)CWZOLXX(53x15)(2x3)NH(5x2)JGMMC(2x3)GG(12x5)DVBMMKUAPRYW(6x2)LDZRUL(11x7)UISRTGWZGBA(1441x12)(205x5)(198x1)(112x15)(12x9)(7x9)AUFRDTR(25x2)(6x8)NFQXPE(8x13)UBIQERPU(1x14)S(50x2)(36x13)FCHZSFHMGANOGOUQVLJKOHLDWTMPFMNSRIEE(2x8)TB(12x12)TRFNONQMYBIP(52x12)(11x1)(5x10)WWKAS(28x14)(15x2)CMWTIEXKMRAPKLV(2x3)SE(134x1)(44x8)(8x5)IVGODFUS(16x13)BASOECHOINZYNNMD(2x15)FC(54x11)(29x7)(22x15)FVODZGCRBBMBYOWCIBMVSN(4x14)PJDW(3x10)YDA(5x10)BAJUZ(7x3)(1x14)N(433x15)(425x12)(94x3)(13x11)(7x14)YYITBHX(30x2)OBWPJEYZYQSWDUDLIUCZNZKAPHAQFJ(31x10)(7x5)JHTOXMH(13x5)RMLWZHDTWOUEB(107x5)(10x12)NZMVIUWXEI(15x5)(9x13)KKFXSAMBX(14x3)QWXFSSFJFDTGOT(7x3)YDOEMMV(30x13)(24x2)PXHELXXFAKACDZHBZGNBSUVU(2x11)WF(184x10)(57x7)(22x6)FSFWZBMGYAEZGMWZQTGGMU(15x2)QOTUZLMACRVFWDV(3x9)KIE(9x11)XMVQKMEPC(55x11)(1x13)G(1x14)Y(2x10)JU(27x3)PYBCBHWYJWJNMFZRIMOLKIGGQED(38x2)(11x1)QHKHBHSZMSV(1x12)P(9x3)NBULTVPAG(5x13)LTLHD(628x11)(1x10)C(589x14)(112x10)(1x2)I(22x4)RGDAVMUUEPYFVXXXYOPPNF(17x3)JRMWVCDJHYWFTDGHY(31x11)IMHJJDPKDSWOEBXGUWXYCOXKNIFDBWE(11x4)(6x1)VOJPYT(11x15)(6x8)IEFWPJ(177x4)(63x3)(26x6)FVNYFOSLLUCTIWQHUIAPLLWZBT(12x10)SRODVSMCVDND(7x4)VQMNEUI(100x12)(7x6)NYRSJAI(31x1)LZHAUWPLWJXPQPCPJNQFSTDMACSTPDR(2x13)MF(36x13)ZFFVXRNWMDPDQPSKSRXEUCAXSLOWTSBLPKJY(121x12)(67x6)(7x10)ORAJOEU(20x11)UGTSPNVTPVARWVQLCASL(14x2)TGSWVFJASSRHBL(2x6)GJ(18x15)UTXXOGUWTWGKPVAVUJ(17x6)(11x5)YHLQNVHWBHY(131x3)(9x8)GEJPUPYNK(13x13)VHELEYMCMPASV(68x15)(5x11)UIJJM(3x10)GKW(19x3)FLZJIQDVHVDUQAGCDER(3x5)AVO(9x13)RUVFUSPGU(16x3)RCSWCVDROBDUNFZT(18x4)KKGUBTFVVNXBCHMHJB(5x14)KOBGU(1330x12)(760x9)(73x7)(67x3)(12x11)AOIQYAVPWCCK(7x3)(2x1)EM(30x2)NAFGRGXWIHNGVSFBPDFPSNWBOCLZEG(246x3)(84x10)(7x6)ARXWZED(65x14)(19x7)JOANFDGLJFRIPTBODXH(10x8)QGVAUQRWRT(4x14)OWDF(8x11)WZBAOFSE(27x2)(21x4)CTNUJPAYYUDWIJRDHCGFA(93x7)(21x3)(5x11)YHJBN(5x1)FNSMH(2x7)LR(53x6)(7x5)KDGLDPD(2x7)OF(22x4)ZDUANVNZXEMGQEUDVNQMNK(1x2)R(10x6)(5x7)ADPQJ(2x3)YM(420x12)(8x11)OZRTLFOE(136x3)(5x8)RGGTC(17x5)ZIZBUMRLXLLGLSCFO(3x4)CDR(37x5)(31x4)EORZSDCKDEPKPNLNTNWZGPFARFEHWBH(46x3)(16x11)BDFBLWNLVUHFHEZS(16x14)KCEELDFXQQWPCKQC(255x14)(76x2)(8x10)ARJSJHNW(1x7)F(7x14)BSQQRIN(11x3)PRXIUVTICTB(19x12)QTCZYASWECYNXMOICBM(16x6)HWFGNOGDXKIAZVEJ(75x9)(36x3)BIIJNXOLTASONLVFEZZDHKHMTKWSTSXUAGYF(1x1)Q(21x5)XQUHREKMFMIFALWIUWGTS(30x6)(17x14)QRGDXBHIIADOCOPNV(1x2)U(28x6)(3x9)NPB(6x8)FYYNBJ(3x10)ZYV(555x13)(159x12)(8x4)(2x15)OT(16x14)BFPHRTHSHNTCWMVO(94x13)(2x5)PV(35x13)(4x4)TLEC(20x9)PXFAFUXKVAFGHMHOBFON(5x7)XNKXK(8x1)(3x8)PRZ(16x1)QPXHKCKIONIWQYRX(15x14)(2x9)KD(3x3)KXC(10x3)KISPBWLEKK(365x9)(112x4)(16x2)LAZNYMGAGIMWHSIH(42x3)ONMLAJLYDYVBHRWJXQAOCIRDZKRTNPUBFLNZNIBMVD(2x13)AH(10x15)(5x9)RHLVU(10x10)(5x4)UOURJ(76x9)(70x8)(18x8)SBLXFWEPITIEZALGDN(13x12)AMATXJMGSOCYB(5x3)OXSKV(2x12)ER(3x8)RRT(157x4)(99x14)(6x15)XMHCMB(35x4)OBBFOQFMLRHSNJBCKWQFZAPWYURPFSQVJVM(17x9)ESHQFHJAZSCGWYVGG(16x11)VFQFDDVZCTBSZOOX(38x4)NJVHVYRULGUNXXLOFBPQAOYYGECLIEVXQKVAWI(1x14)Y(1991x9)(1353x10)(474x9)(7x3)(2x6)KD(124x9)(117x5)(45x9)(10x4)PEWOKCGEWI(22x12)PRYYMTEPGIBALMTTOJFDCJ(35x4)(3x2)RGI(11x1)IKZKCSTHAWC(5x6)JKZGM(19x8)(12x10)TTSYTMTXVSQQ(323x15)(200x2)(28x6)(12x15)KJGXXFFSSLAA(3x12)EFZ(12x9)(7x8)ZLVCZNP(67x3)(5x2)ZSEIN(3x15)VRX(14x1)HMRYHPKBKDBMHS(14x12)NWRUWEPPXIUVES(1x13)P(68x12)(17x4)REXCOUFKZRHTIWQTH(12x8)WYHWEYJONJSS(20x11)PMPDVXSCLOBQRFXBPIGD(11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SMI(86x9)(45x8)(1x14)E(32x6)GRFUWVYLATDVBCPXOHKLOVHZYSGUUJYP(28x12)BJAGISXIMZOJSRLPMEUTIYJWEKMW(124x7)(67x3)(28x3)PJTZGDEUAVDQICPLUVXVTVJTUROK(2x14)LP(11x12)XFJJHQJMWZB(1x13)M(14x13)JKXYFRIDHUZRWG(12x6)KYEVJMUSSVUK(6x12)DTKDSL(242x3)(2x2)HJ(50x4)(6x5)XUIVOZ(1x14)V(4x8)APZW(16x14)HXRYJVUNTZHFWAKS(98x1)(6x14)YZWMLJ(14x11)DIDVCJTRZKYVJR(27x3)OGTHYCRWRMBKXFCVEDFQMCKCIPQ(8x13)LNFWFXYN(12x5)DUJAXBNBWNQK(69x4)(1x11)N(5x12)DROVS(26x8)LBPVCHFZIUJJTKFVDHJYDLVBPD(12x13)UEIKUJEAYAJT(7x13)MIGZAGH(171x3)(7x6)SWSAOJL(24x4)(10x6)TFADCGPRFO(2x14)MI(122x3)(26x7)HQOAUWFWSYKNZPOZZNTAGZXMLU(9x5)LGBRFFSCA(15x8)QAQOIVLDKPZKKZI(5x14)QGOZX(37x15)YPTZXTLQLGKLSZVQUTBQYTTRNKTJWSHPRNPAN(140x4)(1x4)T(25x6)(2x9)SZ(12x5)BDMOLPASNRHH(69x4)(2x13)ES(16x7)ZSNXQMXXYASQGCSK(2x5)TR(9x9)HTFMVOCVW(12x9)JGOKJDUZUSYN(9x12)MUJWHXPXN(7x14)UXRYEYI(3x2)OBG(70x1)(39x2)(8x12)NJBFXFDD(5x14)ORZCE(9x4)BRUWUPCJY(12x5)XTXXAJCPTWYL(1x14)I"
In [3]:
loop <- function(x,recu,factor){
compressed <- x
decompressed <- 0
todo <- compressed
done <- FALSE
while(!done){
g <- str_locate(todo, "\\(\\d*x\\d*\\)")
if(anyNA(g)) break
decompressed <-decompressed +(nchar(paste(str_sub(todo, end=g[1]-1), sep = ""))*factor)
todotmp <-str_sub(todo, start=g[2]+1)
algo <- str_match_all(todo, "\\d*")[[1]]
algo <- algo[!algo==""]
if(recu){
decompressed <- decompressed + loop(str_sub(todotmp, end=as.integer(algo[1])),TRUE,as.integer(algo[2])*factor)
}
else{
decompressed <- decompressed + nchar(paste(replicate(as.integer(algo[2]), str_sub(todotmp, end=as.integer(algo[1]))),collapse=""))
}
todo <- str_sub(todotmp, start=as.integer(algo[1])+1)
}
decompressed <-decompressed + (nchar(todo)*factor)
}
In [4]:
paste("Q1 - Decompression length of Algorithm 1: ", loop(input,FALSE,1),collapse="")
paste("Q2 - Decompression length of Algorithm 2: ", loop(input,TRUE,1),collapse="")