我试图使它正常工作时几乎发疯了...
U?S+'_pC +R:" oo o oo\n "+'opC +"\no")+"\\, \\,} |, /,/"q', £(V=(!Y«U?"|: |" +SpA +'|+X,(1+5*Mr)o mZ=>Ul <Y*4+4©(V=Vh2+A*Mr ,'° ),V)qR +"\n \\"+'_pA +'/+R+(Ul ¥3?"Yuck, foam.":Ug22 ?`B¨p:
(注意:该程序是针对Japt的较旧版本制作的,当前无法在最新版本中使用。要解决此问题,请在URL中指定较旧的版本。不幸的是,这也意味着右上方的代码框不起作用。)
这是迄今为止我用Japt编写的最长的程序。这是一个细分:
步骤1:创建啤酒杯的顶部。
U?S+'_pC +R:" oo o oo\n "+'opC +"\no")
// Implicit: U = input string
// Begin the ASCII art with:
U?S+ // If U is not an empty string, a space +
'_pC +R: // "_".repeat(12) + a newline.
:"..."+ // Otherwise, this string +
'opC + // "o".repeat(12) +
"\no") // a newline and an "o".
如果U是一个空字符串,则使得:
oo o oo
oooooooooooo
o
否则,这将导致:
____________
第2步:创建杯子的中间行。
+"\\, \\,} |, /,/"q', £(V=(!Y«U?"|: |" +SpA +'|+X,
+"..." // Add to the previous string: this string,
q', £( // split at commas, with each item X and its index Y mapped to:
V=( // Set variable V to the result of concatenating:
!Y«U? // If Y is 0 and U is an empty string,
"|: |" // "|"; otherwise, " |";
+SpA // 10 spaces,
'|+X, // "|", and X.
这将导致前一个字符串加上:
| |\
| | \
| |} |
| | /
| |/
步骤3:添加气泡。
(1+5*Mr)o mZ=>Ul <Y*4+4©(V=Vh2+A*Mr ,'° ),V)
// Note: We're still looping through the five rows at this point.
(1+5*Mr) // Generate a random integer between 1 and 5.
o // Create an array of this many integers, starting at 0.
mZ=> // Map each item Z in this range to:
Ul <Y*4+4© // If the length of U is less than Y*4+4,
// (in other words, if there's less than Y+1 "sip"s)
(V=Vh '° // Insert "°" at position
2+A*Mr // 2 + random number between 0 and 9.
),V)qR // Finally, return V, and join the five rows with newlines.
此时,杯子看起来像这样:
____________
| |\
| | \
| ° |} |
|° ° ° | /
| ° ° |/
步骤4:添加最后一行和可选文本。
+"\n \\"+'_pA +'/+R+(Ul ¥3?"Yuck, foam.":Ug22 ?`B¨p:
+"\n \\" // Add a newline and " \".
+'_pA // Add 10 "_"s.
+'/+R // Add a slash and a newline.
+(Ul ¥3? // If the length of U is 3 (i.e. 1 "sip"),
"..." // add the string "Yuck, foam.".
:Ug22 ? // Otherwise, if U has a character at position 22 (six or more "sip"s),
`B¨p // decompress this string ("Burp") and add it.
: // Otherwise, add nothing.
现在,一切准备就绪,可以发送到输出了,这是自动完成的。如果你有任何问题随时问!
°
是代码点176字符