22
\$\begingroup\$

Draw this Ascii coffee cup:

  o
       o
    o
 __________
/          \__
|   J      |  \
|    A     |  |
|     V    |  |
|      A   |__/
\__________/

Brownie points for coffee-script or java :)

Shortest code in bytes, function or program, trailing newline or white space is acceptable, drink up!

\$\endgroup\$
  • 37
    \$\begingroup\$ I'd be very suspicious of a cup of sparkling coffee. ;) \$\endgroup\$ – Dennis Feb 24 '17 at 14:22
  • 8
    \$\begingroup\$ @Dennis it's my special coffee for Friday mornings ;) \$\endgroup\$ – Aaron Feb 24 '17 at 14:22
  • 1
    \$\begingroup\$ Wouldn't be this more interesting with 2 or more drinks: the hot one would have vapors symbolized with “(” and “)”, the cold one sparkles? And by borrowing from Rod's comment, the code should display one or other based on current time. \$\endgroup\$ – manatwork Feb 24 '17 at 14:31
  • 1
    \$\begingroup\$ Would it be acceptable to have trailing white space on lines? \$\endgroup\$ – Jonathan Allan Feb 24 '17 at 14:38
  • 2
    \$\begingroup\$ @Aaron the cup don't have a good pattern, hard-coding/compressing will be shorter in many languages \$\endgroup\$ – Rod Feb 24 '17 at 14:55

24 Answers 24

3
\$\begingroup\$

SOGL, 48 bytes

mγmλ⁶…Jcēņ▒&↓¡℮štΥ{ιE‽▼⅛÷εγ╝Ξ∫$■⌡πθ&χF׀▼ΡQ7L↓F¶‘

Explanation:

SOGL has built-in string compression and one of the things it has is a char dictionary compression. Even better, it has a boxstring compression type where the only chars available are " /\|_-\n". So the whole program is a string encased in "‘ (the " is implicit).

The string I gave the compressor are (escaped):

"  o\n       o\n    o\n ",
"__________",
"\n/          \\__\n|   ",
"J",
"      |  \\\n|    ",
"A",
"     |  |\n|     ",
"V",
"    |  |\n|      ",
"A",
"   |__/\n\\",
"__________",
"/"
\$\endgroup\$
16
\$\begingroup\$

JavaScript (ES6), 110 104 bytes

Saved 4 bytes thanks to edc65

let f =

_=>`1o
6o
3o
 9
/44\\__
|2J5|1\\
|3A4|1|
|4V3|1|
|5A2|__/
\\9/`.replace(/\d/g,n=>' _'[n>>3].repeat(++n))

console.log(f())

How it works

The compression of the original ASCII art is achieved by replacing all sequences of 2 to 10 consecutive spaces and the two sequences of 10 consecutive underscores with a single digit:

  • Each sequence of N consecutive spaces is encoded with the digit N-1.
  • The underscore sequences are encoded with a 9.

We use N-1 rather than N so that we never have to use more than one digit. Hence the need for ++n when decoding.

The expression n>>3 (bitwise shift to the right) equals 0 for n = 1 to n = 7 and equals 1 for n = 8 (not used) and n = 9. Therefore, ' _'[n>>3] gives an underscore for 9, and a space for all other encountered values.

The only special case is the sequence of 10 consecutive spaces just above "JAVA". Encoding it with a 9 would conflict with the underscore sequences. So we need to split it into two sequences of 5 spaces, encoded as 44.

