このアスキーコーヒーカップを描きます。
o o o __________ / \ __ | J | \ | A | | | V | | | A | __ / \ __________ /
コーヒースクリプトまたはjavaのブラウニーポイント:)
バイト、関数またはプログラム、末尾の改行または空白での最短コードは許容されます、飲み干してください!
このアスキーコーヒーカップを描きます。
o o o __________ / \ __ | J | \ | A | | | V | | | A | __ / \ __________ /
コーヒースクリプトまたはjavaのブラウニーポイント:)
バイト、関数またはプログラム、末尾の改行または空白での最短コードは許容されます、飲み干してください!
回答:
mγmλ⁶…Jcēņ▒&↓¡℮štΥ{ιE‽▼⅛÷εγ╝Ξ∫$■⌡πθ&χF׀▼ΡQ7L↓F¶‘
説明:
SOGLには組み込みの文字列圧縮があり、その中の1つに文字辞書圧縮があります。さらに良いことに、使用可能な文字が「/ \ | _- \ n」のみであるボックス文字列圧縮タイプがあります。したがって、プログラム全体は、「」で囲まれた文字列です(「」は暗黙的です)。
私がコンプレッサーに与えた文字列は(エスケープされます):
" o\n o\n o\n ",
"__________",
"\n/ \\__\n| ",
"J",
" | \\\n| ",
"A",
" | |\n| ",
"V",
" | |\n| ",
"A",
" |__/\n\\",
"__________",
"/"
edc65のおかげで4バイト節約
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())
オリジナルのASCIIアートの圧縮は、2〜10個の連続するスペースのすべてのシーケンスと、10個の連続するアンダースコアの2つのシーケンスを1桁に置き換えることで実現されます。
N
連続するスペースの各シーケンスは、数字でエンコードされN-1
ます。9
。私たちは、使用N-1
するのではなくN
、我々が一桁以上使用する必要がありませんように。したがって、++n
デコード時の必要性。
式n>>3
(右へのビット単位シフト)は、n = 1
to が0でn = 7
、n = 8
(使用されない)およびが1ですn = 9
。したがって、に' _'[n>>3]
はアンダースコアを9
、その他のすべての値にはスペースを提供します。
唯一の特殊なケースは、「JAVA」のすぐ上にある10個の連続したスペースのシーケンスです。でエンコードすると9
、アンダースコアシーケンスと競合します。したがって、それを5つのスペースの2つのシーケンスに分割し、としてエンコードする必要があります44
。
f=
)。あなたはこの方法でバイト4を保存することができます:n>>3
代わりに+!(n&7)
、9
代わりに_8
(2回)をし、44
代わりに9
f=
はその中に数えたのか分かりません...節約されたバイトをありがとう!
' '
)。しかし、それがどのように行われるのか正確にはわかりません。ビットシフトは何をしますか?なぜnを増やしているのですか?
Dennisのおかげで-2バイト(1.冗長性を削除し”
、2。転置およびランレングスデコードZŒṙ
を要素の繰り返しによる削減で置き換えx/
ます。)
“Ñṁ{xGgṭḷVỤɲ8ṿfƬT9Ɱ¹=qṀS“$<(ƇỤ08ØÑḌṃṘX6~cuc8HṗḞ2’Dx/ị“ ¶_/\|JAVo
“...“...’
2つのbase-250圧縮数のリストです。
[1021021021332411532617161526181616261916162618163425334, 2117114111551155121131612111415121115141211161312111551]
D
10進数に変換して、2つの数字リストを生成します。
[[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/
要素の繰り返しによって減少し、1つの数字のリストを提供します(最初のリストからの数字をもう1つのリストの対応する値で繰り返す):
[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]
ị
右側のリストにインデックスを作成するよう指示します。1つはベースであり、モジュール式です(右端のアイテムには0インデックス)。右側のリスト¶_/\|JAVo
は、ピルクロウ¶
が改行と同じコードポイントである必要な順序で使用される文字です。“
これがプログラムの終了であるため、終了パートナーは必要ありません。
[' ', ' ', 'o', '\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'o', '\n', ' ', ' ', ' ', ' ', 'o', '\n', ' ', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '\n', '/', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\', '_', '_', '\n', '|', ' ', ' ', ' ', 'J', ' ', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', '\\', '\n', '|', ' ', ' ', ' ', ' ', 'A', ' ', ' ', ' ', ' ', ' ', '|', ' ', ' ', '|', '\n', '|', ' ', ' ', ' ', ' ', ' ', 'V', ' ', ' ', ' ', ' ', '|', ' ', ' ', '|', '\n', '|', ' ', ' ', ' ', ' ', ' ', ' ', 'A', ' ', ' ', ' ', '|', '_', '_', '/', '\n', '\\', '_', '_', '_', '_', '_', '_', '_', '_', '_', '_', '/']
Jellyはこのリストの暗黙的な印刷を実行します。これには文字が含まれているため、文字列であるかのように印刷されます。
o
o
o
__________
/ \__
| J | \
| A | |
| V | |
| A |__/
\__________/
”
暗黙的であり、あなたは置き換えることができZŒṙ
てx/
。また、バイトがありませんが¶
、リテラル改行の代わりに使用すると、コードがより使いやすいimoになります。
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 |__/
\__________/"""
ハードコーディングなし。
Base-64エンコードなし。
正規表現なし。
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+'/'])
外在で2つのバイトを保存'_'*10
してのPythonの変換を利用してTrue -> 1
してFalse -> 0
。
不要な空白を削除して1バイトを節約しました。
@TuukkaXのおかげで4バイト節約されました!
] for
とin [
。
[2,7,4]
と[3,4,5,6]
する2,4,7
と3,4,5,6
。
"""2o
7o
4o
$(($a='_'*10))
/55\__
|3J6|2\
|4A5|2|
|5V4|2|
|6A3|__/
\$a/"""-replace'(\d)','$(" "*$1)'|iex
@briantist -replace
が、どこかにあると知っていた短い方法を見つけてくれてありがとう。
これは、必要な数のスペースの代わりに数字を含む文字列を取ります。次に-replace
、スクリプト式を使用して数字を正規表現します$(" "*$1)
。したがって、たとえば、文字列の最初の行はになり$(" "*2)o
、2番目の行は同様になります$(" "*7)o
。トリプルクォートのため、これはパイプラインに文字列として残されます。これをダンプしますiex
(略してInvoke-Expression
に似てeval
います)。スクリプト式を処理し、結果の複数行文字列をパイプラインに残します。出力は暗黙的です。
($_,' '*$_)[+$_-in48..57]
-私が何を変更しても、失敗するようです。
s:$: o@SS o@S o@ UU@/SSS \\__@|SJSS| \\@|S AS | |@|S VS | |@|SSAS|__/@\\UU/:
s:S: :g
y:@:\n:
s:U:_____:g
基本的なエンコーディングは、それは3つのスペースとして保存するS
、\n
など@
などと5下線をU
。もっと短いものを見つけるために、組み合わせを試行し続けます。
文字列を直接印刷する簡単な解決策を以下に示します。上記のエンコードスキームを使用して136バイトの圧縮が行われ、結果は18%圧縮されます。
c\ o\
o\
o\
__________\
/ \\__\
| J | \\\
| A | |\
| V | |\
| A |__/\
\\__________/
S
3つのスペースを保存する1バイト少ないソリューションを見つけましたs
。同じ数の変換を保持するため、代わりにこれを編集すると思います。
[TIH][IAC]111Z?c'(ty!(OWM4J4gW{lm> >bw8ch|.FU2W"@\#2Dj!NQDeIMZ'F'_ /|\JAV'Za7e
この解決策は、コーヒーを「泡」とマグカップの2つの部分に分けます。バブルを作成するには、111が3つの位置にあるスパース行列を作成し、文字配列に変換します
[TIH][IAC]111Z?c
マグコンポーネントについては、文字列圧縮に依存しています
'(ty!(OWM4J4gW{lm> >bw8ch|.FU2W"@\#2Dj!NQDeIMZ'F'_ /|\JAV'Za7e
両方のコンポーネントが出力に印刷され、コンポーネント間に改行が自動的に配置されます
MATL Onlineでお試しください
Rodのおかげで-1バイト(('_'*10,)
宣言を避けるためにタプルの乗算を使用)。
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))
注:その二重バックスラッシュは改行の前に必要です。
間のすべて'''
と'''
単一の文字列で、2は、%s
末尾の内容に置き換えますフォーマッタいる%(...)
順番にの2つのコピーが含まタプル、'_'*10
タプル乗算経由を(...)*2
。'_'*10
収量に行う文字列乗算'__________'
。
コードは、文字を横切りc
、その文字列全体を使用for c in '''...
し、(接合によって新しい文字列を生成するjoin(...)
)
のいずれかによって同定スペースの数c
、int(c)
あれば、c
桁である
か、 c
それ自体
-桁であることによって識別さ'0'<c<':'
にわたって保存しますc.isdigit()
。
u,u
て('_'*10,)*2
とドロップu
宣言
ゴルフ:
()->{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;}
コルモゴロフ複雑さの精神で、これは出力する文字列をハードコードしません。代わりに、複数のスペースの後に印刷可能な文字が続く場合が多いという事実を利用します。下位バイトの実際のASCII文字で、文字の上位バイトの文字に先行するスペースの数をエンコードします。
ゴルフをしていない:
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();
}
}
\u0641
ます。
0x
接頭辞をなくすことが助けになりました。
<v"XaXXXNYXNY77777'XXXXX2_TXQXX0XZTXDXX0X^TXXRX0X^TXXDX07]27777#"p29+55
:<_@#:,g2/+55,g2%+55
\JV/|_Ao
文字列内の文字は、最初にインデックスとして10個の可能な値のルックアップテーブルにエンコードされます。次に、インデックスはペアにグループ化され、各ペアは0〜99の範囲の単一の数値(i1 + i2 * 10)に結合されます。ルックアップテーブルの順序を慎重に選択することで、これらの値が常に有効になることを保証できます文字列リテラルで表現できるASCII文字。
これはコード自体の内訳です:
ルックアップテーブルの最後の要素を改行文字(ASCII 10)で初期化することから始めます。
次に、文字列リテラルを使用して、エンコードされたコンテンツをスタックにプッシュします。
最後に、スタックの値をループ処理し、一度に2つの文字をデコードして出力します。
最後の行はルックアップテーブルを保持します。9番目の要素は暗黙のスペースであり、10番目(改行)は前述のように手動で設定されます。
(format t"~3@{~vto
~} ~10@{_~}
/~11t\\__
| J~11t| \\
~2@{|~5t~a~11t| |
~}|~7tA |__/
\\~10{_~}/"2 7 4'A" V"1)
Enterを~&
s ではなくstringに入れるというアイデアを使用して、6バイトを保存しました。
改善のアイデアを歓迎します。
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*'_'+'/')
s=' '
変数を宣言して使用する方が良いでしょう。
'o\n'
、と同じ長さ'o'+n
です。
print(*(' o',7*' '+'o',4*' '+'o',' '+10*'_','/'+10*' '+'\__','|'+3*' '+'J'+6*' '+'| \\','|'+4*' '+'A'+5*' '+'| |','|'+5*' '+'V'+4*' '+'| |','|'+6*' '+'A'+3*' '+'|__/','\\'+10*'_'+'/'),sep='\n')
または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)
、両方まだ長いより197ある136ハードコード。
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.
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');
}
void g(){puts(" o\n o\n o\n __________\n/ \\__\n| J | \\\n| A | |\n| V | |\n| A |__/\n\__________/\n");}
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.
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!
1\n__________
to 1\n_____
and then change each 1
in the main substitution to 11
Try it online!
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.
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\\__________/");}
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
.
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.
()->{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\\__________/"
•1d'uì[_ÍpH»Ð]jŠ$ÿ{ɘß|ªpå±W¾Ö:ÞjÇ&@è$´Öàˆå]Á¢šBg¦ï&-ã¥ønØ7Ñà'?•9B8ÝJ"o _/\|JAV"‡15ô»