25
\$\begingroup\$

Put simply, you are to print out the following number:

0202020100110020122120012121100120121020202100012110002002010110211221012021112010200012112021220120022222102211121110110201220020202001111212210010100222100112101201122100222120201002002020200011110002211002202100022210212020112002020000120222111121112002112101000011112021202002210220022121002011021000202102101010210220022011011210102021110111212122201122021101211110121100111110122110110201011100022000212022020110211221022001201211120110221212221012220101121222011202112012221010212021120022110020022202020212022222012000012111001022021211110221211001201020202020011122222010010112222002010220111111111101010220120110010102100211000120111022212000220210121222000020212112010102012210201021022020202102102002011100211022101011202222111120100000021221101221220220200102010010021110120012202111012000100021102111102220102021100021001010020020001001222220121221122100102020000000221101220111201210200212111010211122211011210012020010012110110021221010121121202220001112220120221112001021001211112211110112212100001212200021111011200010120221010201110201121021002201221111210102010200200210112020022102110212020112111000121001021202101012000112210101112122220120012022121202101110221120012122120220120010122102110102002222120201102002111100001021001121100211122200011102122022110122000102212201111020200010222211002210021200202210102022221022222101121020102100100111221102211100102000211010012201121121220122021122102201000011221122101101111201102120001002012211020211122102002211111121222112110222212012201221111222010100101120022022111002012122112201212201011022212100010001022010102100120112001012110202210101220021102112210122210010202011211010002122111111221121222002211200201122010022021011110112111020102102001110000201111222220120011111112102212011200021210100210100010

This is a randomly generated string of zeroes, ones, and twos. It is 1777 characters long. You may be asking: what makes this challenge interesting or unique?

In normal text compression you would be able to get this down to roughly 29% of its initial size. However, if you were to use a base-4 compression - i.e. using two bits per character - you could actually get that down to 25% of its initial size. The point here is that simply compressing this file will likely not be enough to win this challenge. And, base-4 or base-8 (etc...) compression may not actually be the best solution, because no powers of 2 can be evenly divided by 3. So, you will need to get creative!

Other

-You are allowed to have a trailing newline after the output

-This challenge was inspired by this question and, while it is true that the premises are largely the same, the biggest and most important difference between the two are that this challenge in not in a friendly base (the linked question is effectively in base-4, which makes compression relatively nice).

-Other than the optional trailing newline, you must output the string/number exactly (i.e. no switching those characters for different characters), as this is

Scoring

This is . Shortest code in bytes wins! [If you wish, you can also try to solve this in as few characters as possible - but make sure you still include the byte count]

\$\endgroup\$
12
  • 5
    \$\begingroup\$ Usually I don't mind a bit of background, but here not only is it quite unrelated, it is also rather misleading - indeed, ternary computers exist. Perhaps updating it to something else could be better. \$\endgroup\$ Aug 11 '20 at 18:51
  • 5
    \$\begingroup\$ I think this challenge is actually much easier to compress well: the theoretical limit here is around 352 bytes, and current answers are very close to it (because simple base conversion works). In the COVID-19 challenge, base conversion is not efficient (because the characters occur with different probabilities, the current best answer is 7333 bytes while base conversion produces at least 7476) \$\endgroup\$ Aug 12 '20 at 2:16
  • 1
    \$\begingroup\$ how'd you randomly generate it? \$\endgroup\$
    – S.S. Anne
    Aug 12 '20 at 23:33
  • 1
    \$\begingroup\$ @S.S.Anne Try it online!. The outputted value is not currently the same as in the question \$\endgroup\$
    – Daniel H.
    Aug 12 '20 at 23:36
  • 5
    \$\begingroup\$ I like that you explain in the challenge what makes it "interesting or unique", and why it's different from other compression tasks, \$\endgroup\$
    – xnor
    Aug 13 '20 at 10:08

14 Answers 14

10
\$\begingroup\$

Charcoal, 356 bytes