\$\endgroup\$
  • \$\begingroup\$ I count 108 bytes (not counting f=). You can save 4 bytes this way: n>>3 instead of +!(n&7), 9 instead of _8 (twice) and 44 instead of 9 \$\endgroup\$ – edc65 Feb 24 '17 at 15:19
  • \$\begingroup\$ @edc65 I've no idea why I counted f= in that one... Thanks for the saved bytes! \$\endgroup\$ – Arnauld Feb 24 '17 at 15:28
  • \$\begingroup\$ Can you explain how the regex works a little bit? It appears like it replaced a digit d, with d spaces ('4' becomes ' '). But not sure exactly how it does that. What does the bit shift do? Why are we incrementing n? \$\endgroup\$ – Cruncher Feb 24 '17 at 16:33
  • 1
    \$\begingroup\$ @Cruncher I've added a 'How it works' section. \$\endgroup\$ – Arnauld Feb 24 '17 at 17:22
  • \$\begingroup\$ @Arnauld Very clever :) \$\endgroup\$ – Cruncher Feb 24 '17 at 17:43
16
\$\begingroup\$

Jelly, 67 64 bytes

-2 bytes thanks to Dennis (1. remove redundant , and 2. replace transpose and run-length decode, ZŒṙ, with reduce by element repetition, x/.)

