The answer to life, the universe, and ASCII-art

25

1

Simple challenge: try to output the following text in as few bytes as you can:

       the        answer
      toli      fetheuniv
     ersea     nde     ver
    ything     the     ans
   wer tol     ife     the
  uni  ver           sean
 dev   ery         thin
gth    ean       swer
tolifetheuni    ver
seandeveryth   ing
       the     ans      wer
       tol     ifetheuniver
       sea     ndeverything

The original drawing contains 332 characters.

Rules

  • No input or an unused input.
  • Output can be in any reasonable format (string, list of strings, matrix of chars and so on).
  • You can use uppercase instead of lowercase for the drawing if your prefer so.
  • Trailing whitespaces and newlines allowed.
  • This is , so may the shortest program/function for each language win!

Notes

  • This has been identified as a possible duplicate of We're no strangers to code golf, you know the rules, and so do I. That question was about searching and replacing text. Here you have to draw a shape using a given text, and at least two of the current answers demonstrate that golfing languages can beat plain compression algorithms in this case.

Charlie

Posted 2017-07-19T06:11:51.580

Reputation: 11 448

This comes from the sandbox.

– Charlie – 2017-07-19T06:13:32.733

@Phoenix I edited the question, you can check out the clues to see that this challenge may be more about thinking and less about compressing or just making replacements. – Charlie – 2017-07-19T06:53:36.400

@cairdcoinheringaahing is more about who has the best compression algorithm in their language. Aren't many kolmogorov-complexity problems so? – officialaimm – 2017-07-19T09:15:17.250

ahh~ you finally posted it like this :) @CarlosAlejo – V. Courtois – 2017-07-19T10:05:18.197

1Personally, I think this is on-topic and not a dupe. I don't think you need a spoiler quote, though. – programmer5000 – 2017-07-19T10:15:39.120

@programmer5000 thank you very much for your support. I added the spoiler quote because I considered I needed it to defend my question after the warnings. – Charlie – 2017-07-19T10:18:04.463

1

@Phoenix I don't think this is a dupe, sogl has outgolfed bubblegum. Therefore, compression is not an optimal way of doing this.

– programmer5000 – 2017-07-19T10:34:14.503

1To be honest, I didn't realize my reopening vote was binding. For the reasons already mentioned by @programmer5000, I really don't think it's a dupe of We're no strangers.... It may be a dupe of another -- yet to identify -- challenge, but not this one. – Arnauld – 2017-07-19T12:41:29.303

@Arnauld gold [tag:code-golf] badge = mod close/reopen powers! – programmer5000 – 2017-07-19T14:53:12.630

AHHHHHHHHHHHHHH I FRIGGIN LOVE IT! BIGGEST FAN OF THAT SERIES. I READ THE BOOKS, NOT THE MOVIE. THE MOVIE RUINED IT FOR ME. – Magic Octopus Urn – 2017-07-19T23:06:05.467

@MagicOctopusUrn here is the example of what happens when a geek examples. – Christopher – 2017-07-20T01:57:43.660

This is an even better proof that 42 is the answer, than Arthur pulling out scrabble pieces. See how perfectly it fits??? – Nacht - Reinstate Monica – 2017-07-20T06:50:12.667

1@Nacht the best part is that at first I drew the 42 with * characters, and then replaced them with the text, which fit perfectly. I did not have to modify the original drawing to make the sentence fit. Coincidence? – Charlie – 2017-07-20T06:53:13.980

We need an answer in Seed https://esolangs.org/wiki/Seed

– Jerry Jeremiah – 2019-10-31T01:45:21.853

Answers

21

Python 3, 224 220 219 215 211 194 bytes

  • Thanks to @TFeld for 1 5 bytes: if(j%27<1)*j instead of if j*(j%27<1) and simplified print statement.
  • Thanks to @Leaky Nun for 4 bytes:Inverting 0 and 1, did not require the padding by zeros 7*'0'
  • @Leaky nun saved 17 bytes with his awesome golfing skills(Thanks a lot!!!!): awesome use of modular indexing