”)∨➙γOZNh≕◧≧hO=↖Laκ%mNπCσm‽⌊₂α¶↷⁴L⁶→XγU<¡'²xP`E←≡¤≔`"⦃NoT3# <≔3P'I³i↨⁸~⭆ jLγD≡vU[\F3^¹wV6?ξeλ4q⊕XLHH`⪪CtFνS,{}z↗q"d⊙Mρ&⁼Zqu¤ε‹⊙S4SR*=HD|νsX⁰±s⁹d#αj⧴σZηχº«⎚⌈UKa⍘⌈DIχR>\₂Nψ ⊗w⸿◨K´*y↶/§◧?↖Q¶X&rÀv⌊↘�§G≕ⅉβ8⁰I>∨FQ¬|F↓&V⪫M⬤s›LïyWuE⸿◧H)*⎚↓'kψ‽τ⁻≦lSl∕»RιPζxqv⮌PiPγ·¿0v∕)¦≦¶=|w¬!▶¬G⭆iTwQL↘`×I↨"`T&“κh⭆&ι]⊙₂✳→V⊞¶⊖ê{✂wP#⟧⧴f➙<ε<J+→₂→f¹F´ê⪫✂ξ#!We≦qÀηl⁶²∕6m≕▷8χo;wZ3Xσ≡�+

Try it online! Link is to verbose version of code, which is just a Print statement of the original string, which the deverbosifier helpfully compresses using the best supported compression algorithm, which in this case I think is converting from base 3 to bijective base 255.

\$\endgroup\$
10
\$\begingroup\$

JavaScript (Node.js),  504 481  474 bytes

Builds a BigInt from a string encoded in base 126 and converts it to base 3.

Because the data string contains many unprintable characters, it is not shown at all below.

_=>0+Buffer(`...`).reduce((n,v)=>n*126n+BigInt(v-1),0n).toString(3)

Try it online!

The theoretical length of the string is:

$$\left\lceil\frac{\log(3^{1777})}{\log(126)}\right\rceil=404$$

Because a few characters need to be escaped, we actually need \$410\$ bytes to store it in the source.

\$\endgroup\$
6
\$\begingroup\$

05AB1E, 360 359 bytes

0•1"ôÒ^¯ùg©ÞPò–>Δª7н8l9ëŒƶuÚ*'ΛZúΩиç“À¨'Õƒ†ìà\¬Õ¯zʒbGmK_¤Rï1αÉAΛ÷₂*ƶÃ/¿ž-‘`Ž¾η¥ÓEÛ‰±þ»¡{ÒõÆΩf`ÆнÜmÙ*Ë-γèΩ²IĀSRÉ×₃"!ÒVNÑc¥à8¡{øs²†?тλ¢[)¿„œQ6ýÕl…cüÖ₄δðnøÍθds—'>oÉÙÛÄȉÓ|5&þMbǝ¥₄ü¿ö-.ã Äh›µ„玜LΩ.Ÿv¹[ïüãDÞw[š²ð,ê∊R–=¿
Ý°–Oôìʒi5ÛtWƒв²ÞΔgîγz₆/pÈv£A~y≠B₄Ý]®©₅^ïr÷Á©Ñþ‰”»«é¸₆Θ™šEΓCΘ‘
™ÕâGε¼"Äθv4¼[F+„ûW¿–ãîvîð._e!ð‘h 4DŽÕ‡ZΩĆ1·ÜY“¨â²Œ₃;öŸrÐÿRƒδ¾ñI₆Œ@Θ˜ß!™∊G¨u[d•3B«

Try it online!

Ah yes, 05AB1E. The language designed to perform well with base conversion challenges. Shamelessly compressed using this trick by Kevin

-1 thanks to @mypronounismonicareinstate

\$\endgroup\$
2
  • \$\begingroup\$ I think you can replace the в by B and omit the last character (interesting fact: I did not read the documentation of the last two characters so I don't know what exactly they do) \$\endgroup\$ Aug 12 '20 at 1:55
  • \$\begingroup\$ -1 byte by compressing the leading 0 as trailing 0 as well, and using a rotate Á, instead of prepending the 0 afterwards. \$\endgroup\$ Aug 20 '20 at 8:56
6
\$\begingroup\$

Google Sheets, 674 635 624 426

Closing parens discounted.

Column A: Padded original number up to something of length divisible by 10, then converted each 10-character chunk into a number. Then converted that into a unicode character (using UNICHAR):

Ȣ
僂
�
栩
㦱
讛
ꎫ
휾
莡
쉹
苼
䢸
⑅
㦚
紗
ᱨ
竾
횂
㙓
㤁
侏
펵
뫁
艁
ⶂ
败
覤
疒
᠃
�
惦
愮
援
媉
㿂
郸
껙
殰
犅
␱
佭
蟷
䅑
໑
ꘒ

嫌
秿

䂥
勣
굑
�
貇
뀓
�
 
൉
ᫀ
켑
♱
嚪
ꕈ
떹
葜
脄
ぎ
㪳
垈
㛠
㦸
㕏
㾈
⣏
甒
᚜
�
ઍ
ᕂ
ㄲ
聸
涠
킙
گ
ᆹ
ᄎ
쮾
῵
ࠉ
ꛏ
㖼
⃌
欎
ꬲ
橧
뛕
衠
罡
삼
刜
뿪
裀
췒
⟨
놢
焠
㲪
쁾
ꑉ
럧
ퟬ
걣
ԓ
욾
魕
娑
꠲
쥼
溚
郗
⬙
懦
䱽
汹
䵉
⤩
缶
捳
崉
�
㣿

ᗩ
뛼
믬
笠
俥
뺡
Ὡ
᭰
썴
꾋
ꉟ
쏧
珴
聼
镄
繷
쁁
�
�
�
嗍
ឭ
ዟ
錃
夶
䷙
큇
ⰲ
⻁
圻
淅
韫
㟕
ފ
眪
쾺
㟩
䚜
媤
⁽
暾
耏
೑
敎
ݥ
㳃
  • B1 - =RIGHT(JOIN(,ArrayFormula(BASE(UNICODE(FILTER(A:A,A:A>0)),3,10))),1777)
    • Convert A1 back to unicode numbers, then back to Base 3.

Supplementary Formulae

I added these because copy+paste from the code box drops some characters.

  • Padded original number (A1) with this formula:
=REPT(0,10-MOD(LEN(A1),10))&A1
  • Converted using this formula, where A2 holds the padded number.
=ArrayFormula(UNICHAR(DECIMAL(MID(A2,SEQUENCE(LEN(A2)/10,1,1,10),10),3)))
  • Byte count done for column A with this formula (=347):
=ArrayFormula(SUM(LENB(A:A)))
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Note: this is very unstable. You will have to regenerate the characters if you close out of the sheet and come back because Sheets doesn't seem to save the unrecognized ? characters properly. \$\endgroup\$ Aug 12 '20 at 16:35
5
\$\begingroup\$

brainfuck, 3178 3073 3072 2961 2955 bytes

-6 bytes thanks to Jo King

++>->>->->->>->>+>->->>->>+>>+>->->->+>>>->+>>+>+>->>+>>>>>>>>->->+>>->+>+>+>+>+>>>>>->+>->->->->>>>->->+>->>+>->>->+>->>>>+>>>->>>>>->>+>->+>+>->->>->+>+>>>->+>->->+>>>+>+>->->+>+>+>>+>>>+>+>>>>>>>+>+>>+>->->->>->>>+>>>->+>->+>->>->->>+>+>+>>->>+>+>>>+>->>>+>->->+>+>>->>->>+>+>->+>->>>+>>->>->->+>>>->+>>->->>+>->>->>->+>+>->>->->->>->->->>+>>+>+>+>->>>->>->+>+>>+>>->+>+>>>+>+>>+>>->+>->->>>>+>+>->+>+>->->+>>>->>->->>->>->+>+>+>>>>>+>+>>->+>+>>->+>>+>+>+>+>->>>+>>>+>+>+>>+>>>>>>>+>+>->->+>->>+>+>>>>+>->+>->>>+>+>>->+>->->>->->->+>>+>->>>->+>>>>>->>>->>+>+>>>+>+>>>->->->->>->+>+>->>+>+>>>+>->+>+>>->+>+>>+>>>+>>>->+>+>>->->>->>>+>->->->+>->>->->>>>+>+>->>>+>+>>>>->->>->->>+>->>->+>->>+>>>->>+>+>+>+>+>->>+>+>+>+>->+>->>->>+>+>->+>->->+>>+>->->>+>+>->->>>+>+>+>+>->>->->->+>->+>->>>>>->+>+>>+>+>->>->->->+>+>>->>>+>+>->+>+>>+>->>>>->->->+>+>+>>>>+>->->>>+>>>->->>+>->>->->->->>>>>+>->->+>->>>->+>->+>>+>+>+>+>->->+>->>->>>+>->>+>+>>->>->->+>>->+>+>->+>>+>+>>+>>->->+>>>+>+>->>>>->>+>->+>>+>>+>+>->+>>->->+>>->+>+>+>+>>+>>>>->>->>+>+>>>->->->+>>->>->>+>->+>>+>->>->->>+>>->->->>>>+>>>->+>->+>>+>->>>+>->>+>+>->->+>->+>>>->>+>->->+>->->+>->>->+>->>->>+>>>>>+>+>>->+>+>->->>+>->>+>>>->+>->>>>->+>->>->>+>+>->+>>->>->->->+>>>->>>>>+>->->->+>+>>+>>->->->->>+>>+>+>>>->>>>>+>+>>>>>+>>->->>+>->>->->+>>>>+>+>->+>>->+>+>+>>>>->->->+>+>+>->+>>+>>>+>>->>->>+>+>>+>->->>>->>>+>>->->>->->+>->+>>->->>+>>>->>>+>+>+>>>>+>->>->>>>+>>+>->->+>->>+>>->+>>>>->+>+>>->>>+>+>->->->->->->->+>->+>->>->->>+>+>>>+>+>>+>>->+>+>+>+>+>>->->>->->->+>->->+>->->>->>->->>+>->->->>>+>->+>->>->+>+>+>->>>>>+>->>>+>->->->>->->->+>>->>>>+>->+>+>>->->+>>->>>>+>->->>->->>->+>->>->->+>->+>+>->+>+>>+>+>>->>>+>+>>+>->->->->->->>->+>>>>>+>+>+>+>->+>>>->>->>+>+>->>>+>->->>>>->+>->->+>->>+>->>+>->+>->+>->+>+>->>+>->>->+>->>+>+>>->+>->>->>->+>>>+>>+>->+>->->->->+>+>+>>+>>->>+>->+>+>->->->+>>+>+>+>->>>>->+>>->->->>>+>->->>+>->>->>->->>>->+>>->+>+>->>->>->>>>>>>>>>>->+>+>->>->+>->->+>+>+>+>>>->>->->>->+>+>+>+>+>>>>->->+>->+>->+>->+>->>->+>>->->>>+>>+>+>->>>>>+>>+>->+>+>->>->->>>>+>>->->->->+>>->+>+>+>+>+>->+>>+>->+>->+>->+>+>+>->->+>->->>>+>+>->->+>>>+>->+>>+>->>->>+>+>+>>->+>>>+>->+>>>->+>+>+>>+>>>->>->+>+>+>>->>+>+>+>>+>>+>+>->>>->+>>>>+>>->+>>->->+>+>->>+>+>>>+>->>>->+>->+>+>->+>>+>->->->+>+>->->->>>>->>->+>->>>->>>+>+>>->>>>>>->->>>+>>->>>>>+>>->>>+>->+>+>>>->+>+>+>>+>>+>>>>->>>>+>->+>->>->>+>>>->>>->+>+>->->+>+>->>+>->>->>->>+>->>+>->+>->->->>+>->>>->+>->->>+>>+>+>->->+>+>->>+>+>->->+>->+>>+>->+>>>>>->->->->>->>+>>>+>->->+>>>>+>>>>>+>+>+>->+>>->->->->+>->+>->->+>>>->+>->+>>+>->>+>+>+>->->->>+>->+>+>->->>>+>+>->->->>>>>->->->+>->+>->+>->->+>->->>->+>->+>>+>+>+>->->>+>+>>>->+>>->>+>>>->->>+>+>+>->->>->>->->>+>+>>+>>>>>->->+>->+>->+>->->+>+>>->+>->>>->>>>+>>>>+>+>->>+>+>+>+>+>->->+>>->+>+>>+>->+>>>+>>->->->+>->>->+>>>>+>->+>>->>+>+>>>+>->>>->>->+>->->+>->->->>>+>>->->->>+>->+>->+>->>+>>->+>>->->>>+>>+>>->->+>>+>+>>->+>->->>>->->>->+>->+>->+>---[>-[<+>-----]<.[-]<--]

Try it online!

It first stores the number backwards then it adds 49 to the cell before printing it then goes to the cell before that and it does that until it reaches ++

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Not really sure what that extra pair of brackets is doing in the last section. It can just be [>-[<+>-----]<.[-]<--] instead \$\endgroup\$
    – Jo King
    Dec 3 '20 at 8:07
  • \$\begingroup\$ @jo-king When I was making the code at the end I had problems getting it to stop at ++, so I kept changing the code until it returned the correct results, so it's a bit messy. Thank you! \$\endgroup\$
    – RezNesX
    Dec 3 '20 at 12:49
4
\$\begingroup\$

MATL, 438 bytes

'1ye}Ju:]rrY6|H!R^ 4Fl^/z*F|`[=I"5A3nYj](eaiU/+1dxw5}MWfh-G6uV9@/jQy_)I6D@e?f+5*!4xOE^1+=\.Op`=?K8Wurme+#3F}+v*n\Hd<2e")H*JzcUR.1fg{q 3b+i(xtuj-0]hTrr@<wj?y$uj&2zstc=uDv}p|1_IM1$I)o^p*~~WE/kkG?R<QS=x{%Y5EMLCUVk%$s69A#mHm,6RjN`*tI\,{10o,0zQ_<LK+\uG2p*y\=-vQ?n*1W~`sjgmR2c>tfZ%.vWk=eL"JP{QP /)gR{Et\hjwx dUZVz%\4utDRexe=KI $tv<,P8U mDxuTgi%44;6FYN`i/|HQ&9gpLOtWu<7:[)AH:t?h"h7N#j\X;m(_(L+h!2 zVA"NzMb!`:}|9>mi>s||MrxQE/9M&6:S+.P{Z}n'T210VZa

Don't try it online! (it times out).

Here is a GIF file of the program running with the offline MATLAB compiler:

enter image description here

How it works

'1ye}Ju:]rrY6|H!R^ 4Fl^  ···  S+.P{Z}n'   % Push this very long string (not shown in
                                          % full; it contains 427 characters plus the
                                          % 2 enclosing single quotes)
T                                         % Push true. This indicates the that origin
                                          % base is the 95 printable ASCII chars
210                                       % Push number 210 
V                                         % Convert to string. This gives the
                                          % destination base, '210'
Za                                        % Base conversion. Implicitly display
\$\endgroup\$
4
\$\begingroup\$

Pyth, 361 bytes

This has too many unprintables for TIO, so here's the hexdump:

00000000: 746a 6b6a 4322 01bd bf32 7574 a357 55f7  tjkjC"...2ut.WU.
00000010: f4ca 74e0 9fbf 89f3 58ad 59c8 798b b009  ..t.....X.Y.y...
00000020: 60bc 0f8a 71f4 a90e da7b 61a6 6145 9a5b  `...q....{a.aE.[    
00000030: 2f16 8968 611f 9b8d 75fb a9f0 0308 7d38  /..ha...u.....}8
00000040: 9acd fdf3 53b1 e7be 2fa4 1ce2 6870 fcae  ....S.../...hp..
00000050: 51df 0aec 521b e506 bb84 df0b f439 2917  Q...R........9).
00000060: 7303 8ac3 0d48 489c 727c 3712 4e66 2ed6  s....HH.r|7.Nf..
00000070: ec54 c5e3 eb14 4b10 8a10 6974 683b fbcd  .T....K...ith;..
00000080: 9976 1731 c976 2d60 b2d8 c644 7641 bcd2  .v.1.v-`...DvA..
00000090: acfd b4da 6026 341f 8994 7cc8 ef94 ff58  ....`&4...|....X
000000a0: 5b47 47c8 a880 1a8e b8ae 385f 632a 306c  [GG.......8_c*0l
000000b0: 4d64 9b80 4e7e fb93 2c51 7484 0e53 2d7c  Md..N~..,Qt..S-|
000000c0: 9e46 10ac 9a6d 3d2f 0237 3fa4 9ae8 056f  .F...m=/.7?....o
000000d0: 5e2e aca5 ac4b 424c f151 d152 094f 8f57  ^....KBL.Q.R.O.W
000000e0: a644 f6ad 7032 f28c e937 3d2c a65f b434  .D..p2...7=,._.4
000000f0: 8279 4ab3 b349 ec8e 0244 44db 50e6 5426  .yJ..I...DD.P.T&
00000100: b177 d3b0 5f95 6d98 7b7f ba7e 0bac 1131  .w.._.m.{..~...1
00000110: 6f77 2710 c024 05d9 88e2 7194 fb5f 00d6  ow'..$....q.._..
00000120: 6204 d12b 5620 0020 3ab6 23ea acdd 05cf  b..+V . :.#.....
00000130: 254e ebed 0448 f957 64a7 47f8 35fb 368f  %N...H.Wd.G.5.6.
00000140: 203e f9c6 aa02 a9f4 4618 c9da 48d0 56d3   >......F...H.V.
00000150: 29ac f370 2178 6d05 e2dc 2985 aca1 8be9  )..p!xm...).....
00000160: 082c c9a6 dfcd 5e22 33                   .,....^"3

To run this, put the above hexdump in a.dump, run xxd -r a.dump > a.pyth, and then run python3 pyth.py a.pyth, using pyth.py from the Pyth repository.

Basically, the program is

tjkjC" ... "3

The long string is equivalent to the ternary string with a 1 placed in front, converted from ternary to base 256.

C converts the string from base 256 to an integer, j .. 3 to a ternary list of digits, jk to a string, and t removes the leading 1.

By sheer luck, this has no characters that need to be escaped (e.g. " and \ in certain cases), so it's shorter than it would have been otherwise. Unfortunately, Pyth's base conversion takes inputs backwards of the sensible choice, so that adds two bytes, and the required output is a string, not a list of digits, which adds another 2 bytes.

\$\endgroup\$
1
  • \$\begingroup\$ Here is a paste of a TIO link. I had tried with the native compressed string, but it required a lot of escaping, so good idea to use C instead! \$\endgroup\$ Aug 13 '20 at 15:31
3
\$\begingroup\$

Raku, 431 bytes

say 0,:127[q[ ... ].ords].base(3)

Try it online!

Uses conversion from base 127. Since TIO can't really handle carriage returns and to a lesser extent NUL bytes, I've generated and then eval'd the program in the header. I'm lucky that the generated string contained three pairs of [] so I was able to use the q[ ] quoting construct.

\$\endgroup\$
3
\$\begingroup\$

Rust, 551 566 bytes (404 405 byte code + 147 161 byte decoder)

fn main(){for x in br#"..."#.chunks(5){let mut v=x.iter().fold(0,|a,x|a*127+*x as u64-(*x>13)as u64);for _ in 0..5*x.len()-3{print!("{}",v%3);v/=3;}}}

Formatted:

fn main() {
    for x in br#"..."#.chunks(5) {
        let mut v = x
            .iter()
            .fold(0, |a, x| a * 127 + *x as u64 - (*x > 13) as u64);
        for _ in 0..5*x.len()-3 {
            print!("{}", v % 3);
            v /= 3;
        }
    }
}

Rust source code is always UTF-8. Looking at the table of encodings for UTF-8, it becomes clear that ASCII contains the most amount of information per byte (7 bits per byte), while the mult-byte encodings all are less than 6 bits per byte.

Because Rust doesn't have arbitrarily large integers, we need to fix a length of bytes we transform at once. In k bytes, we can encode $$\lfloor \log_3 (k\cdot7) \rfloor$$ trits (base 3 digits). Looking at these values without the floor, we see that we get pretty close to the optimal information density for k=5 (4.4 trits/byte vs the optimal 4.4165 trits/byte (for 7 bits per byte)). That means we will encode every 22 trits as 5 bytes.

To embed the data in our source code, we can use the raw byte string literal syntax (the br#"..."#) to get it as a &[u8] instead of a &str (byte string), and not needing to escape special characters. I stumbled into the problem that a raw CR (not part of a CRLF sequence) is not allowed in a raw byte string. So I just added 1 to every byte that was above the ASCII for CR when encoding, and subtracted it again. Fortunately we can still fit 22 trits into 5*log2(127) bits :)

Then we just need to avoid printing extra zeroes at the end, which I avoided by checking if the second byte was 7 (which only occurred in the final 5-byte-tuple).

EDIT: The first byte of the last 5-byte-tuple is zero. We can leave it out to get the same value for v, and then we can use 5*x.len()-3 to switch from printing 22 trits to 17 trits at the end, also making the decoder shorter. This also means we are at the theoretical optimum code size! (404 bytes vs 403.0055 (rounded up to 404))

Here's the encoded sequence as a hexdump:

00000000: 2439 7e78 2947 2e4b 167f 4608 6e70 135f  $9~x)G.K..F.np._
00000010: 1741 3f2d 6f1a 226b 641e 782c 1e76 752d  .A?-o."kd.x,.vu-
00000020: 0416 4650 045f 473d 3c4e 5229 731b 2961  ..FP._G=<NR)s.)a
00000030: 007f 5b6d 7a71 6a05 3139 7818 2557 747e  ..[mzqj.19x.%Wt~
00000040: 2347 032d 256a 2f4e 7658 6774 4a5a 3700  #G.-%j/NvXgtJZ7.
00000050: 4125 466b 6a2e 5f73 2845 1402 0642 3034  A%Fkj._s(E...B04
00000060: 374d 3902 6379 3f65 5111 2d3c 4453 7540  7M9.cy?eQ.-<DSu@
00000070: 683c 0629 4f00 2815 4d5a 255e 513b 3a45  h<.)O.(.MZ%^Q;:E
00000080: 1f75 3252 087d 0725 273a 3a35 297e 142d  .u2R.}.%'::5)~.-
00000090: 4461 3a3d 086a 5643 4312 2347 305e 7b44  Da:=.jVCC.#G0^{D
000000a0: 1a4a 0e64 4c00 1b6f 0766 2c53 192a 4526  .J.dL..o.f,S.*E&
000000b0: 2f0e 6d2e 3e29 2020 320f 1e59 5a2b 6324  /.m.>)  2..YZ+c$
000000c0: 2f6f 4000 051c 7503 5459 473e 554a 2040  /o@...u.TYG>UJ @
000000d0: 6034 445a 6c53 4637 0c1f 4a14 0750 5313  `4DZlSF7..J..PS.
000000e0: 6e08 3500 3615 0355 6c4f 7d64 2f25 594b  n.5.6..UlO}d/%YK
000000f0: 5666 310e 3d4d 2a54 761d 5f09 627a 3763  Vf1.=M*Tv._.bz7c
00000100: 3647 0302 2057 1904 7a2d 0003 5b06 5a05  6G.. W..z-..[.Z.
00000110: 4d4c 3a1d 7558 392a 1643 2359 3270 3e1c  ML:.uX9*.C#Y2p>.
00000120: 4315 1501 7a4a 3354 1f6a 0f29 6f19 1947  C...zJ3T.j.)o..G
00000130: 172a 6563 0634 442f 4853 3672 1014 6b49  .*ec.4D/HS6r..kI
00000140: 4319 0e12 7903 6a56 467d 5a0f 1313 4658  C...y.jVF}Z...FX
00000150: 526a 5159 362f 5614 3a53 5c6d 2c16 1343  RjQY6/V.:S\m,..C
00000160: 6058 7410 2c17 2d65 5b13 633f 2331 7440  `Xt.,.-e[.c?#1t@
00000170: 3b1c 0160 765d 1355 6950 3e65 1856 156c  ;..`v].UiP>e.V.l
00000180: 7a09 6464 2529 2161 496b 7103 583e 712f  z.dd%)!aIkq.X>q/
00000190: 070e 557f                                ..U.