“Ñṁ{xGgṭḷVỤɲ8ṿfƬT9Ɱ¹=qṀS“$<(ƇỤ08ØÑḌṃṘX6~cuc8HṗḞ2’Dx/ị“ ¶_/\|JAVo

Try it online!

How?

“...“...’ is a list of two base-250 compressed numbers:

[1021021021332411532617161526181616261916162618163425334, 2117114111551155121131612111415121115141211161312111551]

D converts to decimal to yield two lists of digits:

[[1, 0, 2, 1, 0, 2, 1, 0, 2, 1, 3, 3, 2, 4, 1, 1, 5, 3, 2, 6, 1, 7, 1, 6, 1, 5, 2, 6, 1, 8, 1, 6, 1, 6, 2, 6, 1, 9, 1, 6, 1, 6, 2, 6, 1, 8, 1, 6, 3, 4, 2, 5, 3, 3, 4], [2, 1, 1, 7, 1, 1, 4, 1, 1, 1, 5, 5, 1, 1, 5, 5, 1, 2, 1, 1, 3, 1, 6, 1, 2, 1, 1, 1, 4, 1, 5, 1, 2, 1, 1, 1, 5, 1, 4, 1, 2, 1, 1, 1, 6, 1, 3, 1, 2, 1, 1, 1, 5, 5, 1]]

x/ reduces by element repetition to give one list of digits (repeating the number from the first list by the corresponding value of the other):

[1, 1, 0, 2, 1, 1, 1, 1, 1, 1, 1, 0, 2, 1, 1, 1, 1, 0, 2, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 3, 3, 2, 6, 1, 1, 1, 7, 1, 1, 1, 1, 1, 1, 6, 1, 1, 5, 2, 6, 1, 1, 1, 1, 8, 1, 1, 1, 1, 1, 6, 1, 1, 6, 2, 6, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 6, 1, 1, 6, 2, 6, 1, 1, 1, 1, 1, 1, 8, 1, 1, 1, 6, 3, 3, 4, 2, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4]

instructs to index into the list of the right, one based and modularly (0 indexes into the rightmost item). The list on the right, ¶_/\|JAVo, is simply the character used in the required order where the pilcrow, , is the same code-point as a linefeed. The closing partner of is not required as this is the end of the program:

[' ', ' ', 'o', '\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'o', '\n', ' ', ' ', ' ', ' ', 'o', '\n', ' ', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '\n', '/', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\', '_', '_', '\n', '|', ' ', ' ', ' ', 'J', ' ', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', '\\', '\n', '|', ' ', ' ', ' ', ' ', 'A', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', '|', '\n', '|', ' ', ' ', ' ', ' ', ' ', 'V', ' ', ' ', ' ', ' ', '|', ' ', ' ', '|', '\n', '|', ' ', ' ', ' ', ' ', ' ', ' ', 'A', ' ', ' ', ' ', '|', '_', '_', '/', '\n', '\\', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '/']

Jelly performs an implicit print of this list, which, since it contains characters, prints as if it were a string:

  o
       o
    o
 __________
/          \__
|   J      |  \
|    A     |  |
|     V    |  |
|      A   |__/
\__________/
\$\endgroup\$
  • 7
    \$\begingroup\$ I swear some of these languages are straight up compression algorithms \$\endgroup\$ – Cruncher Feb 24 '17 at 16:26
  • 6
    \$\begingroup\$ @Cruncher that would be Bubblegum \$\endgroup\$ – Jonathan Allan Feb 24 '17 at 16:32
  • 4
    \$\begingroup\$ Of course, any language that can output text longer than the code, must necessarily have code longer than the output text for some output texts. I assume if you tried to write something for a completely randomized input the code for it(unless you got lucky) would be longer? \$\endgroup\$ – Cruncher Feb 24 '17 at 16:38
  • \$\begingroup\$ Yep if random. Bubblegum is actually using compression, the goal being Kolmogorov complexity challenges and hence the input should have pattern (or at least repetition like here). \$\endgroup\$ – Jonathan Allan Feb 24 '17 at 16:51
  • \$\begingroup\$ The final is implicit and you can replace ZŒṙ with x/. Also, while it doesn't have any bytes, using instead of a literal newline makes the code more redable imo. \$\endgroup\$ – Dennis Feb 26 '17 at 13:43
9
\$\begingroup\$

CoffeeScript ES6, 214 180 bytes

r="replace";" 1o0n0 6o0n0 3o0n0 _9n0/0 9b0_1n0|0 2J0 5|0 1b0n0|0 3A 4|0 1|0n0|0 4V0 3|0 1|0n0|0 5A0 2|0_1/0n0b0_9/0"[r](/\d/g,(a,b,c)->c[b-1].repeat(a))[r](/n/g,"\n")[r](/b/g,"\\")

CoffeeScript, 135 bytes with hardcoding

f=()->"""  o
       o
    o
 __________
/          \__
|   J      |  \\
|    A     |  |
|     V    |  |
|      A   |__/
\__________/"""
\$\endgroup\$
  • 8
    \$\begingroup\$ No up/down vote; I don't like this answer because generally the point in a kolmogorov-complexity answer is to generate the output without using the entire thing in the code. \$\endgroup\$ – HyperNeutrino Feb 24 '17 at 14:37
  • \$\begingroup\$ @HyperNeutrino, I agree, working on improving it. \$\endgroup\$ – Tom Feb 24 '17 at 14:39
7
\$\begingroup\$

Python 2, 174 172 171 167 bytes

No hard-coding.
No Base-64 encoding.
No Regex.

k=' '
q='_'*10
print'\n'.join([k*i+'o'for i in 2,7,4]+[k+q]+['/'+k*10+'\\__']+['|'+k*s+'JAVA'[s-3]+k*(9-s)+'|'+' _'[s==6]*2+'\\||/'[s-3]for s in 3,4,5,6]+['\\'+q+'/'])

Saved 2 bytes by externalizing '_'*10 and by exploiting Python's conversion of True -> 1 and False -> 0.
Saved 1 byte by removing unnecessary whitespace.
Saved 4 bytes thanks to @TuukkaX!

\$\endgroup\$
  • \$\begingroup\$ You seem to have 2 useless whitespaces at ] for and in [. \$\endgroup\$ – Yytsi Feb 25 '17 at 7:07
  • \$\begingroup\$ Actually, you can shorten [2,7,4] and [3,4,5,6] to 2,4,7 and 3,4,5,6. \$\endgroup\$ – Yytsi Feb 25 '17 at 7:09
7
\$\begingroup\$

PowerShell, 136 124 123 105 bytes

"""2o
7o
4o
 $(($a='_'*10))
/55\__
|3J6|2\
|4A5|2|
|5V4|2|
|6A3|__/
\$a/"""-replace'(\d)','$(" "*$1)'|iex

Try it online!

Thanks to @briantist for finding the shorter -replace method that I knew was there somewhere.

This takes the string with numbers in place of the requisite number of spaces. We then regex -replace the digits with a script expression $(" "*$1). So, for example, the first line of the string will be $(" "*2)o, the second will be $(" "*7)o and so on. Because of the triple-quoting, this is left as a string on the pipeline. We dump that to iex (short for Invoke-Expression and similar to eval), which processes the script expressions and leaves the resulting multi-line string on the pipeline. Output is implicit.

\$\endgroup\$
  • \$\begingroup\$ That's strange, hardcoding is shorter. Hm. +1 anyway :) \$\endgroup\$ – HyperNeutrino Feb 24 '17 at 14:47
  • \$\begingroup\$ I was hoping for some answers using innovative (huffman) coding schemas, but my python implementation is still coming up longer as well.. \$\endgroup\$ – Aaron Feb 24 '17 at 14:54
  • \$\begingroup\$ for some reason the short-hand if/else doesn't seem to work ($_,' '*$_)[+$_-in48..57] - no matter what I change it seems to fail for me. \$\endgroup\$ – colsw Feb 24 '17 at 17:43
  • \$\begingroup\$ @ConnorLSW That's because both expressions are evaluated and the array built before the indexing happens. As a result, PowerShell doesn't know how to multiply space by o and barfs. \$\endgroup\$ – AdmBorkBork Feb 24 '17 at 17:54
  • 1
    \$\begingroup\$ @briantist Thanks for finding that! I knew it was there, just couldn't come up with the right combination of quotes to get it to work. \$\endgroup\$ – AdmBorkBork Feb 27 '17 at 13:47
4
\$\begingroup\$

GNU sed, 113 112 bytes

s:$:  o@SS o@S o@ UU@/SSS \\__@|SJSS|  \\@|S AS  |  |@|S  VS |  |@|SSAS|__/@\\UU/:
s:S:   :g
y:@:\n:
s:U:_____:g

Basic encoding, it stores 3 spaces as S, \n as @ and 5 underlines as U. I'll keep trying combinations to find something shorter.

Try it online!

The trivial solution of printing the string directly is given below. It has 136 bytes, resulting in a compression of 18 %, using the encoding scheme above.

c\  o\
       o\
    o\
 __________\
/          \\__\
|   J      |  \\\
|    A     |  |\
|     V    |  |\
|      A   |__/\
\\__________/

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Encoding ss as S saves 1 byte. \$\endgroup\$ – Riley Feb 24 '17 at 16:19
  • \$\begingroup\$ @Riley Thanks. I also just found a 1 byte less solution, with S storing 3 spaces, no s. I think I'll edit this one instead, because it keeps the same number of transformations. \$\endgroup\$ – seshoumara Feb 24 '17 at 16:26
4
\$\begingroup\$

MATL, 87 86 83 82 78 bytes

[TIH][IAC]111Z?c'(ty!(OWM4J4gW{lm> >bw8ch|.FU2W"@\#2Dj!NQDeIMZ'F'_ /|\JAV'Za7e

This solution breaks the coffee into two pieces: the "bubbles" and the mug. To create the bubbles, we create a sparse matrix with 111 located at three locations and convert it to a character array

[TIH][IAC]111Z?c

For the mug component, we rely upon string compression

'(ty!(OWM4J4gW{lm> >bw8ch|.FU2W"@\#2Dj!NQDeIMZ'F'_ /|\JAV'Za7e

Both components are printed to the output and a newline is automatically placed between the components

Try it at MATL Online

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

Python 2, 128 127 bytes

-1 byte thanks to Rod (use multiplication of tuple ('_'*10,) to avoid a declaration).

print''.join('0'<c<':'and' '*int(c)or c for c in'''2o
7o
4o
 %s
/ 9\__
|3J6|2\\
|4A5|2|
|5V4|2|
|6A3|__/
\%s/'''%(('_'*10,)*2))

Try it online!

Note: that double backslash is needed before the line feed.

Everything between the ''' and ''' is a single string, the two %s are formatters which get replaced by the content of the trailing %(...) tuple, which in turn contains two copies of '_'*10 via the tuple multiplication (...)*2. The '_'*10 performs string multiplication to yield '__________'.

The code traverses the characters, c, of that whole string using for c in '''... and creates a new string by joining (join(...))
either the number of spaces identified by c, int(c), if c is a digit
or c itself
- being a digit is identified by '0'<c<':' to save over c.isdigit().

\$\endgroup\$
  • \$\begingroup\$ You can replace u,u with ('_'*10,)*2 and drop the u declaration \$\endgroup\$ – Rod Feb 24 '17 at 16:23
  • \$\begingroup\$ Oh, nice I did look at that and think there was a way - thanks @Rod! \$\endgroup\$ – Jonathan Allan Feb 24 '17 at 16:53
4
\$\begingroup\$

Java 8, 294 289 248 bytes

Golfed:

()->{String s="";for(char c:"\u026F\n\u076F\n\u046F\n __________\n/\u0A5C__\n|\u034A\u067C\u025C\n|\u0441\u057C\u027C\n|\u0556\u047C\u027C\n|\u0641\u037C__/\n\\__________/".toCharArray()){for(int i=0;i<c>>8;++i)s+=' ';s+=(char)(c&255);}return s;}

In the spirit of , this does not hard-code the string to output. Instead, it makes use of the fact that there are many cases of multiple spaces followed by a printable character. It encodes the number of spaces that precede a character in the high-order byte of the character, with the actual ASCII character in the low-order byte.

Ungolfed:

import java.util.function.*;

public class DrinkYourMorningCoffee {

  public static void main(String[] args) {
    System.out.println(f(
    () -> {
      String s = "";
      for (char c : "\u026F\n\u076F\n\u046F\n __________\n/\u0A5C__\n|\u034A\u067C\u025C\n|\u0441\u057C\u027C\n|\u0556\u047C\u027C\n|\u0641\u037C__/\n\\__________/".toCharArray()) {
        for (int i = 0; i < c >> 8; ++i) {
          s += ' ';
        }
        s += (char) (c & 255);
      }
      return s;
    }
    ));
  }

  private static String f(Supplier<String> s) {
    return s.get();
  }
}
\$\endgroup\$
  • \$\begingroup\$ I think it would be better to encode the number of leading spaces before a character in the high byte. So, an 'A' preceded by six spaces would be encoded as \u0641. \$\endgroup\$ – David Conrad Feb 26 '17 at 18:03
  • \$\begingroup\$ @DavidConrad why not do both? There are no more than ten consecutive repetitions anywhere in the string, and decimal ten fits in hex F. It should be possible to fit both in there. \$\endgroup\$ – user18932 Feb 26 '17 at 18:06
  • \$\begingroup\$ That's a good point. \$\endgroup\$ – David Conrad Feb 26 '17 at 18:10
  • 1
    \$\begingroup\$ @DavidConrad it ended up making the file size bigger due to the second loop I had to add. But I did save a few bytes by converting hex to decimal constants. Losing the 0x prefix helped. \$\endgroup\$ – user18932 Feb 26 '17 at 18:57
  • 1
    \$\begingroup\$ There are two encodings that look useful: number of spaces, and number of repetitions. You were correct: encoding the number of spaces is a net gain. I was also able to golf some of the other code (if is redundant, for example) and shave off around 1/6th of the size. \$\endgroup\$ – user18932 Feb 26 '17 at 19:16
2
\$\begingroup\$

Befunge, 158 105 101 bytes

<v"XaXXXNYXNY77777'XXXXX2_TXQXX0XZTXDXX0X^TXXRX0X^TXXDX07]27777#"p29+55
:<_@#:,g2/+55,g2%+55
\JV/|_Ao

Try it online!

The characters in the string are first encoded as indices into a lookup table of the ten possible values. The indices are then grouped into pairs, each pair being combined into a single number (i1 + i2*10) in the range 0 to 99. By carefully choosing the order of the lookup table, we can guarantee that those values will always be valid ASCII characters which can be represented in a string literal.

This is a breakdown of the code itself:

Source code with execution paths highlighted

* We start by initialising the last element of the lookup table with a newline character (ASCII 10).
* We then use a string literal to push the encoded content onto the stack.
* Finally we loop over the values of the stack, decoding and outputting two characters at a time.
* The last line hold the lookup table: the 9th element is an implied space, and the 10th (newline) is set manually, as explained earlier.

\$\endgroup\$
2
\$\begingroup\$

Retina, 71 bytes

Differently from my other answer, this one was written by hand.


2o¶6o¶3o¶1=¶/55\__¶|3J6|2\¶|4A5|2|¶|5V4|2|¶|6A3|__/¶\=/
=
10$*_
\d
$* 

(there's a trailing space at the end)

Try it online!

The principle is still having a "compressed" string from which the cup of coffee can be reconstructed by substitutions. Trying different substitutions it turned out that the only ones worth doing are:

  • = turns into __________ (10 underscores)
  • any digit turns into that number of spaces
\$\endgroup\$
2
\$\begingroup\$

Common Lisp, 125 123 122 120 114 bytes

(format t"~3@{~vto
~} ~10@{_~}
/~11t\\__
|   J~11t|  \\
~2@{|~5t~a~11t|  |
~}|~7tA   |__/
\\~10{_~}/"2 7 4'A" V"1)

I saved 6 bytes, using idea of just putting enters in string instead of ~&s.

Ideas for improvement welcomed.

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

Python3, 206 bytes

print('  o\n'+7*' '+'o\n'+4*' '+'o\n'+' '+10*'_'+'\n'+'/'+10*' '+'\__\n'+'|'+3*' '+'J'+6*' '+'|  \\\n'+'|'+4*' '+'A'+5*' '+'|  |\n'+'|'+5*' '+'V'+4*' '+'|  |\n'+'|'+6*' '+'A'+3*' '+'|__/\n'+'\\'+10*'_'+'/') 
\$\endgroup\$
  • 2
    \$\begingroup\$ So many space characters… Better declare a s=' ' variable and use it. \$\endgroup\$ – manatwork Feb 24 '17 at 14:36
  • \$\begingroup\$ Also wouldn't hurt to predefine newline \$\endgroup\$ – Sriotchilism O'Zaic Feb 24 '17 at 14:37
  • 3
    \$\begingroup\$ Hardcoding the output is shorter \$\endgroup\$ – Cows quack Feb 24 '17 at 14:41
  • \$\begingroup\$ @WheatWizard, I don't think so. There is only a single solitary newline. The others are inside strings, so using a variable would also need a concatenation operator. And 'o\n' has the same length as 'o'+n. \$\endgroup\$ – manatwork Feb 24 '17 at 15:50
  • 2
    \$\begingroup\$ @manatwork One could: print(*(' o',7*' '+'o',4*' '+'o',' '+10*'_','/'+10*' '+'\__','|'+3*' '+'J'+6*' '+'| \\','|'+4*' '+'A'+5*' '+'| |','|'+5*' '+'V'+4*' '+'| |','|'+6*' '+'A'+3*' '+'|__/','\\'+10*'_'+'/'),sep='\n') or for x in(' o',7*' '+'o',4*' '+'o',' '+10*'_','/'+10*' '+'\__','|'+3*' '+'J'+6*' '+'| \\','|'+4*' '+'A'+5*' '+'| |','|'+5*' '+'V'+4*' '+'| |','|'+6*' '+'A'+3*' '+'|__/','\\'+10*'_'+'/'):print(x), both are 197. Still longer than a 136 hard code. \$\endgroup\$ – Jonathan Allan Feb 24 '17 at 16:02
1
\$\begingroup\$

Pyth, 80 bytes

r"  o
7 o
4 o
 10_
/10 \__
|3 J6 |  \\
|4 A5 |  |
|5 V4 |  |
|6 A3 |__/
\\10_/"9

Online interpreter available here.

Simple run-length decoding.

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

C - 179

Solution with extensive use of format string:

void f(){printf("%1$3c\n%1$8c\n%1$5c\n%2$11s\n/%3$13s\n|%4$4c%5$7c%6$3c\n|%7$5c%5$6c%5$3c\n|%8$6c%5$5c%5$3c\n|%7$7c%5$4c__/\n\\%2$s/\n",'o',"__________","\\__",74,'|',92,65,86);}

Here is a more readable version:

void f() {
  printf("%1$3c\n"
         "%1$8c\n"
         "%1$5c\n"
         "%2$11s\n"
         "/%3$13s\n"
         "|%4$4c%5$7c%6$3c\n"
         "|%7$5c%5$6c%5$3c\n"
         "|%8$6c%5$5c%5$3c\n"
         "|%7$7c%5$4c__/\n"
         "\\%2$s/\n"
         'o',"__________","\\__",'J','|','\','A','V');
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Brute forcing the art inside code give a shorter version and print with puts: void g(){puts(" o\n o\n o\n __________\n/ \\__\n| J | \\\n| A | |\n| V | |\n| A |__/\n\__________/\n");} \$\endgroup\$ – Churam Feb 24 '17 at 17:21
1
\$\begingroup\$

Retina, 99 bytes

This solution was generated automatically using this script.


0 0o¶ 1¶/32\__¶4 J24\¶|3A 34|¶| 3V34|¶|2A   |__/¶\1/
4
|  
3
    
2
      
1
__________
0
  o¶    

(there are trailing spaces on many lines)

This works by using numbers 1,2,3,4 in place of some character sequences that are repeated in the target string and then substituting them back.

I know it could be golfed more by tweaking this code or completely changing approach, but since the kolmogorov meta-golf challenge had quite a disappointing outcome I wanted to try using my script on a real challenge.

Try it online!

\$\endgroup\$
  • \$\begingroup\$ You can replace all the spaces at the end of the last line to a 3 and then move the substitution up to before the 3. Also you can change 2\n to 2\n3 and move this substitution to before the 3. Try it online! \$\endgroup\$ – Cows quack Feb 26 '17 at 10:29
  • \$\begingroup\$ You can also change 1\n__________ to 1\n_____ and then change each 1 in the main substitution to 11 Try it online! \$\endgroup\$ – Cows quack Feb 26 '17 at 10:32
  • \$\begingroup\$ @KritixiLithos as I said, I know this can be golfed :) I just wanted to post a solution created directly by my algorithm, maybe I'll post another answer which is optimized manually^^ \$\endgroup\$ – Leo Feb 26 '17 at 10:33
0
\$\begingroup\$

Python 3.6

(non-competing)

Here's my attempt at Huffman encoding. It's definitely golfable further if anyone wants to take up the idea.

from bitarray import bitarray as b
a=b()
a.frombytes(bytes.fromhex('ca7fca7e53b6db6db664ffc6d9ae1fd6335e2fad1af83d68d7e2e9b218db6db6db20'))
print(''.join(a.decode({k:b(v)for k,v in zip(" _|\no/\\AJV","1 011 010 0011 00101 00100 00011 00010 00001 00000".split())})))

The literal could be compressed further still by converting to base64 or other, and the Huffman tree could be optimized to yield a shorter bitarray still.

\$\endgroup\$
  • 3
    \$\begingroup\$ Non-competing is not an excuse for invalidity. \$\endgroup\$ – Mego Feb 24 '17 at 16:23
  • \$\begingroup\$ @Mego I don't have the time rn to fix it, I just wanted to give the framework of a solution for someone else to run with. non-competitive because I was the OP of the challenge \$\endgroup\$ – Aaron Feb 24 '17 at 16:26
  • 2
    \$\begingroup\$ That really doesn't matter. Our policy is clear. \$\endgroup\$ – Mego Feb 24 '17 at 16:27
  • \$\begingroup\$ @Mego fixed... just for you \$\endgroup\$ – Aaron Feb 24 '17 at 16:44
0
\$\begingroup\$

GameMaker Language, 138 bytes

show_message("  o#       o#    o# __________#/          \__#|   J      |  \#|    A     |  |#|     V    |  |#|      A   |__/#\__________/")
\$\endgroup\$
0
\$\begingroup\$

C, 141 Bytes

f(){printf("  o\n%7co\n    o\n __________\n/%11c__\n|   J%6c|  \\\n|    A     |  |\n|%6c    |  |\n|%7c   |__/\n\\__________/",0,92,0,86,65);}

Usage

main(){f();}

Easy Solution, 148 Bytes:

w(){puts("  o\n       o\n    o\n __________\n/          \\__\n|   J      |  \\\n|    A     |  |\n|     V    |  |\n|      A   |__/\n\\__________/");}
\$\endgroup\$
0
\$\begingroup\$

PHP, 116 bytes

for(;$c="1o
6o
3o
 9
/44\\__
|2J5|1\\
|3A4|1|
|4V3|1|
|5A2|__/
\\9/"[$i++];)echo$c>0?str_repeat(" _"[$c>8],$c+1):$c;

This looks a lot like Arnauld´s answer - and does pretty much the same. Run with -r.

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

zsh, 86 bytes

printf "^_<8b>^H^@^@^@^@^@^B^CSPÈçR^@^A^P^CJÆÃ^A<97>¾^B^\Ä^@¹5@Ú^KÂ^E2cÀ|^EG^X¿^FÂW^HCæÃTÔÄÇësÅÀ^L^Fq^@<92>}ý^?{^@^@^@"|zcat

Explanation: that string is the gzip-compressed java cup ascii art. I use printf, because with echo, zcat prints a warning, and echo -e is one character longer. It doesn't work with bash or sh, because they think it's a binary file. Since you can't effectively paste that output from the browser, here's a usable file.

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

Java 9 / JShell, 299 bytes

()->{String s="";BigInteger b=new BigInteger("43ljxwxunmd9l9jcb3w0rylqzbs62sy1zk7gak5836c2lv5t36ej6682n2pyucm7gkm9bkfbn4ttn0gltbscvbttifvtdfetxorj6mmy3mt6r3",36);while(!b.equals(BigInteger.ZERO)){int x=b.intValue()&0x3ff;for(int i=0;i<x>>7;i++)s+=' ';s+=(char)(x&0x7f);b=b.shiftRight(10);}return s;}

Ungolfed:

() -> {
    String s = "";
    BigInteger b = new BigInteger(
        "43ljxwxunmd9l9jcb3w0rylqzbs62sy1zk7gak5836c2lv5t36ej6682n2pyucm7gkm9bkfbn4ttn0gltbscvbttifvtdfetxorj6mmy3mt6r3",
        36);
    while (!b.equals(BigInteger.ZERO)) { 
        int x = b.intValue() & 0x3ff;
        for (int i = 0; i < x >> 7; i++) s+=' ';
        s += (char)(x&0x7f);
        b = b.shiftRight(10);
    }
    return s;
}

Usage in JShell:

Supplier<String> golf = <lambda expression>
System.out.println(golf.get())

Encodes each character as ten bits consisting of a count of the number of spaces before the character in the high three bits following by the code point in the low seven bits.

(Since there are only three bits for the count it can't represent more than seven consecutive spaces, and there are ten spaces at one point in the string. These are encoded as a count of six, followed by a space, and then a count of three followed by the next character.)

Sadly, it loses to this trivial 140-byte Java solution:

()->"  o\n       o\n    o\n __________\n/          \\__\n|   J      |  \\\n|    A     |  |\n|     V    |  |\n|      A   |__/\n\\__________/"
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 85 bytes

•1d'uì[_ÍpH»Ð]jŠ$ÿ{ɘß|ªpå±W¾Ö:ÞjÇ&@è$´Öàˆå]Á¢šBg¦ï&-ã¥ønØ7Ñà'?•9B8ÝJ"o _/\|JAV"‡15ô»

Try it online!

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