23
4
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!
23
4
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!
3
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\\",
"__________",
"/"
16
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())
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:
N
consecutive spaces is encoded with the digit N-1
.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
.
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
– edc65 – 2017-02-24T15:19:30.413
@edc65 I've no idea why I counted f=
in that one... Thanks for the saved bytes! – Arnauld – 2017-02-24T15:28:07.747
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? – Cruncher – 2017-02-24T16:33:53.757
1@Cruncher I've added a 'How it works' section. – Arnauld – 2017-02-24T17:22:40.773
@Arnauld Very clever :) – Cruncher – 2017-02-24T17:43:51.897
Why not change console.log(f())
to alert(f())
to save 6 bytes – Albert Renshaw – 2017-02-25T23:00:30.733
Or is that not part of your byte count? – Albert Renshaw – 2017-02-25T23:06:46.017
@AlbertRenshaw That's right: let f =
and console.log(f())
are not part of the answer. They're not counted at all. – Arnauld – 2017-02-25T23:07:45.687
Ah gotcha okay cool! Good answer btw – Albert Renshaw – 2017-02-25T23:09:53.047
16
-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
“...“...’
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 |__/
\__________/
7I swear some of these languages are straight up compression algorithms – Cruncher – 2017-02-24T16:26:48.213
4Of 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? – Cruncher – 2017-02-24T16:38:11.450
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). – Jonathan Allan – 2017-02-24T16:51:42.593
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. – Dennis – 2017-02-26T13:43:34.617
@Dennis ah, nice save with the reduce, and catch on the trailing close quote. I did actually think about using the pilcrow and must have gotten side-tracked. – Jonathan Allan – 2017-02-26T19:57:43.020
9
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,"\\")
f=()->""" o
o
o
__________
/ \__
| J | \\
| A | |
| V | |
| A |__/
\__________/"""
8No 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. – HyperNeutrino – 2017-02-24T14:37:52.587
@HyperNeutrino, I agree, working on improving it. – Tom – 2017-02-24T14:39:11.837
9
"""2o
7o
4o
$(($a='_'*10))
/55\__
|3J6|2\
|4A5|2|
|5V4|2|
|6A3|__/
\$a/"""-replace'(\d)','$(" "*$1)'|iex
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.
That's strange, hardcoding is shorter. Hm. +1 anyway :) – HyperNeutrino – 2017-02-24T14:47:49.800
I was hoping for some answers using innovative (huffman) coding schemas, but my python implementation is still coming up longer as well.. – Aaron – 2017-02-24T14:54:02.580
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. – colsw – 2017-02-24T17:43:56.617
@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.
strange that wrapping the ' '*$_
in a scriptblock doesn't stop that behavior, but powershell will do as it will. – colsw – 2017-02-24T17:59:40.717
@ConnorLSW you can do it like this, but the extra quoting kills its viability (the solution would be 124 bytes again): ("'$_'","' '*$_")[+$_-in48..57]|iex
– briantist – 2017-02-26T03:39:58.790
1@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. – AdmBorkBork – 2017-02-27T13:47:37.783
@AdmBorkBork not related to this question but I thought you might be interested in this
– briantist – 2017-02-27T15:41:10.4507
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!
You seem to have 2 useless whitespaces at ] for
and in [
. – Yytsi – 2017-02-25T07:07:03.073
Actually, you can shorten [2,7,4]
and [3,4,5,6]
to 2,4,7
and 3,4,5,6
. – Yytsi – 2017-02-25T07:09:31.613
4
-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))
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()
.
You can replace u,u
with ('_'*10,)*2
and drop the u
declaration – Rod – 2017-02-24T16:23:36.313
Oh, nice I did look at that and think there was a way - thanks @Rod! – Jonathan Allan – 2017-02-24T16:53:41.353
4
[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
4
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.
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 |__/\
\\__________/
Encoding ss
as S
saves 1 byte. – Riley – 2017-02-24T16:19:29.857
@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. – seshoumara – 2017-02-24T16:26:17.467
4
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 kolmogorov-complexity, 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();
}
}
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
. – David Conrad – 2017-02-26T18:03:37.033
@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. – None – 2017-02-26T18:06:11.640
That's a good point. – David Conrad – 2017-02-26T18:10:05.903
1@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. – None – 2017-02-26T18:57:21.763
1There 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. – None – 2017-02-26T19:16:26.913
2
(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.
2
<v"XaXXXNYXNY77777'XXXXX2_TXQXX0XZTXDXX0X^TXXRX0X^TXXDX07]27777#"p29+55
:<_@#:,g2/+55,g2%+55
\JV/|_Ao
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:
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.
2
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)
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)1
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*'_'+'/')
2So many space characters… Better declare a s=' '
variable and use it. – manatwork – 2017-02-24T14:36:29.487
Also wouldn't hurt to predefine newline – Post Rock Garf Hunter – 2017-02-24T14:37:27.303
3Hardcoding the output is shorter – user41805 – 2017-02-24T14:41:02.603
@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
. – manatwork – 2017-02-24T15:50:16.473
2
@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.
1
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.
1
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');
}
1Brute 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");}
– Churam – 2017-02-24T17:21:54.273
1
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.
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!
You can also change 1\n__________
to 1\n_____
and then change each 1
in the main substitution to 11
Try it online!
@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^^ – Leo – 2017-02-26T10:33:46.453
1
"2o
7o
4o
0
/55\__
|3J6|2\
|4A5|2|
|5V4|2|
|6A3|__/
\0/"-replace'\d',{' '*"$_"+(,'_')["$_"]*10}
0
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.
3Non-competing is not an excuse for invalidity. – Mego – 2017-02-24T16:23:57.360
@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 – Aaron – 2017-02-24T16:26:57.903
@Mego fixed... just for you – Aaron – 2017-02-24T16:44:39.690
0
show_message(" o# o# o# __________#/ \__#| J | \#| A | |#| V | |#| A |__/#\__________/")
0
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);}
main(){f();}
w(){puts(" o\n o\n o\n __________\n/ \\__\n| J | \\\n| A | |\n| V | |\n| A |__/\n\\__________/");}
0
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
.
0
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.
0
()->{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\\__________/"
0
•1d'uì[_ÍpH»Ð]jŠ$ÿ{ɘß|ªpå±W¾Ö:ÞjÇ&@è$´Öàˆå]Á¢šBg¦ï&-ã¥ønØ7Ñà'?•9B8ÝJ"o _/\|JAV"‡15ô»
0
'oƵ®Sú»•BÇÉι!т³ÂSˆtTóV”PHAëdÀāåΘý”å.@=Ø₂)øUqrÖ½ñ*•“_ |
\/AVJ“ÅвJ»
Pretty straight-forward approach which most likely has room for improvement.
Explanation:
'o '# Push an "o"
Ƶ® # Push compressed integer 274
S # Convert it to a list of digits: [2,7,4]
ú # Prepend that many leading spaces to the "o": [" o"," o"," o"]
» # Join them by newlines: " o\n o\n o"
•BÇÉι!т³ÂSˆtTóV”PHAëdÀāåΘý”å.@=Ø₂)øUqrÖ½ñ*•
# Push compressed integer 21514733101393053622421734761651860518184887728386739717403046550918945532453802933506348033205129
“_ |\n\/AVJ“ # Push string "_ |\n\/AVJ"
Åв # Convert the integer to base-"_ |\n\/AVJ"
# (builtin for converting to base string-length, and index those into the string)
J # Join the characters to a single string
» # And join the two strings on the stack by a newline
# (after which the result is output implicitly as result)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ƶ®
is 274
and •BÇÉι!т³ÂSˆtTóV”PHAëdÀāåΘý”å.@=Ø₂)øUqrÖ½ñ*•
is 21514733101393053622421734761651860518184887728386739717403046550918945532453802933506348033205129
.
38I'd be very suspicious of a cup of sparkling coffee. ;) – Dennis – 2017-02-24T14:22:01.817
9@Dennis it's my special coffee for Friday mornings ;) – Aaron – 2017-02-24T14:22:46.143
1Wouldn'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. – manatwork – 2017-02-24T14:31:58.070
1Would it be acceptable to have trailing white space on lines? – Jonathan Allan – 2017-02-24T14:38:25.077
2@Aaron the cup don't have a good pattern, hard-coding/compressing will be shorter in many languages – Rod – 2017-02-24T14:55:09.477
@Rod my intention was to try to encourage an extremely small huffamn decoder, but I can see it has largely failed... I can also see a good regex coming into play here – Aaron – 2017-02-24T14:59:10.450
I like this pattern. The opportunities for compression are there, but subtle. – xnor – 2017-02-24T17:21:43.610
@xnor I have created challenges that end up getting solved in 4 or 5 bytes before by the likes of jelly, matl, etc... I didn't want to make it too easy :) Here languages like JavaScript and Perl have a fighting chance (although still at a disadvantage) – Aaron – 2017-02-24T17:26:23.300
1@Dennis Yeah, fizzy coffee isn't normal or tasty at all... except if it's a new type of coffee, anti-golfing coffee. – Erik the Outgolfer – 2017-02-25T14:33:59.180