Old code (without the removed null byte at the end):

fn main(){for x in br#"..."#.chunks(5){let mut v=x.iter().fold(0,|a,x|a*127+*x as u64-(*x>13)as u64);for _ in 0..(if x[1]!=7{22}else{17}){print!("{}",v%3);v/=3;}}}

Formatted:

fn main() {
    for x in br#"..."#.chunks(5) {
        let mut v = x
            .iter()
            .fold(0, |a, x| a * 127 + *x as u64 - (*x > 13) as u64);
        for _ in 0..(if x[1] != 7 { 22 } else { 17 }) {
            print!("{}", v % 3);
            v /= 3;
        }
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ Can you add a link to an online execution environment (TIO/rust playground/etc)? Also, you can save some bytes by using a closure (||{...}) instead of fn main(){...}. Finally, are the # around the string necessary? If you just wanted a &[u8], I believe you can accomplish the same thing with just b"...". \$\endgroup\$
    – TehPers
    Aug 14 '20 at 21:40
  • 1
    \$\begingroup\$ Unfortunately, I can't figure out how to enter code containing NUL characters into TIO/Rust Playground. I can't copy-paste them, as they are interpreted as string terminating nulls. The # are required because the code contains both " and `` characters. The decoder can definitely be improved though, using a closure is a good start! \$\endgroup\$
    – madlaina
    Aug 15 '20 at 17:44
2
\$\begingroup\$

R, 454 419 bytes (360-byte string + 59-byte decoder)

cat(head(rep(utf8ToInt("I¸{A´ ;ÐÄ` 3’<ˆp>ƾ]Ò‰}HµÁ‡©+\\m’'šdI°‚Y%ÊúÞ7I\\‰‹Ú(5ÆEÒ&Ì3`NhN·2žJ}¤ø¨~… 5o}F‚UR뀩濌wäo¹¥½QBi›–Ó·ÃRÿ:zW¡wÓ—ÃD“è,ýF醃0;asO„ô%Ϭà¹HÐsëÄÐGew,É׸ªAíDF*ƒ´ÅmO×[ryË*)ÿ?ÛaÁ\rñ§ŒÐS|ØñŽ< {©n£÷6êY•L¡ª}õâ#}°<ͼGÑ%ªŽqE\"&OÞ8yuM:9hø´Z›4óôêð|·ô»¶‚bÓØ儨Ôåwé°]{Ì–XrúÿlqLbªYa±|@â¨’Vªïk˜RÀØÐY‡­ þÀAŠ¹–È{?Û?¹x(vic7-ï@OÛoËI(ã†ó¬Yµ‘fMƒ¡FÐ4‡ý•†ŸÝ”ße(d")-13,e=5)%/%3^(4:0)%%3,-3),sep="")

Try it online!

(Note that copy-pasting within TIO seems to convert some single-byte utf8 characters to multi-byte versions, resulting in a higher reported byte count. See code footer for check that all characters are indeed encodable in single-byte representation. If anyone can suggest how to avoid the utf8 recoding upon copy-paste within TIO, I'd be grateful!)

How?

The general approach is to encode the base-3 string as a base-243 (=3^5) number, represented by a string of utf8 characters in the range 13-255. The compressed string therefore represents compression to log(3)/log(243) = 0.2 of the original string length. However, to type the string into a program (or, put another way, to be copy-pastable), we need to escape the '\r' (carriage-return), '"' (quote) and '\' (backslash) characters. So the final average compression for base-3 strings is 0.2 * (243+3)/243 = 0.2024691.

In the particular case of the string in this challenge, we need 356 base-243 characters plus 4 escape '\' characters = encoded string length of 360 single-byte characters.

Since R cannot natively handle arbitrarily large integers, we decode character-by-character, which is made possible by using 243 = 3^5 as the encoded number base: so every 5 base-3 digits are independently converted to a base-243 number, represented by a single-byte character. See the TIO header for the code to perform this step.
The R decoder is 59 bytes, giving a total size for this particular string of 419 bytes.

cat(                                # output...
  head(                             # all first characters of...
    rep(                            # repeats of...
      utf8ToInt("_string_")-13      # utf8 codes of _string_ minus 13...
      ,e=5)                         # x5 each...
    %/%3^(4:0)%%3,                  # converted to base-3 digits...
  -3)                               # except last 3 characters...
,sep="")                            # joining digits without spaces
\$\endgroup\$
2
\$\begingroup\$

Ruby + bases, 588 bytes

$><<?0+Bases.val('43ur6p5v87byc6oertnvopy75perajuyj6vvdx4dirisox7zjv1cn2viaoe4ta62al6phj2yiy8wqrx1yki34ihtmasmgf42gboode2gkhqu50yw3ttiblo95td8gb692jshoixb66h1mmcrfekd154h5gvo9b0p98hy6dj8oeq1nn9hihzyah1fmb9i9oqf38x8xrgabaldnxf5d1okwf7gagydqlctacv9x9r8shhnkrcj7xf34rgj3c6gb54kd8apxealduij2tecvzd31re7u1kc0ddesug9zp064abj4yrnoydre17zrfmjlpcho43146gase8zk9kkl348mopxx3qkcdepo3svrxtezb4jra4bzdjn1tytt76g74hroej9zaswy9zb0q55p3urqcbjqylcjhtxjtiadvmosf2ytxznjh3980mxkntwz4thp10ldkowsxymmhpuvbw5o0wh2t5uke1k896sjb4e07txzory0mgqj8jsrupiuvj4x19ncfyo2rspdx4u5wryx6lrlo1bncpi3').in_base(36).to_base(3)

I tried converting across multiple bases, and got the shortest string at base 36. This is a pretty simple number conversion.

Try it on repl.it!

\$\endgroup\$
0
\$\begingroup\$

Jelly, 361 bytes

“¥ḷɗ4ḄṄƥƭ&Ȯ¡ƲẓḃsÑ}G⁸ƲkẈ$ọ,Ŀ²|6ñĿṘỵHṬżṁm;=İḥɼḶɲ8Œ5Ɓ).yṙṛ7ṫʂṃ¶\Æ\gḷ¢KÞŀȮ]zƇẎẠ×ȷ÷;|Dy[¬Çe⁶Mỵ}ʋ⁵Ż;⁷ɱċlı7¦ĊĠƈỵOḄK³Ñ"}ȷɗİʠỤ,ɓÐṣẓẠẎDỊxĊċ0€⁷ɠ,wⱮȧ)u÷⁷⁵@ṬƓƑLị?`ẊạʋɠḂȧĖ>xRḢ"ls⁾Ạ"×Z⁴Ḃq^ẈƁç⁾ỴM!Ƥzẏ¹G6µ-ż0zĠ⁾Ḅ€Mɦ?ĖḞ/eẸ¹/⁼%Ġ Xẹxȷ`1ḄÄkÄ;Ṫɲ<fLW&Yɲ¡U6ẏu3ƇAɱỤḶWF°SS⁸ṪvC[`°½ḍẏ¬Äạr¿pFR0ḋ@#⁷Ʋyc\⁸ÑQÐẉⱮ#BĠƲ§×ỵMẎṾɠẆ⁹ḲlƲ5ḥÐ}ṘṄḟ|(Ẓ]¶J¿Ȥŀ;µỊ(ȤỌ⁾ÆV²ċ#ɓ¿ŀmYœʋƈḊḟ¬ŀ*ỴḂĿq⁴ḣ¹3¡r⁽Ẋø*+ƇṄỌRƘ’b3ŻṾ€

