| Bytes | Lang | Time | Link |
|---|---|---|---|
| 341 | AWK | 250411T193847Z | xrs |
| 155 | 05AB1E | 210509T231326Z | Makonede |
| 194 | Vyxal | 210523T103133Z | emanresu |
| 080 | Canvas | 210510T222634Z | hakr14 |
| 106 | Jelly | 210511T181235Z | Jonathan |
| 117 | Jelly | 210510T004227Z | hyperneu |
| 105 | 05AB1E | 210510T144814Z | ovs |
| 252 | JavaScript ES8 | 210511T002914Z | Arnauld |
| 307 | JavaScript | 210510T075208Z | user1006 |
| 240 | Julia 1.0 | 210510T133554Z | MarcMush |
| 329 | JavaScript V8 | 210509T220510Z | rydwolf |
| 249 | Python 2 | 210509T232826Z | dingledo |
| 144 | Retina | 210510T104956Z | Neil |
| 095 | Charcoal | 210509T224222Z | Neil |
AWK, 346 342 341 bytes
AWK, 346 342 341 336 bytes
{(L=length)>l&&l=L;x[++y]=FS$0 FS}END{l+=2
for(z=y;z;z--)for(;length(x[z])<l;)x[z]=x[z]" "
for(h=g=FS;l--;h=h"-")g=g"_"
if(1~y)g=g"\n<"x[1]">"
else{g=g"\n/"x[1]"\\"
for(i=1;++i<y;)g=g"\n|"x[i]"|"
g=g"\n\\"x[i]"/\n"}print g h"\n"(B=" ")"\\ ^__^\n"B" \\ (oo)\\_______\n"B" (__)\\\\"B")\\/\n"B B" ||----w |\n"B B" || ||\n"}
{ # for each line
b=(B=" ")"\\ ^__^\n"B" \\ (oo)\\_______\n"B" (__)\\\\"B")\\/\n"B B" ||----w |\n"B B" || ||\n"
# the cow
length>l&&l=length; # finding longest line
x[++y] # feed lines to array
=FS$0 FS} # pad each line a spaces
END{ # when no more lines
l+=2 # pad for lines "______"
for(z=y;z;z--) # for each line of text
for(;length(x[z])<l;) # if text is short
x[z]=x[z]" " # pad with spaces
for(h=g=FS;l--; # build lines "------"
h=h"-")g=g"_" # by appending
if(1~y) # if one line of text
print g"\n<"x[1]">" # print and leave
else{ # more than one text line
print g"\n/"x[1]"\\" # initial text
for(i=1;++i<y;) # for each line
print "|"x[i]"|" # print text
print"\\"x[i]"/"} # last line of text
print h"\n"b} # print cow
05AB1E, 155 bytes
¶¡©éθgUð'_XÌ×¶®gΘ„/<èð®нðX®нg->×®gΘ„\>è¶[®¦©gĀ_#®gΘ„|\èð®нðX®нg->×®gΘ„|/è¶}ð'-XÌ×¶•1rΛKιØ²è{ʯ4Þ₁ÐÃ5Λ^ÛиÏú!j™¨õ‰6æ≠ÓÍl¼ûÑ©kθJ*
Rèªùî¾&Σp•"\ ^_
(o)/|-w"ÅвJJ
Vyxal, a 194-byte mess
□⁋↵:ƛL;G:£2+\_*\ +\ $+,L1=[‛< □‛ >++,|□L(n[n›□L=[`\\ `` /`|`| `` |`]|`/ `` \\`]□ni:L¥ε\ *+$++,)]\ ¥2+\-*\ ++,` ?\\ ^__^
?\\ (oo)\_______
?? (__)\\ ?)\\/\\
???||----w |
???||?||
`\?\ 5*V,
Explanation tomorrow.
Canvas, 92 87 86 83 81 80 bytes
l╷?/ω┤|*\∔∔]<} +↔ω┘+×L┤_×α-×└∔∔r 7ד;yB¾‾≡*hsNMnJS=f≤)g<◂AX↓ZxLh?╷r┌╴\⁵n╪.cE^‟+∔
Takes input surrounded by ```.
Jelly, 106 bytes
“¢Ʋėỵ“Œ\ė#ݲ¿“¤e+ṂTƒƑ¶d“Ṫ©Ḋ9çṀṠ“Ṫ©Ḋ87⁹Ġ’ṃ“ \_)o|w-^/(”⁶;$8¡€
Ø^⁾><Ṗ?WẋLU0¦”|JṖḊƊ¦⁾ ©jṁ€2ɓ®jⱮz⁶⁾_-jⱮZj@";¢
A monadic Link that accepts a list of the lines and yields a list of lines. (Gives eight spaces before the cow, for seven change 8¡€ to 7¡€)
How?
Ø^⁾><Ṗ?WẋLU0¦”|JṖḊƊ¦⁾ ©jṁ€2ɓ®jⱮz⁶⁾_-jⱮZj@";¢ - Main Link: list, Lines
Ṗ? - if popped (Lines)? (i.e. > 1 line?):
Ø^ - then: "/\"
⁾>< - else: "><"
W - wrap (that) in a list, say "Corners"
L - length (of Lines)
ẋ - repeat (Corners that many times)
0¦ - apply to rightmost:
U - upend (reverse to "<>" or "\/")
Ɗ¦ - apply to indices...
J - range of length (of Lines)
Ṗ - pop
Ḋ - dequeue
”| - ... '|' (replaces all but first and last)
⁾.. - " "
© - (copy this to the register)
j - join
ṁ€2 - mould each like 2 ("||" and " " as needed)
ɓ - new dyadic chain - f(Lines,Edges=that)
® - recall from register -> " "
jⱮ - map (across Lines) with join
z⁶ - transpose with space as filler
⁾_- - "_-"
jⱮ - map (across these columns) with join
Z - transpose (back to rows)
@" - zip with, with swapped arguments:
j - (Edge-pair) join (Row)
¢ - call last Link as a nilad -> cow lines
; - concatenate
“...’ṃ“ \_)o|w-^/(”⁶;$8¡€ - Link 1, Get cow lines: no arguments
“...’ - list of integers (one per line of the cow)
“ \_)o|w-^/(” - " \_)o|w-^/(" (the cow's constituents)
ṃ - base decompress
€ - for each:
8¡ - repeat this eight times:
$ - last two links as a monad:
⁶ - ' '
; - concatenate
Jelly, 117 bytes
L⁾||ẋṫ5“/\“\/”jµ⁾<>Ḋ?⁶ẋ4¤s2¤js1s2
j@€⁾ z⁶⁾_-jⱮZj@"Ç;“¡{+Ṁ“#ßɗ⁾ŀ`m“¬ṖȥƇʂẆEẒẓ“¡ɲÇ⁹E⁸ċ⁷“¡ɲÇ⁹D⁹{Ṅ’ṃ“\ ^_(o)/|-w”¤⁶;$8¡€¤
-26 bytes using base + integer compression (thanks to Bubbler for the idea)
-2 bytes thanks to caird coinheringaahing
-1 byte thanks to Nick Kennedy
thanks to Jonathan Allan for finding a bug; also -4 bytes from fixing it
-1 byte thanks to Jonathan Allan
Explanation
L⁾||ẋṫ5“/\“\/”jµ⁾<>Ḋ?⁶ẋ4¤s2¤js1s2 Helper Link - generates the side borders
? If
Ḋ list[1:] (basically, if the length is not 1)
L⁾||ẋṫ5“/\“\/”jµ Sublink; generate the side borders for the non-edge case
L Take the length
⁾||ẋ Repeat "||" that many times
ṫ5 Tail; remove the first 4 elements
“/\“\/”j Use that result to join ["/\", "\/"]
⁾<> Otherwise, return "<>"
⁶ẋ4¤ " " * 4
s2¤ split into slices of size 2
j Prepend and append (Extra spaces are needed because the top and bottom borders don't have side borders)
s2 Slices of length 2 (separate the left and right border components)
s2 Slices of length 2 (group the left and right border components into pairs)
j@€⁾ z⁶⁾_-jⱮZj@"Ç;“...’ṃ“ \_(o)/|-w^”¤⁶;$8¡€¤ Main Link
j@€⁾ join " " with each row (surround in spaces)
z⁶ Zip, using space as filler
Ɱ For each column
⁾_-j Join ["_", "-"] using it (prepend _ and append -)
Z Zip
j@"Ç Vectorized swapped join with the helper link (basically, for each row, prepend and append the borders)
; Append: {{
“...’ [23386201, 8811166311836860, 134563374682941922730, 101089407352370886, 101089407336781202]
ṃ“ \_(o)/|-w^” Base decompressed with " \_(o)/|-w^" - this is the cow without leading spaces
€ For each row
⁶;$ Prepend " "
8¡ 8 times
¤ }}
05AB1E, 116 112 105 bytes
-7 bytes thanks to Kevin Cruijssen!
.BDgi„><€S`ëDgÍ'|и'\š'/ªÂ}Š)ø¬Jg'_×ð욬¤'-:ª•˜©ã€õĆWõ½*¸cÀΓý¼oº₁%<Yë;Gá“•" \^_
(o)/|-w"ÅвJ¶¡•–ãö•28вjÅ\«»
Speech bubble:
# add sides:
.B # Squarify: split input by newlines and pad each line to the same length with spaces
Dg # duplicate the list and get the number of lines
i # if this equals 1:
„><€S` # push [">"] and ["<"]
# stack layout: ["Single line"], [">"], ["<"]
ë # else (more than one line of input):
DgÍ # number of lines - 2
'|и # repeat "|" this many times in a list
'\š'/ª # prepend "\" and append "/"
# the list is now ["\", "|", ..., "|", "/"]
 # keep this list and push the reverse
# stack layout: ["multi-line", ..., "input"], ["\", "|", ..., "|", "/"], ["/", "|", ..., "|", "\"]
# add top and bottom:
Š)ø # triple-swap, wrap stack into a list and transpose to assemble the lines
¬Jg # get the length of the first complete line (without the spaces)
'_× # create a string of this many "_"
ðì # prepend a space
š¬ # prepend this string to the list of lines
¤'-: # push another copy of the "_" string and replace "_" with "-"
ª # append to the list of lines
Cow:
•˜...á“•" \^_\n(o)/|-w"ÅвJ # base-compressed cow without leading spaces
•–ãö•28в # compressed list of line lengths: [15, 23, 27, 24, 24]
jÅ\ # pad each line to desired length with spaces in the front
«» # concatenate the cow lines to the other lines and join the lines by newlines
JavaScript (ES8), 266 252 bytes
s=>` _2
3
-2
5\\ 1^__^
10\\ (oo)\\_5
9(__)\\ 5)\\/\\
13||-6w |
13|| 7||`.replace(/.(\d+)/g,(s,n)=>n^3?s[i=0].repeat(n^2||w):a.map(s=>'|\\/<'[j=!i++*2|!a[i]]+s.padEnd(w)+'|/\\>'[j]).join`
`,a=s.split`
`.map(w=s=>` ${w>(v=s.length+2)?0:w=v,s} `))
How?
We first split the input string into lines surrounded with 2 spaces and compute the width w of the biggest line (including said spaces):
a = s.split`\n`.map(w = s => ` ${w > (v = s.length + 2) ? 0 : w = v, s} `)
Each number n in the template string is interpreted as follows:
2: repeat the preceding characterwtimes (for the top and bottom borders of the text bubble)3: insert the text bubble:a.map(s => '|\\/<'[j = !i++ * 2 | !a[i]] + s.padEnd(w) + '|/\\>'[j] ) .join`\n`anything else: repeat the preceding character
n XOR 2times
JavaScript, 342 299 307 bytes
n=>[' '+'_'.repeat(e=Math.max(...(s=n.split`
`).map(l=>l.length))+2),...s.map((i,l,_,x=i.padEnd(e-1))=>1 in s?l?l>s.length-2?`\\ ${x}/`:`| ${x}|`:`/ ${x}\\`:`< ${x}>`),' '+'-'.repeat(e),''].join`
`+[(n=' ')+"\\ ^__^"," \\ (oo)_______",` (__)${n})\\/\\`,n+` ||----w |`,n+" || ||"].join(`
`+n)
Explanation
This builds an array of strings which are joined with a newline.
What each element does
- element 1: underscore string
- next few elements: each line of the inputted string with the added limiters
- next element: hyphen string
- then, add the cow string.
-43 bytes thanks to A username
+8 bytes due to empty line bug
Julia 1.0, 243 240 bytes
r=readlines()[(R=end;:)]
a=' '
l=maximum(length,r)+2
println.([a*'_'^l
["|/\\<"[(j=1+(i<2)+2(i==R);)]rpad(a*r[i],l)*"|\\/>"[j] for i=1:R]
a*'-'^l
replace(raw"? \ ^__^
? \ (oo)\_______
?? (__)\? )\/\
???||----w |
???||?||",'?'=>a^5)])
I was trying to compress the cow but dingledooper's trick was more efficient
JavaScript (V8), 380 354 329 bytes
-25 thanks to @A username
t=>` ${"_".repeat(m=Math.max(...(l=t.split`
`).map(d=>d.length)))}__
${"/<"[j=+!l[1]]} ${l.shift().padEnd(m)} ${"\\>"[j]}
${j?'':l.map(d=>"|\\"[w=+!l[++j]]+' '+d.padEnd(m)+' '+"|/"[w]).join`
`+`
`} `+"-".repeat(m+2)+`
\\ ^__^
\\ (oo)\\_______
(__)\\${n=' '})\\/\\
${n}||----w |
${n}|| ||`.replace(/\n/g,`
`+n)
Python 2, 249 bytes
-1 byte thanks to @ovs
-3 bytes thanks to @Jonathan Allan
A relatively straight-forward implementation. One thing to note is that the cow contains a lot of spaces, which allows us to save a couple bytes by using replace.
s=input().split('\n')
m=max(map(len,s))+2
l=len(s)-2
z=-l*'<>'or'/\\'+'||'*l+'\/'
print'','_'*m
for c in s+['-'*m,'''? \ ^__^
? \ (oo)\_______
?? (__)\? )\/\\
???||----w |
???||?||'''.replace('?',' '*5)]:print z[:1],c.ljust(m-2),z[1:2];z=z[2:]
Retina, 156 144 bytes
mP`^.*
¶
\¶\
1,-2%`^.|.$
|
^
$.%'*_¶/
$
/¶ $.%`*-
¶/(.+)/¶
__¶<$1>¶
$
¶7* \ ^__^¶8* \ (oo)\7*_¶11* (__)\7* )\/\¶15* ||4*-w |¶15* ||5* ||
Try it online! Explanation:
mP`^.*
Pad all lines to the same length.
¶
\¶\
Add \s on all the intermediate lines...
1,-2%`^.|.$
|
... but fix interior lines to use | instead.
^
$.%'*_¶/
$
/¶ $.%`*-
Insert the leading row of _s and trailing row of -s, plus the /s at the start and end of the bubble (still assuming a multiline bubble).
¶/(.+)/¶
__¶<$1>¶
Fix up a single-line bubble, not only to change the /s to <>s, but also because not enough _s are calculated for the initial row.
$
¶7* \ ^__^¶8* \ (oo)\7*_¶11* (__)\7* )\/\¶15* ||4*-w |¶15* ||5* ||
Append the cow using run length encoding.
Charcoal, 95 bytes
≔⌈E⪪θ¶⁺²LιηP×_ηM↙EI⁺²Xχ№θ¶§|/\<Iι η‖BOηM⁷¦¹↘²M²↗”{‴JCεχ(J7WS⊙u#←L⌈η‽=Ykc8¿№➙Q⎚⊗\`ê:VI✂e≡8s”J¹¦¹θ
Try it online! Link is to verbose version of code. Note that multiline input with empty lines is an awkward input format for Charcoal, so you'll have to use Pythonic format. Explanation:
≔⌈E⪪θ¶⁺²Lιη
Find out the length of the longest line in the text.
P×_ηM↙
Print the top row of underscores, then move down and left so that the next output appears to the left of the underscores.
EI⁺²Xχ№θ¶§|/\<Iι
Print the left-hand side of the speech bubble. Each row is coded according to whether it is the first (+1) or last (+2) row, with a row that is both first and last therefore having a value of 3, which is then indexed to find the appropriate character.
η
Print the row of dashes aligned with the underscores.
‖BOη
Reflect the left side to complete the speech bubble.
M⁷¦¹↘²M²↗
Print the diagonal line joining the speech bubble to the cow.
”{‴JCεχ(J7WS⊙u#←L⌈η‽=Ykc8¿№➙Q⎚⊗\`ê:VI✂e≡8s”
Print the cow as a compressed string.
J¹¦¹θ
Jump back to the bubble to print the input text.