i=j=0
k=int("OHZE5WCKDTW6JYMO1JNROAAJQVAN6F8KEO0SMKJM86XIBMCEH5FXXONZGBAVCN3689DS",36)
while k:j+=1;print(k%2*'theanswertolifetheuniverseandeverything'[i%39]or' ',end='\n'*(j%27<1));i+=k%2;k//=2

Try it online!

Explanation:

Uses base-36 compression to compress this binary number(new-line excluded)

111111100011111111000000111
111111000011111100000000011
111110000011111000111110001
111100000011111000111110001
111000100011111000111110001
110001100011111111111000011
100011100011111111100001111
000111100011111110000111111
000000000000111100011111111
000000000000111000111111111
111111100011111000111111000
111111100011111000000000000
111111100011111000000000000

We basically have two counters i and j. On encountering a 1 we print a space; Else if 0 is encountered we print next letter from the string and increase i. j increases for each 0 or 1. We also print new-lines whenever necessary i.e. when j%27<1 becomes true.

officialaimm

Posted 2017-07-19T06:11:51.580

Reputation: 2 739

1You can save 1 byte by changing if j*(j%27<1): to if(j%27<1)*j: – TFeld – 2017-07-19T08:41:05.177

1

215 bytes: Try it online!

– TFeld – 2017-07-19T08:53:25.950

1you need 7*'0' because your number starts with 0. Invert 0 and 1 to solve this problem. – Leaky Nun – 2017-07-19T09:25:21.220

2205 bytes – Leaky Nun – 2017-07-19T09:52:41.443

2201 bytes with integer arithmetic – Leaky Nun – 2017-07-19T09:55:29.720

2200 bytes with modular indexing – Leaky Nun – 2017-07-19T09:56:29.600

1196 bytes – Leaky Nun – 2017-07-19T09:59:03.187

2194 bytes – Leaky Nun – 2017-07-19T09:59:35.567

8

Python 2, 235 218 213 bytes

x=bin(int('OC5POO6MZYQNBWY0RP6BKBZCOZL13MIAB6I8YZ5N7LXSZBVKX7GC57AW5631YCJ6XCLC',36))[2:].replace('1',' ')
for c in'theanswertolifetheuniverseandeverything'*4:x=x.replace('0',c,1)
while x:y,x=x[:27],x[27:];print y

Try it online!

Switched to a base 36 encoded int of the positions of letters as hinted in thew question.

Replaces each character one at a time.

       111        111111                              the        answer
      1111      111111111                            toli      fetheuniv
     11111     111     111                          ersea     nde     ver
    111111     111     111                         ything     the     ans
   111 111     111     111                        wer tol     ife     the
  111  111           1111                        uni  ver           sean
 111   111         1111             --->        dev   ery         thin
111    111       1111                          gth    ean       swer
111111111111    111                            tolifetheuni    ver
111111111111   111                             seandeveryth   ing
       111     111      111                           the     ans      wer
       111     111111111111                           tol     ifetheuniver
       111     111111111111                           sea     ndeverything

Edit: It seems officialaimm used base 36 before me.

TFeld

Posted 2017-07-19T06:11:51.580

Reputation: 19 246

7

Bubblegum, 125 bytes