Try it online!

Mostly for completeness. Jelly is slightly worse at compressing than 05AB1E because it uses base 250 instead of 255, but on the other hand, it seems to take fewer bytes to display the number, though it's still 2 bytes longer overall.

Explanation

“...’b3ŻṾ€   Main niladic link
“...’        The integer in base 250
     b3      Convert to base 3
       Ż     Prepend a zero
        Ṿ€   Unevaluate (convert to string) each
\$\endgroup\$
0
\$\begingroup\$

Deadfish~, 3366 bytes

{{i}ddddd}ddciicddciicddciicddcicdcciccdcciicddciciccdcicddccicicdcicdccdccicicddcicicdcdciicddciicddciicdcdcccicicdccdccciicddcciicddcicdciccdciicdcciccdcdcicicddciicdcccicddcicdciicddcccicicdccicddciicdciccddcicicddcciicccccdcdciiccdcccicdcccdciccdciicddciciccddcciicddciicddciicddcciccccicdciccdcdccicdcicdcciicccdcdcciccicdcdcicicddcicciccdcdcciicccdcicddciicddcicdcciicddcciicddciicddciicddccciccccdccciiccdccdcciiccddciicdcdccciicccdcdciicdcicddciicddciccicddcciicddciicddccccicicddciicccdccccicdcccicddcciicdccicdcdcicdcccciccccicddciicdcicddciicddcciiccdcdciiccddcciiccdcicdcdcciicddciccdciicdcdccciicddciicdcdciicdcdcicdcicdciicdcdciiccddcciiccddciccdciccicdcdcicdciicddciicdcccdcicccicdcicdcicccddcicciccddciicdccdcicicdccccdcicicdccdccicccccdciciccdccdciccdciicddcicdcicccdccciiccddccciicdcicddciiccddciicddciccdciicdcciccdcdciiccddccicicddcicicdcccicddciccdciiccdcicdcicccdcdcicicccddcicdciccicdcicccddciccicddciicdccicddcicicccdcdcicdciicdcicddciicdccicddcciiccdccdcciicddcciicccddciicddciicddciicdcicddciicccccddcicicddccccicicdcccdccicdciiccddciicdcicdccccdciiccdcicdccdccicicddcicdciicddciicddciicddciicddccicccicccccddcicdccicdcicciccccddcciicddcicdciiccddci{c}dcicdcicdciiccddcicicddciccdccicdcicdciicdcdcciicdccdcccicicddcicccdciicccdcicddccciiccddciicdcdcicicdcicccddcccciicddciicdcicdccicddcicdcicdciicddciciccdcdciicddcicdciicdcdciiccddciicddciicddciicdcdciicdcdciicddcciicddcicccdcciicdccdciiccdcdcicdciccicddciiccccdccccicddcicdcccccciicdciccdccdciciccdciccddciiccddciicddccicdciicddcicdccicdcciicdcccdcicicddcciciccddciicdcccdcicicddcccicdccciicdccdciicdccccdciicccddcicdciicddciicdccdccciicdcdccicdcicdcciicddcciicddcccicdccicicccccddcicicdciccdcciccdcdccicdciicddciicddccccccciiccdccdciciccddcicccicddcicicdcdciicddcciicdcicdcccdcicdciicdcccicccdccdciccicdcdccicicddciicddccicdccicicdccdciccdcciicdciccdcdcicdcicicdccicdcicddciicccddcccicccicccddcicicddciiccdcccicddccicdciicdcdccicicdcccciccdccccdcicciccdcicdcdccccicicdciccddccciicdccccdciccicddcccicdcicicddciiccdcdcicdciicddcicccdciicddciccicdcdciicdcdcciiccddciciccdccccicdcdcicdciicddcicdciicddcciicddcciicdcdciccicddciicddcciiccdcdciicdccdciicdcicddciicddciccicdcccdcccicicdcdccicdciicdcicddciicdcdcicdcicicddcccicciccdcdcicdcicccicdciccccddcicicddccicicddciiccdcicdcicddciicdcdcicccdciiccdccicddccicicdciccdcicddciiccddcicicddccicdciciccdcdciicdccdcicdciicddcciiccccdcicddciicddciccdciicddcciicdccccdccccicdciicdcdcciccicdccdcciicdcccicccddcccicccdciicdciccddciiccdccdciciccddcccicdciiccdciccddciccccdciicddciicddcccicdciiccccdccdcciiccdcdcciicdcicddcciicddciiccdcdcicdciicddciiccccdcdciicccccdcdciccicdcdciicddcicdciicdcdccicdcciccciccdccdciiccdcccdccicdciicddccciicdccdcicdcciciccddciccicdccicdciccddciciccddciicdcciccdcdciiccddcicdccccicciccdcciccdcdciccdciccccicddciccdciicdcicddcccicdcciicddciciccdccdciicddciicdccciccdcdciicddcciiccdccccccicdcicccdccicdccdciiccccdcicddciciccddciciccdccccicccddcicdcicdccicdciccicddcciiccddciiccdcccdcciicddcicicdciccdcciccddcicicdciccddcicdciccdciicccdcicdcdcccicdcccicdciiccddcicdcicdciicdcdccicicddciccicddccicdcicicdccdciicddciiccdcdcicdciciccddcciicdccdciicdcciccdcdcicicccdcdccicdciicddciicddciccicdccdcicdccciicdciccdcccccciccdccicdcicccddcciiccdccicddcciicddcicciccddcicdcciiccddciicdcdciccccdciccicdcccdciicddcicdciicdcdciicddccicccdcccciicddciccccicccccddcicicddccicccccccicdcdciiccdcicddciccicddccciicdcicdcdcicdcciicdcdcicdcccicdc

