# “Cowsay” in short [closed]

Simulate cowsay in the default mode.

$cowsay <<< Hello _______ < Hello > ------- \ ^__^ \ (oo)\_______ (__)\ )\/\ ||----w | || ||$ perl -e 'print "Long text "x20' | cowsay
__________________________________________
/ Long text Long text Long text Long text  \
| Long text Long text Long text Long text  |
| Long text Long text Long text Long text  |
| Long text Long text Long text Long text  |
\ Long text Long text Long text Long text  /
------------------------------------------
\   ^__^
\  (oo)\_______
(__)\       )\/\
||----w |
||     ||


How short can be the code? The cow and the balloon can be slightly different, but all elements should be present. Dynamic/multiline balloon is a plus.

Explicit list of the required elements:

• Text;
• Balloon;
• Line from the cow to the balloon;
• The cow (eye[s], month, ears, body, legs (minimum two), udder, tail).

/usr/share/cowsay/cows/ may be accessed, but obviously not /usr/games/cowsay itself.

Note: here is the /usr/share/cowsay/cows/default.cow file:

$the_cow = <<"EOC";$thoughts   ^__^
$thoughts ($eyes)\\_______
(__)\\       )\\/\\
$tongue ||----w | || || EOC  Usage of the file is optional. When used, it must be accessed by full path. (Windows users may copy it to something like C:\usr\share\cowsay\co\default.cow, for fairness). ## closed as off-topic by Mego♦, Loovjo, Rɪᴋᴇʀ, Adnan, mbomb007Aug 26 '16 at 15:47 This question appears to be off-topic. The users who voted to close gave this specific reason: • "Questions without an objective primary winning criterion are off-topic, as they make it impossible to indisputably decide which entry should win." – Mego, Loovjo, Rɪᴋᴇʀ, Adnan, mbomb007 If this question can be reworded to fit the rules in the help center, please edit the question. • I'm voting to close this as off-topic because the specification for the format is extremely non-descriptive, which makes it impossible to determine validity of outputs. – Mego Aug 26 '16 at 7:24 ## 5 Answers ## Mathematica: Work in progress I'll pin down the balloon once I can get the cow to settle: ExampleData[{"Geometry3D", "Cow"}]  • this made my day. – acolyte Apr 12 '13 at 14:06 • bahahahhahahahhaha – jamylak Apr 13 '13 at 9:24 • ...is it done yet? – noɥʇʎԀʎzɐɹƆ Aug 18 '16 at 19:08 • Any further development on that balloon? – Taylor Scott May 16 '17 at 23:16 # Perl, 84 characters print$a='-'x52,<>=~s/.{1,50}\b/sprintf"
|%-50s|",$&/rge,"$a
\\
]:p
| )=
| P=
¬"


Output:

----------------------------------------------------
|Long text Long text Long text Long text Long text |
|Long text Long text Long text Long text Long text |
|Long text Long text Long text Long text Long text |
|Long text Long text Long text Long text Long text |
----------------------------------------------------
\
]:p
| )=
| P=
¬


Admittedly, I golfed the cow as much as I golfed the code. But the Mathematica cow is going to win anyway :)

Note: Requires Perl 5.16 for the /r non-destructive substitution flag.