0000000: 45 8f c5 01 03 31 0c 04 ff ae 62 4b 0b 99 02 c7  E....1....bK....
0000010: d8 7d 84 e7 f9 59 30 5e 41 59 4a 84 71 ef e6 3d  .}...Y0^AYJ.q..=
0000020: 4e c1 ea fd b7 42 48 91 66 d6 ae 6e da 89 d3 1c  N....BH.f..n....
0000030: ef 60 ba 97 ae 6e b6 74 2e a5 76 d9 ad ae e4 16  .`...n.t..v.....
0000040: 69 59 08 a6 a6 e8 23 d4 22 af 08 d0 20 7d 17 f0  iY....#."... }..
0000050: 8a 9b 7c 76 c2 61 7b c8 4b 01 41 23 50 24 32 87  ..|v.a{.K.A#P$2.
0000060: f5 98 9e 88 35 24 21 83 ac 50 b2 e0 a2 16 0e 42  ....5$!..P.....B
0000070: bb ba a5 bc ae 6e bd 76 b7 69 d9 f9 07           .....n.v.i...

Try it online!

Dennis

Posted 2017-07-19T06:11:51.580

Reputation: 196 637

How did you generate this? The closest I could get was 127 – musicman523 – 2017-07-19T06:23:19.747

1

With zopfli.

– Dennis – 2017-07-19T06:25:06.160

I did use zopfli, but I swear I tried with and without trailing newlines, with extra spaces....couldn't get under 127 – musicman523 – 2017-07-19T07:14:57.157

6

Python 2, 220 213 212 bytes

-1 byte by switching ()*4 for %39 from @officialaimm

s=""
w=l=i=0
for g in`int("352G7FS4XC8J2Q2M2HNK7IZI65Z9TVUMHOZ6MR3HY46RQBLWY4PR",36)`[:-1]:
	for j in g*int(g):l+=1;s+=[' ',"theanswertolifetheuniverseandeverything"[w%39]][i%2]+"\n"*(l%27<1);w+=i%2
	i+=1
print s

Try it online!

This is a different approach from the other Python answers. I use a hex base-36 (saved 7 bytes) encoding of a PNG-style RLE-style encoding of the image (a string of digits indicating the number of consecutive repeated pixels).

The string of digits is:

73869469755353565353431353533323902433339443437469034389033390735363735903735903

Then I iterate through those digits and alternately print that number of ' 's or characters from the palette ('theanswer...'). When more than 9 of a character is repeated, I'd simply add a 0 and then the remainder.

Coty Johnathan Saxman

Posted 2017-07-19T06:11:51.580

Reputation: 280

+1 for different approach. You can save a byte by using "theanswertolifetheuniverseandeverything"[w%39] TIO

– officialaimm – 2017-07-19T12:54:48.320

Thanks and noted. I was trying to work it in along with an 'or' replacement for the bracket boolean setup I have here now, but it's messing up my newlines... – Coty Johnathan Saxman – 2017-07-19T13:12:53.993

I didn't know PNG used this compression algorithm - I thought that was GIF. – wizzwizz4 – 2017-07-19T18:31:14.243

Nice catch. It wasn't PNG (nor GIF), but actually RLE. I'll add a link to the answer. – Coty Johnathan Saxman – 2017-07-20T02:22:14.310

6

05AB1E, 83 79 74 bytes

-4 bytes thanks to Erik the Outgolfer

Outputs a list of strings to save a byte.

•2ÖH₆Ôn₅Ò\ÊÑĆ¸Ý¾*£„ÔûC∞qΘœ™‚¹µ—₃₄fm•vNÈy×vyiðë¾¼’€€Ž»to‚쀀ªÜ€ƒ‰Ö’è}}}J27ô

Try it online!

Explanation

2ÖH₆Ôn₅Ò\ÊÑĆ¸Ý¾*£„ÔûC∞qΘœ™‚¹µ—₃₄fm is the base 255 representation of the decimal number:

73869469755353565353431353533323902433339443437469034389033390735363735903735903

Which encodes runs of 1s and 0s respectively, even indices being the 1s and uneven indeices the 0s. This evaluates to the binary number:

111111100011111111000000111
111111000011111100000000011
111110000011111000111110001
111100000011111000111110001
111000100011111000111110001
110001100011111111111000011
100011100011111111100001111
000111100011111110000111111
000000000000111100011111111
000000000000111000111111111
111111100011111000111111000
111111100011111000000000000
111111100011111000000000000

Code

•...•                                         Convert from base 255 to decimal
     v                                }       For each digit, do:
      NÈy×                                       is_even(index) repeated that many times
          v                          }           For each digit, do:
           yi                       }               If digit is truthy, then:
             ð                                         Push space
              ë                                     Else:
               ¾¼                                      Get and increment counter, starts at 0
                 ’€€Ž»to‚쀀ªÜ€ƒ‰Ö’                    Push "theanswertolifetheuniverseandeverything"
                                   è                   Get the character at that index
                                       J      Join whole stack
                                        27ô   Split into parts of 27

kalsowerus

Posted 2017-07-19T06:11:51.580

Reputation: 1 894

Replace "ÔAo îιË3š1ĆRÕ₃FWš{ÓÛÏ.!XµM§&¶ñD°3PŸ{óNι2Ðbмh"253ö with •—."Ôq‚Ā0Ál0j¿«ªžé¨0õ₄7“Ÿ!½ÏiæÆø-δq–Å05q½Yñá+• for -4. – Erik the Outgolfer – 2017-07-19T12:42:23.713

@EriktheOutgolfer thanks, updated my answer and now I finally know what these are for :) – kalsowerus – 2017-07-19T12:54:05.193

Nice answer :). Hope you continue to learn the language. If you have any questions feel free to chat me. – Magic Octopus Urn – 2017-07-20T00:21:05.507

@MagicOctopusUrn Thanks a lot! :) – kalsowerus – 2017-07-20T05:59:08.973

5

SOGL V0.12, 74 bytes

"ō⅓׀?@C⁶¬IΧΖO‘@øŗč"βΘ⅔Μv∙KΩqψ3╥W≡A;2ļm½±iq╗∆Δ⁶Πqīσ‽ε⁰5τΩ⅜δσΞoΤi┘‽N¹\Λ:‘'    n

Try it Here!

"...‘              push "the answer to life the universe and everything". because of a bug-not-really-bug, the starting quote is required
     @øŗ           remove spaces
        č          chop it into characters
         "...‘     push a string of spaces and ŗ where ŗ gets replaced with each next characters of the character array
              ' n  split into an array of line length 27

dzaima

Posted 2017-07-19T06:11:51.580

Reputation: 19 048

5

Allow me to answer my own question...

Charcoal, 140 126 112 bytes

A⟦⟧βF⁶⁸F⁻℅§”c#*U[“⎆Vl¶·δ‴ü"Ip8ξZ{e/⪫¦σMM⪫¢Q⁸ULê←⪫W?—υ⁻$⌀)”ι³⁴«¿﹪鲧”m⌊0Y℅¿№”XJ-⁵η}Z¿8_*<o%!±Ÿ”L⊞Oβω ¿¬﹪L⊞Oυω²⁷⸿

Try it online!

You have here a link to the closest verbose version.

Explanation (see verbose version for details):

  • The )%*(+&(+)''%'%'('%'%&%#%'%'%%%$%-&%%%%+&&%&%)&(.&%*.%%2%'%(%)%'.)%'. string (68 bytes, 48 bytes compressed) is a representation of the RLE-encoding of the drawing. Every char code minus 34 is the number of spaces (even positions) or the number of text characters (odd positions) to print consecutively.
  • The algorithm just decompress the RLE-encoded string and writes the next char of the gtheanswertolifetheuniverseandeverythin string (39 bytes, 27 bytes compressed) every time a non-whitespace character is needed to be written. As I check the length of a list to get the next character and that list starts with one element, the last character of the string is written in the first position.
  • Every 27 characters written I insert a new line.

Acknowledgments

  • Many thanks to Neil and his amazing tips for allowing me to save 28 bytes and finally be able to beat Bubblegum. :-)

Charlie

Posted 2017-07-19T06:11:51.580

Reputation: 11 448

1If you use Assign(Minus(1, c), c); then you can just use if (c) { ... } else Print(" ");. – Neil – 2017-07-19T09:27:25.723

Actually if you use for (68) and AtIndex("...", i) then you can use Modulo(i, 2) instead and you don't need c at all. – Neil – 2017-07-19T09:33:24.200

And if you use if (Not(Modulo(Length(PushOperator(u, w)), 27))) then you don't need a either. – Neil – 2017-07-19T09:35:20.863

Oh, and AtIndex does an automatic Modulo so Modulo(b, 39) can be just b. – Neil – 2017-07-19T09:36:43.947

@Neil a bunch of amazing tips indeed! Though I still don't understand the if (Not(Modulo(Length(PushOperator(u, w)), 27))) one... – Charlie – 2017-07-19T09:43:21.520

I think I have it down to 112 bytes: A⟦⟧βF⁶⁸F⁻℅§”c#*U[“⎆Vl¶·δ‴ü"Ip8ξZ{e/⪫¦σMM⪫¢Q⁸ULê←⪫W?υ⁻$⌀)”ι³⁴⁺⎇﹪鲧”m⌊0Y℅¿№XJ-⁵η}Z¿8_*<o%!±”L⊞Oβω ⎇﹪L⊞Oυω²⁷ω⸿. – Neil – 2017-07-19T09:43:34.340

1u is a predefined variable which is just an empty array (saves using A⟦⟧υ). Every time you push something to it its length increases by 1. This is shorter than an explicit assignment to increment. – Neil – 2017-07-19T09:44:43.663

@Neil do you have a TIO-link? Your 112-byte solution doesn't seem to work... – Charlie – 2017-07-19T09:53:31.380

Sorry, I think Stack Exchange adds nonprinting characters in comments to make them wrap. Try it online!

– Neil – 2017-07-19T09:59:36.320

Interestingly your "closest verbose version" isn't what I was working with, but when you remove the redundant characters it also ends up at 112 bytes. – Neil – 2017-07-19T10:11:01.560

102 bytes: Try it online!

– Neil – 2017-12-22T10:56:27.383

5

JavaScript (ES6), 207 205 203 bytes

Returns an array of strings with some trailing spaces.

let f =

_=>[16515968,33489856,k=58950624,k+16,k-40,31458204,7865230,1966983,462847,233471,117670784,k=134185856,k].map(n=>'heanswertolifetheuniverseandeverythingt '.replace(/./g,(_,i,s)=>s[n>>i&i<27?k++%39:39]))

console.log(f().join('\n'));

Arnauld

Posted 2017-07-19T06:11:51.580

Reputation: 111 334

4

Retina, 183 bytes


7386¶6469¶555353¶465353¶33135353¶23239024¶133394¶034374¶090343¶090333¶735363¶735903¶735903¶theanswertolifetheuniverseandeverything
.*$
$&$&$&$&
(\d)(.)
$1$* $2$*
+s`1([ 1¶]+)(.)
$2$1

