9
\$\begingroup\$

The Debian Linux distribution (and Debian-based distros, like Ubuntu, Kali and others) uses a package-manager called APT. To install program foo you would type into a terminal

sudo apt-get install foo

One little Easter Egg of APT is the following

apt-get moo

Which after typing will produce the following output

                 (__) 
                 (oo) 
           /------\/ 
          / |    ||   
         *  /\---/\ 
            ~~   ~~   
..."Have you mooed today?"...

You must write a program that produces this EXACT output in as few bytes as possible. (including trailing spaces and a new line)

Here is the same output with \n added to represent newline characters, and a * to represent trailing spaces

                 (__)*\n
                 (oo)*\n
           /------\/*\n
          / |    ||***\n
         *  /\---/\*\n
            ~~   ~~***\n
..."Have you mooed today?"...\n

As requested in the comments, here is the md5sum of the mooing.

35aa920972944a9cc26899ba50024115  -
\$\endgroup\$
  • 1
    \$\begingroup\$ I think it's APT, not aptitude; aptitude does not have Super Cow Powers \$\endgroup\$ – aditsu Sep 2 '15 at 18:24
  • \$\begingroup\$ @aditsu oh, I guess I misunderstood what aptitude is. I thought aptitude is the name of apt-get. \$\endgroup\$ – DJMcMayhem Sep 2 '15 at 18:26
  • \$\begingroup\$ For reference, could you post the output of apt-get moo|md5sum ? \$\endgroup\$ – aditsu Sep 2 '15 at 18:29
  • 25
    \$\begingroup\$ Bash, 11 bytes: apt-get moo :P \$\endgroup\$ – Dennis Sep 2 '15 at 18:57
  • 5
    \$\begingroup\$ @Dennis Doesn't work on Arch Linux ... cannot reproduce the result :P \$\endgroup\$ – Otomo Sep 2 '15 at 23:07
6
\$\begingroup\$

Bash, 95 bytes

0000000: 7a 63 61 74 3c 3c 27 27 0a 1f 8b 08 01 01 01 01 01  zcat<<''.........
0000011: 02 03 53 40 07 1a f1 f1 9a 0a 5c 98 c2 f9 f9 a8 c2  ..S@......\......
0000022: fa ba 60 10 a3 8f 2c aa af 50 03 a2 6a 40 24 42 58  ..`...,..P..j@$BX
0000033: 0b 28 11 03 54 ab 1f 83 6a 70 5d 1d 8c e0 d2 d3 d3  .(..T...jp]......
0000044: 53 f2 48 2c 4b 55 a8 cc 2f 55 c8 cd cf 4f 4d 51 28  S.H,KU../U...OMQ(
0000055: c9 4f 49 ac b4 57 02 ca 70 01                       .OI..W..p.

The above is a reversible hexdump. To create the file, execute

xxd -r -c 17 > 55918.sh

paste the hexdump and press Enter, then Ctrl + D.

To run created file, execute

bash 55918.sh 2>&-

Any other filename will do.

I chose zopfli as the compressor since it is compatible with the Coreutils program zcat and achieves better compression than gzip, bzip2 and xz.

zcat<<'' will read the following lines (until EOF) and feed them as input to zcat.

Note that zcat will print a warning (since I stripped the checksum of the compressed file), as will bash (since the HEREDOC isn't terminated by an empty line). These warnings are printed to STDERR (suppressed by 2>&-), which is allowed by default per consensus on Meta.

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

CJam, 96

This uses a lot of nasty bytes, so here's a hex dump of it:

00000000  22 ee 51 1e 53 41 15 ee  51 20 53 41 15 9a 5f 5a  |".Q.SA..Q SA.._Z|
00000010  b9 5f 41 15 8c 5f 41 f9  38 24 2a 15 7e 55 1c 5f  |._A.._A.8$*.~U._|
00000020  b9 30 5f b9 41 15 a8 26  2a 26 2a 15 36 45 91 c3  |.0_.A..&*&*.6E..|
00000030  ed cb 41 f3 df eb 41 db  20 cb c9 41 e9 df c9 c3  |..A...A. ..A....|
00000040  f3 7f 45 36 15 22 7b 69  32 6d 64 5c 5f 63 5c 37  |..E6."{i2md\_c\7|
00000050  6d 64 22 20 5f 6f 2d 7c  7e 2e 22 3d 2a 3f 7d 2f  |md" _o-|~."=*?}/|

You can run the file with the java interpreter; it may be necessary to use ISO-8859-1 encoding, such as:
java -Dfile.encoding=ISO-8859-1 …

Try it online

Equivalent (and much longer) ASCII version:

[238 81 30 83 65 21 238 81 32 83 65 21 154 95 90 185 95 65 21 140 95 65 249 56 36 42 21 126 85 28 95 185 48 95 185 65 21 168 38 42 38 42 21 54 69 145 195 237 203 65 243 223 235 65 219 32 203 201 65 233 223 201 195 243 127 69 54 21]:c
{i2md\_c\7md" _o-|~."=*?}/

Try it online

Explanation:

There are 7 characters that have repetitions: _o-|~.. Each of them can be encoded as a number n from 0 to 6. For each repeating sequence, I am encoding both the character's index (n) and the number of repetitions (k) in a single byte: 2 * (k * 7 + n), written as a character with that code. And I am encoding any single characters as 2 * c + 1, where c is the ASCII code. Everything goes in the initial string, and the rest of the program is decoding it:

{…}/      for each character in the string
  i       convert to integer (extended-ASCII code)
  2md     integer division by 2, obtaining the quotient (q) and remainder (r)
           r decides whether it's a repetition or single character
  \_      swap q and r, and duplicate q
  c\      convert q to character and move it before the other q
           this is for the r=1 case (single character)
  7md     divide q by 7, obtaining the quotient (k) and remainder (n)
  "…"=    get the corresponding character from that string (decoding n)
  *       repeat the character k times
  ?       use the single character or the repetition, depending on r

Old version (109):

" H(_2) 
 H(o2) 
 B/-6\/ 
 A/ | 4|2 3
 9* 2/\-3/\ 
 C~2 3~2 3
.6"{_'M,48>&{~*}&}/3/"Have you mooed today?"`*N

Try it online

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

Pyth, 100

r"17 (__) 
17 (oo) 
11 /6-\/ 
10 / |4 ||3 
9 *  /\\3-/\ 
12 ~~3 ~~3 
3.\"Have you mooed today?\"3."9

Try it online: Demonstration

r"string"9 run-length-decodes the string.

edit:

Here's a 97 char solution: Demonstration. Very likely this is also 97 bytes (in iso-8859-1). But too tired for writing the bytes down and doing an explanation. Tomorrow evening, I guess.

\$\endgroup\$
4
\$\begingroup\$

GolfScript (107 bytes)

This is a very simple encoding: newlines are replaced with ^, and spaces are run-length-encoded. The result contains some non-printable characters, so I present it here as xxd output:

0000000: 2711 285f 5f29 015e 1128 6f6f 2901 5e0b  '.(__).^.(oo).^.
0000010: 2f2d 2d2d 2d2d 2d5c 2f01 5e0a 2f01 7c04  /------\/.^./.|.
0000020: 7c7c 035e 092a 022f 5c2d 2d2d 2f5c 015e  ||.^.*./\---/\.^
0000030: 0c7e 7e03 7e7e 035e 2e2e 2e22 4861 7665  .~~.~~.^..."Have
0000040: 0179 6f75 016d 6f6f 6564 0174 6f64 6179  .you.mooed.today
0000050: 3f22 2e2e 2e27 7b2e 3332 3c7b 2220 222a  ?"...'{.32<{" "*
0000060: 7d2a 7d25 225e 222f 6e2a 0a              }*}%"^"/n*.

Online demo

Note that this is one character shorter than the corresponding CJam code. The tradeoff is using ' as the delimiter for the main string (saving two \s to escape the "), saving an i to convert character values to integers in the decoding loop, and getting a free trailing newline; vs having character literals to replace the single-character string literals.


Since this question was briefly tagged , I also made a version with only (108) printable characters:

'Y(__)I
Y(oo)I
S/------\/I
R/I|L||K
Q*J/\---/\I
T~~K~~K
..."HaveIyouImooedItoday?"...'{.82-.*82<{72-' '*}*}%

Instead of encoding the run-lengths of the spaces as characters ^A to ^R (and encoding ^J as ^ to avoid collisions), it leaves newlines untouched and encodes the run-lengths as I to Y.

Incidentally, my general-purpose GolfScript Kolmogorov program produces a 120-byte program.

\$\endgroup\$
1
\$\begingroup\$

Lua, 186 178 bytes

8 bytes saved thanks to a suggestion by @DJ McMayhem

p=print s=" "a=s:rep(17)b=s:rep(9)p(a.."(__) ")p(a.."(oo) ")p(b.."  /------\\/ ")p(b.." / |    ||   ")p(b.."*  /\\---/\\ ")p(b.."   ~~   ~~   ")p"...\"Have you mooed today?\"..."

Ungolfed:

p=print --Save the print function for later use
s=" " --Space character
a=s:rep(17) --string.rep(string, times) repeats the given string
b=s:rep(9)
p(a.."(__) ") --print out the lines
p(a.."(oo) ")
p(b.."  /------\\/ ")
p(b.." / |    ||   ")
p(b.."*  /\\---/\\ ")
p(b.."   ~~   ~~   ")
p"...\"Have you mooed today?\"..."
\$\endgroup\$
  • \$\begingroup\$ You could save 5 bytes by replacing line 2 with a=repeat(" ",17) \$\endgroup\$ – DJMcMayhem Sep 2 '15 at 19:15
  • \$\begingroup\$ Ah thank you :) i was trying to figure out if i could do something like that... \$\endgroup\$ – Nikolai97 Sep 2 '15 at 19:17
1
\$\begingroup\$

><>, 217 bytes

!v"                 (__) "a"                 (oo) "a"           /------\/ "a"          / |    ||   "a"         *  /\---/\ "a"            ~~   ~~   "a"..."c3*2-"Have you mooed today?"c3*2-"..."a!
 >r>l0)?v;
    ^   o<

Unfortunately this is a pretty boring answer. It starts by reading out a string that draws out the entire cow, with newlines made by adding a value of 10 to the stack (a). It then goes into a loop which just draws out the cow.

I originally made a loop to add in a set of spaces, but it was actually more expensive byte wise than just putting spaces in.

EDIT: Forgot that fish is written as "><>"

\$\endgroup\$
1
\$\begingroup\$

PowerShell, 144 bytes

$a="        "
"$a$a (__) "
"$a$a (oo) "
"$a   /------\/ "
"$a  / |    ||   "
"$a *  /\---/\ "
"$a    ~~   ~~   "
'..."Have you mooed today?"...'

The above code will work properly in environments that print Unix-style newlines (\n). It produces the correct output with, e.g., Pash on Linux.

Mathematically, for PowerShell, having 8 spaces for the $a variable is the optimal, as less means too many additional spaces between the variable and the cow to make a $b worthwhile, and more means we can't double-up on the first two lines for the head.

\$\endgroup\$
  • 4
    \$\begingroup\$ I would argue that the "newline character" is locale/platform dependent, making your output as eligible as any other. \$\endgroup\$ – sleblanc Sep 2 '15 at 22:04
  • \$\begingroup\$ 1. There's no such thing as a "newline character". \r is a carriage return, \n is a linefeed. Together, \r\n forms a newline on Windows. 2. PowerShell is not Windows only. I have tested your code with Pash (an open-source implementation of Windows PowerShell for Mono) and the output has the proper MD5 hash. 3. Because of the above, I took the liberty to unwiki your post. If you disagree with this, please re-wiki it. \$\endgroup\$ – Dennis Sep 4 '15 at 4:02
  • \$\begingroup\$ Very interesting, @Dennis ... I'm aware of the differences between \r\n and \n, but like I said, I couldn't get the MD5 correct on Windows without something egregious. Thanks for that edit, though. First I've heard of Pash, too, so thanks for that as well. I wonder how complicated that would be to build under Cygwin ... ;-) \$\endgroup\$ – AdmBorkBork Sep 4 '15 at 12:36
0
\$\begingroup\$

Molecule, 145 bytes

"   "_____:a"  (__) 
";a____"  (oo) 
";a__"  /------\\/ 
";a__" / |    ||   
";a__"*  /\\---/\\ 
";a____"~~"b"~~
...\"Have you mooed today?\"..."

My first time trying to compress ASCII art :P

\$\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.