• Can you tell us please what is that r after the s///? Can not find such flag in the documentation. Thank you. – manatwork Apr 12 '13 at 15:53
• Upvoted. Not everyone is brave enough to call that "a cow" – Dr. belisarius Apr 12 '13 at 17:06
• Bow your head left to see the cow. – Vi. Apr 12 '13 at 17:37
• @manatwork the r flag returns the result, instead of modifying the operand in place (<> is of course read-only, and can't be modified). – primo Apr 12 '13 at 18:04
• Thank you for the explanation, Vi. @belisarius, it gets a dachshund look here because the line-height: 1.4em set for the code blocks, but in terminal it looks better. – manatwork Apr 12 '13 at 18:15

# Ruby: 152150149146 143 characters

load'/usr/share/cowsay/cows/default.cow'
p=%w{U~ o* o o}
puts l=?-*44,gets.gsub(/(.{1,40})\b\s*/){"( %-41s)\n"%$1}+l,$the_cow.gsub(/$\w+/){p.pop}  The cow art is read from the default.cow file and decorated in after-12-rounds-vs-Mike-Tyson manner, similar with a cowthink -e 'o*' -T 'U~' invocation. The text is read from standard input and wrapped at most 40 characters. Line breaks in the input text are not supported. Sample run: bash-4.2 perl -e 'print "Long text "x15' | ruby cow.rb -------------------------------------------- ( Long text Long text Long text Long text ) ( Long text Long text Long text Long text ) ( Long text Long text Long text Long text ) ( Long text Long text Long text ) -------------------------------------------- o ^__^ o (o*)\_______ (__)\ )\/\ U~ ||----w | || ||  ## With art bending: 138135 136 characters load'/usr/share/cowsay/cows/default.cow' puts l=?-*44,gets.gsub(/(.{1,40})\b\s*/){"( %-41s)\n"%1}+l,the_cow.gsub(/$.+?([use]+)\b/,'\1')


As the elements have to be just present, we can use what we have in place instead of defining realistic ones.

Sample run:

bash-4.2\$ ruby cow.rb <<< 'Hello poor little cow'
--------------------------------------------
( Hello poor little cow                    )
--------------------------------------------
s   ^__^
s  (es)\_______
(__)\       )\/\
ue ||----w |
||     ||


## K, 178

{-1'g,({"+ ",x,((&/(c-4;60-#x))#" ")," +"}'l),(g:,(&/(64;4+c::#*l:(60*!-_-(#x)%60)_x))#"+"),("+  ^__^";" + (oo)\\_______";"   (__)\\       )\\/\\";"       ||----w |";"       ||     ||");}


.

k){-1'g,({"+ ",x,((c-#x)#" ")," +"}'l),(g:,(&/(64;4+c::#*l:(60*!-_-(#x)%60)_x))#"+"),("+  ^__^";" + (oo)\\_______";"   (__)\\       )\\/\\";"       ||----w |";"       ||     ||");}"Hello codegolf.stackexchange.com"
++++++++++++++++++++++++++++++++++++
+ Hello codegolf.stackexchange.com +
++++++++++++++++++++++++++++++++++++
+  ^__^
+ (oo)\_______
(__)\       )\/\
||----w |
||     ||


## APL 133 140 138 122

This one liner takes screen input in the form of a character vector or array enclosed in quotes via: ←⍎⍞ The appearance of the output is improved by including leading and following spaces in the input.

('∘'⍪'∘',((¯2↑1,⍴t)⍴t←⍎⍞),'∘')⍪'∘'⋄5 19⍴(,⍉(19⍴2)⊤323584 196592 63503 4072 3096)\'∘^__^∘(oo)\_______(__)\)\/\||----w|||||'


The cow character locations on each row of the array are specified as 19 bit boolean vectors.

To use input the one liner followed by the bubble text in quotes:

' Hello '

°°°°°°°°°
° Hello °
°°°°°°°°°
°  ^__^
° (oo)\_______
(__)\       )\/\
||----w |
||     ||


Multi-line text is input as an array.

3 36⍴' Multi-line text input as an array. '

°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
° Multi-line text input as an array. °
° Multi-line text input as an array. °
° Multi-line text input as an array. °
°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
°  ^__^
° (oo)\_______
(__)\       )\/\
||----w |
||     ||


This version can be tested via the free APL interpreter at www.nars2000.org

• How to properly count the characters? I counted 171 UTF-8 bytes and 141 Unicode codepoints here (newlines included). /* Also haven't found what I need to apt-get install to run APL... */ – Vi. Apr 12 '13 at 11:07
• @Vi. The APL+WIN v5 character set is based on single byte characters. I have to convert them to UTF-8 to get them to render properly on this site. Therefore I believe I am justified in counting characters including newline characters as single bytes. I am not sure how you can run APL. I normally recommend the free version at nars2000.org but it does not appear to support relative assign. – Graham Apr 12 '13 at 11:18