Try it online! Explanation: The first stage adds the RLE encoding of the cell bitmap and the text, which the second stage then duplicates to the correct length, while the third stage decodes the RLE encoding. The fourth stage then moves the text into the cells.

Neil

Posted 2017-07-19T06:11:51.580

Reputation: 95 035

4

Jelly, 83 bytes

“¡eu⁾ṃṣƬİḂṃ½)ṣṾṘƇ@^AṀẆṫ+¢ṗɲ⁾ṭḋZ`⁺×Ṗj½Ṇ-Þḣ2żṿƤc’BCẋ"`“ÆZ⁺ƙ{ÆߥŀŒ1gỤ3Ḍṭṁ ṃjɓ»ṁȯ€⁶s27Y

Try it online!

How it works

“XX’BCẋ"`“YY»ṁȯ€⁶s27Y
“XX’                   a large number
    B                  binary
     C                 complement
      ẋ"`              1 becomes [1] and 0 becomes []
             ṁ         reshape
         “YY»             "theanswertolifetheuniverseandeverything"
              ȯ€⁶      replace [] with " "
                 s27   split into chunks of length 27
                    Y  join with newline

Leaky Nun

Posted 2017-07-19T06:11:51.580

Reputation: 45 011

3

Add++, 1398 bytes

+32
&
&
&
&
&
&
&
+84
&
-12
&
-3
&
-69
&
&
&
&
&
&
&
&
+65
&
+13
&
+5
&
+4
&
-18
&
+13
&
-104
&
+22
&
&
&
&
&
&
+84
&
-5
&
-3
&
-3
&
-73
&
&
&
&
&
&
+70
&
-1
&
+15
&
-12
&
-3
&
+16
&
-7
&
-5
&
+13
&
-108
&
+22
&
&
&
&
&
+69
&
+13
&
+1
&
-14
&
-4
&
-65
&
&
&
&
&
+78
&
-10
&
+1
&
-69
&
&
&
&
&
+86
&
-17
&
+13
&
-104
&
+22
&
&
&
&
+89
&
-5
&
-12
&
+1
&
+5
&
-7
&
-71
&
&
&
&
&
+84
&
-12
&
-3
&
-69
&
&
&
&
&
+65
&
+13
&
+5
&
-105
&
+22
&
&
&
+87
&
-18
&
+13
&
-82
&
+84
&
-5
&
-3
&
-76
&
&
&
&
&
+73
&
-3
&
-1
&
-69
&
&
&
&
&
+84
&
-12
&
-3
&
-91
&
+22
&
&
+85
&
-7
&
-5
&
-73
&
&
+86
&
-17
&
+13
&
-82
&
&
&
&
&
&
&
&
&
&
&
+83
&
-14
&
-4
&
+13
&
-100
&
+22
&
+68
&
+1
&
+17
&
-86
&
&
&
+69
&
+13
&
+7
&
-89
&
&
&
&
&
&
&
&
&
+84
&
-12
&
+1
&
+5
&
-100
&
+93
&
+13
&
-12
&
-72
&
&
&
&
+69
&
-4
&
+13
&
-78
&
&
&
&
&
&
&
+83
&
+4
&
-18
&
+13
&
-104
&
+106
&
-5
&
-3
&
-3
&
-3
&
-1
&
+15
&
-12
&
-3
&
+16
&
-7
&
-5
&
-73
&
&
&
&
+86
&
-17
&
+13
&
-104
&
+105
&
-14
&
-4
&
+13
&
-10
&
+1
&
+17
&
-17
&
+13
&
+7
&
-5
&
-12
&
-72
&
&
&
+73
&
+5
&
-7
&
-93
&
+22
&
&
&
&
&
&
&
+84
&
-12
&
-3
&
-69
&
&
&
&
&
+65
&
+13
&
+5
&
-83
&
&
&
&
&
&
+87
&
-18
&
+13
&
-104
&
+22
&
&
&
&
&
&
&
+84
&
-5
&
-3
&
-76
&
&
&
&
&
+73
&
-3
&
-1
&
+15
&
-12
&
-3
&
+16
&
-7
&
-5
&
+13
&
-17
&
+13
&
-104
&
+22
&
&
&
&
&
&
&
+83
&
-14
&
-4
&
-65
&
&
&
&
&
+78
&
-10
&
+1
&
+17
&
-17
&
+13
&
+7
&
-5
&
-12
&
+1
&
+5
&
-7
&
P

Try it online!

It looks like hardcoding it is the shortest way (at least in Add++)

caird coinheringaahing

Posted 2017-07-19T06:11:51.580

Reputation: 13 702

3

Vim, 239 keystrokes

:h4<CR>3hy5bZZitheanswerto<Esc>p:%s/ \|,//g<CR>ye3P
lqqi<CR><Esc>qqw3li <Esc>lq3@wbhr<CR>16l@q@w3-@w6l@ql@w9l@qll3@whr<CR>3l9@w4l@q 2@w4l@q2@w4l@q9l2@wlr<CR>9l@w4klr<CR>4whr<CR>jj
el<C-v>3k"aD0jji <Esc>qqdiwukPi <Esc>q5@qwy04j$"ap6+<C-v>GPp3kw3i <Esc>2@q4kbXj2@qywh<C-v>4jp2je<C-v>jj4A <Esc>8j5i <Esc>b<C-v>jj2I <Esc>

Linebreaks added for "readability"

Explanation

The first line yanks life, the universe and everything from a help page, which is one byte shorter than simply typing it out. It then turns that into this:

theanswertolifetheuniverseandeverythingtheanswertolifetheuniverseandeverythingtheanswertolifetheuniverseandeverythingtheanswertolifetheuniverseandeverything

The second line breaks the string up into:

the answer
toli fetheuniv
ersea nde ver
ything the ans
wer tol ife the
uni ver sean
dev ery thin
gth ean swer
tolifetheuni ver
seandeveryth ing
the ans wer
tol ifetheuniver
sea ndeverything

And then the final line indents it to make:

       the        answer
      toli      fetheuniv
     ersea     nde     ver
    ything     the     ans
   wer tol     ife     the
  uni  ver           sean
 dev   ery         thin
gth    ean       swer
tolifetheuni    ver
seandeveryth   ing
       the     ans      wer
       tol     ifetheuniver
       sea     ndeverything

BlackCap

Posted 2017-07-19T06:11:51.580

Reputation: 3 576

3

Jelly, 76 bytes

“¡¢ʋỵṆ⁻kỴ⁷ṁḤæ ƊVṛĠ¥¡¢tṢ}ȧƘ=ẒṆ_`-p1ḷṠ’ḃ⁴ĖŒṙḂ¬R“£:(ḥB⁼Ṇ#¥Ṡ1ɗĠðȮ $¿⁹½ɓ»ṁȯ€⁶s27Y

Try it online!

Dennis

Posted 2017-07-19T06:11:51.580

Reputation: 196 637

2

Retina, 185 bytes


7!8&sw'6Bi6fe!Av¶5#sea5nde5v'4y%g5!5&s¶3w#1B5ife5!¶2A2v#92se&¶1dev3#y9%¶gth4e&7sw'Bife!A4v'se&dev#yth3ing¶7!5&s6w'7B5ife!Av'7sea5ndev#y%g
'
#¶
&
an
%
thin
#
er
!
the
A
uni
B
tol
\d
$* 

Try it online!

ovs

Posted 2017-07-19T06:11:51.580

Reputation: 21 408

2

JavaScript, 215 bytes

solution based on guest44851

$=>'a21xb0k9qf30155yiv016ewp3018lkhz0ohfdb077or302cl5b0mgzr0b8hz028ghs7028gi67028gi67'.split(p=0).map(x=>parseInt(x,36).toString(2).slice(1).replace(/./g,x=>" theanswertolifetheuniverseandeverything"[+x&&1+p++%39]))

tsh

Posted 2017-07-19T06:11:51.580

Reputation: 13 072

2

Ruby, 216 bytes

o=i=1
puts"6iffnqxq0opdbco5e3f1zk5d7eezo2j6zwly9z5yykqsc1hl5svaof".to_i(36).to_s(17).chars.map{|c|
o=!o
c.to_i(17).times.map{o ? (i+=1)&&"ngtheanswertolifetheuniverseandeverythi"[i%39]:" "}.join
}.join.scan /.{1,27}/

Try it online!

Explanation Similar to the Python solutions but I used Run Length Encoding before converting to base 36. So the data string is only 54 characters instead of 68.

But it still ended up longer over all, hopefully it can be golfed further.

Simon George

Posted 2017-07-19T06:11:51.580

Reputation: 31

2

A port of my Charcoal answer:

C# (.NET Core), 229 bytes

_=>{var r="";for(int i=0,j,k=0,n=0;i<68;i++)for(j=0;j++<")%*(+&(+)''%'%'('%'%&%#%'%'%%%$%-&%%%%+&&%&%)&(.&%*.%%2%'%(%)%'.)%'."[i]-34;){r+=i%2<1?' ':"theanswertolifetheuniverseandeverything"[k++%39];if(++n%27<1)r+='\n';}return r;}

Try it online!

Charlie

Posted 2017-07-19T06:11:51.580

Reputation: 11 448

2

C (gcc), 220 219 217 213 210 bytes

-1 byte thanks to ceilingcat

-3 bytes thanks to Jerry Jeremiah

q,i,j,t;main(c){for(;c="HDIG@GEGJ@FFFDFD@EGFDFD@DDBDFDFD@CDCDLE@BDDDJE@ADEDHE@AMED@AMDD@HDFDGD@HDFM@HDFM"[t++];)for(c%=64,j=c?q=!q,c:2;--j;)putchar(c?q?32:"theanswertolifetheuniverseandeverything"[i++%39]:10);}

Try it online!

gastropner

Posted 2017-07-19T06:11:51.580

Reputation: 3 264

A function is only half a program - just use a full program for 214 bytes

– Jerry Jeremiah – 2019-10-30T21:51:23.577

@JerryJeremiah Very true; nice catch! Could shave one more byte from it too. – gastropner – 2019-10-30T21:52:38.190

1

JavaScript, 265 237 219 bytes

(i=0)=>'jwq80,13ntvk,26p62g,25g7w8,239k3c,zg4xc,7rpbk,1e9dc,b8mw,5mbc,4f9reg,4f9r0g,4f9r0g'.split`,`.map(b=>parseInt(b,36).toString(2).slice(1).replace(/./g,c=>'  theanswertolifetheuniverseandeverything'[+c||2+i++%39]))

Few bytes off thanks to @tsh.

JSFiddle

user72349

Posted 2017-07-19T06:11:51.580

Reputation:

.substr -> .slice(1) save some bytes – tsh – 2017-07-19T07:25:30.147

"Output can be in list of string" so just skip the join – tsh – 2017-07-19T07:40:08.277

@tsh. Thanks. . . – None – 2017-07-19T08:38:46.500

1

Pyth, 121 bytes

This contained too many bytes that I couldn't get to show up in TIO, so here's a hexdump:

00000000: 7558 6848 477c 2a64 6548 622c 5658 434d  uXhHG|*deHb,VXCM
00000010: 2290 8d8d 817e 7e7b 7875 7572 6663 5753  "....~~{xuurfcWS
00000020: 504d 4946 4343 3f3c 3939 3633 302d 2d2a  PMIFCC?<99630--*
00000030: 2721 211e 1b16 160d 0909 0300 225d 545d  '!!........."]T]
00000040: 3133 6a43 2202 1232 a464 b09d 7303 4244  13jC"..2.d..s.BD
00000050: 9386 74d2 e954 b89e e722 3132 2a34 2e22  ..t..T..."12*4."
00000060: 6179 1aa6 55ad c176 932b 6088 d5c5 556c  ay..U..v.+`...Ul
00000070: e4f4 5575 12a0 e7fb 1f                   ..Uu.....