Who cares about compression?

\$\endgroup\$
0
\$\begingroup\$

Deadfish~, 3354 bytes

oiioddoiioddoiioddoiodooioodooiioddoioioodoioddooioiodoiodoodooioioddoioiododoiioddoiioddoiiododoooioiodoodoooiioddooiioddoiodoioodoiiodooioododoioioddoiiodoooioddoiodoiioddoooioiodooioddoiiodoiooddoioioddooiiooooododoiioodoooiodooodoioodoiioddoioiooddooiioddoiioddoiioddooiooooiodoioododooiodoiodooiiooododooiooiododoioioddoiooioododooiiooodoioddoiioddoiodooiioddooiioddoiioddoiioddoooioooodoooiioodoodooiiooddoiiododoooiiooododoiiodoioddoiioddoiooioddooiioddoiioddooooioioddoiiooodooooiodoooioddooiiodooiododoiodooooiooooioddoiiodoioddoiioddooiioododoiiooddooiioodoiododooiioddoioodoiiododoooiioddoiiododoiiododoiodoiodoiiododoiiooddooiiooddoioodoiooiododoiodoiioddoiiodooodoioooiodoiodoioooddoiooiooddoiiodoodoioiodoooodoioiodoodooiooooodoioioodoodoioodoiioddoiodoiooodoooiiooddoooiiodoioddoiiooddoiioddoioodoiiodooioododoiiooddooioioddoioiodoooioddoioodoiioodoiodoiooododoioioooddoiodoiooiodoioooddoiooioddoiiodooioddoioiooododoiodoiiodoioddoiiodooioddooiioodoodooiioddooiioooddoiioddoiioddoiiodoioddoiioooooddoioioddooooioiodooodooiodoiiooddoiiodoiodoooodoiioodoiodoodooioioddoiodoiioddoiioddoiioddoiioddooioooioooooddoiodooiodoiooiooooddooiioddoiodoiiooddoi{o}doiodoiodoiiooddoioioddoioodooiodoiodoiiododooiiodoodoooioioddoiooodoiiooodoioddoooiiooddoiiododoioiodoioooddooooiioddoiiodoiodooioddoiodoiodoiioddoioioododoiioddoiodoiiododoiiooddoiioddoiioddoiiododoiiododoiioddooiioddoiooodooiiodoodoiioododoiodoiooioddoiioooodooooioddoiodooooooiiodoioodoodoioioodoiooddoiiooddoiioddooiodoiioddoiodooiodooiiodooodoioioddooioiooddoiiodooodoioioddoooiodoooiiodoodoiiodoooodoiioooddoiodoiioddoiiodoodoooiiododooiodoiodooiioddooiioddoooiodooioioooooddoioiodoioodooioododooiodoiioddoiioddoooooooiioodoodoioiooddoioooioddoioiododoiioddooiiodoiodooodoiodoiiodoooiooodoodoiooiododooioioddoiioddooiodooioiodoodoioodooiiodoioododoiodoioiodooiodoioddoiioooddoooioooioooddoioioddoiioodoooioddooiodoiiododooioiodooooioodoooodoiooioodoiododooooioiodoiooddoooiiodoooodoiooioddoooiodoioioddoiioododoiodoiioddoiooodoiioddoiooiododoiiododooiiooddoioioodooooiododoiodoiioddoiodoiioddooiioddooiiododoiooioddoiioddooiioododoiiodoodoiiodoioddoiioddoiooiodooodoooioiododooiodoiiodoioddoiiododoiodoioioddoooiooioododoiodoioooiodoiooooddoioioddooioioddoiioodoiodoioddoiiododoiooodoiioodooioddooioiodoioodoioddoiiooddoioioddooiodoioioododoiiodoodoiodoiioddooiioooodoioddoiioddoioodoiioddooiiodoooodooooiodoiiododooiooiodoodooiiodoooioooddoooiooodoiiodoiooddoiioodoodoioiooddoooiodoiioodoiooddoioooodoiioddoiioddoooiodoiioooodoodooiioododooiiodoioddooiioddoiioododoiodoiioddoiioooododoiiooooododoiooiododoiioddoiodoiiododooiodooioooioodoodoiioodooodooiodoiioddoooiiodoodoiodooioiooddoiooiodooiodoiooddoioiooddoiiodooioododoiiooddoiodooooiooioodooioododoioodoiooooioddoioodoiiodoioddoooiodooiioddoioioodoodoiioddoiiodoooioododoiioddooiioodooooooiodoiooodooiodoodoiioooodoioddoioiooddoioioodooooioooddoiodoiodooiodoiooioddooiiooddoiioodooodooiioddoioiodoioodooiooddoioiodoiooddoiodoioodoiiooodoiododoooiodoooiodoiiooddoiodoiodoiiododooioioddoiooioddooiodoioiodoodoiioddoiioododoiodoioiooddooiiodoodoiiodooioododoioiooododooiodoiioddoiioddoiooiodoodoiodoooiiodoioodooooooioodooiodoioooddooiioodooioddooiioddoiooiooddoiodooiiooddoiiododoioooodoiooiodooodoiioddoiodoiiododoiioddooiooodooooiioddoiooooioooooddoioioddooioooooooiododoiioodoioddoiooioddoooiiodoiododoiodooiiododoiodoooiodo

Try it online!

The TIO link links to an interpreter I made in Python. The interpreter that already exists in TIO crashes since the code is too long.

First time using Deadfish~

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.