Try it online!

You can add a call to wc or xxd in the bash script to see the byte length or the hexdump I produced above.

Interestingly, this program demonstrates a minor bug (?) in Pyth. Any carriage return bytes (0x0d) are read as newline bytes (0x0a) when in string literals. This forces me to add 6 bytes: X ... ]T]13 to replace the incorrect ten with a thirteen.

Otherwise the idea behind this code was fairly simple: record each position where a run of whitespace occurs. Then, pair each of those indices with the number of spaces in that run. Then, reconstruct the original string by repeating the phrase four times, then inserting in the correct locations. If the number of spaces recorded was zero, instead a newline is inserted.

FryAmTheEggman

Posted 2017-07-19T06:11:51.580

Reputation: 16 206

1

Java (OpenJDK 8), 258 252 251 bytes

z->{int i=0,x,j,N[]={16515968,33489856,x=58950624,x+16,x-40,31458204,7865230,1966983,462847,233471,117670784,x=134185856,x};for(int n:N)for(j=32;j-->0;n/=2)System.out.print(n%2<1?j<1?"\n":" ":"theanswertolifetheuniverseandeverything".charAt(i++%39));}

Try it online!

It's a rather naive implementation. First a mask, for the printed characters, then a roll over the text until done.

  • 6 bytes saved thanks to Carlos Alejo!

Olivier Grégoire

Posted 2017-07-19T06:11:51.580

Reputation: 10 647

You can save some bytes with int[]{16515968,33489856,x=58950624,x+16,x-40,31458204,7865230,1966983,462847,233471,117670784,x=134185856,x}. – Charlie – 2017-07-20T08:23:25.007

0

Javascript, approximate drawing. 319 bytes

s=32
t="theanswertolifetheuniverseandeverything"
j=0
o=""
b=document.createElement('canvas'),c=b.getContext('2d')
b.width=b.height=s
c.font="25px Verdana"
c.fillText('42',0,20)
m=c.getImageData(0,0,s,s)
i=0
while(i<m.data.length) {
 d=m.data[i+3]
 o+=d?t[j%t.length]:" "
 if(d)j++
 i+=4
}
o.match(/.{1,32}/g).join("\n")

^ for what it's worth, not much really, but before I delete the failed code.

sq2

Posted 2017-07-19T06:11:51.580

Reputation: 101