78
\$\begingroup\$

"Baby Shark" is a children's song about a family of sharks. Having long been popular as a campfire song, it has been popularized since the mid-2000s by social media, online video and radio. - Wikipedia

Write program that takes no input, and writes the following text to the standard output or an arbitrary file:

Baby Shark doo doo doo doo doo doo
Baby Shark doo doo doo doo doo doo
Baby Shark doo doo doo doo doo doo
Baby Shark!
Daddy Shark doo doo doo doo doo doo
Daddy Shark doo doo doo doo doo doo
Daddy Shark doo doo doo doo doo doo
Daddy Shark!
Mommy Shark doo doo doo doo doo doo
Mommy Shark doo doo doo doo doo doo
Mommy Shark doo doo doo doo doo doo
Mommy Shark!
Grandpa Shark doo doo doo doo doo doo
Grandpa Shark doo doo doo doo doo doo
Grandpa Shark doo doo doo doo doo doo
Grandpa Shark!
Grandma Shark doo doo doo doo doo doo
Grandma Shark doo doo doo doo doo doo
Grandma Shark doo doo doo doo doo doo
Grandma Shark!

This is code golf — shortest code wins.

Found this on Reddit^1^2, and it seems like an interesting challenge to golf.

Updates:

No newline between stanzas, that makes it too easy :)

Leading/trailing newlines are okay.

\$\endgroup\$
18
  • 6
    \$\begingroup\$ Is a newline between each stanza (each shark) acceptable? (That's always how I've seen the lyrics written) \$\endgroup\$
    – Quintec
    Commented Feb 16, 2019 at 2:00
  • 9
    \$\begingroup\$ Eh, missing a few verses, like all the ones about the swimmers swimming and losing limbs in shark attacks. \$\endgroup\$
    – mbomb007
    Commented Feb 16, 2019 at 17:23
  • 3
    \$\begingroup\$ "doo doo doo doo doo doo" is really over-simplified. \$\endgroup\$ Commented Feb 17, 2019 at 23:54
  • 33
    \$\begingroup\$ As a parent, I feel the strongest urge to downvote this one. I'm repressing the urge because that's not how Stack Exchange works. But if I find myself humming "doo doo doo doo" later today, I'm coming back here and holding you accountable! \$\endgroup\$
    – Cort Ammon
    Commented Feb 18, 2019 at 17:22
  • 5
    \$\begingroup\$ How many people's days ruined now that this is on HNQs? \$\endgroup\$
    – CactusCake
    Commented Feb 18, 2019 at 19:49

66 Answers 66

83
\$\begingroup\$

Emojicode, 292 bytes (140 characters)

🏁🍇🔤Baby🔤➡️b🔤Daddy🔤➡️y🔤Mommy🔤➡️o🔤Grandpa🔤➡️g🔤Grandma🔤➡️a🔤 Shark🔤➡️s🔤 doo🔤➡️d🍨b y o g a🍆➡️f🔂m f🍇🔂i🆕⏩⏩0 3❗️🍇😀🍪m s d d d d d d🍪️❗️🍉😀🍪m s🔤!🔤🍪❗️🍉🍉

Run it

Expanded out:

🏁🍇
  🔤Baby🔤 ➡️ b
  🔤Daddy🔤 ➡️ y
  🔤Mommy🔤 ➡️ o
  🔤Grandpa🔤 ➡️ g
  🔤Grandma🔤 ➡️ a
  🔤 Shark🔤 ➡️ s
  🔤 doo🔤 ➡️ d
  🍨b y o g a🍆➡️f
  🔂m f🍇
    🔂i🆕⏩⏩0 3❗️🍇
      😀🍪m s d d d d d d🍪️❗️
    🍉
    😀🍪m s🔤!🔤🍪❗️
  🍉
🍉

Explained (per the Emojicode doc):

🍇🍉

The same as a { and } (e.g. a code block)

🏁

The "program start" (e.g. int main())

🔤Baby🔤 ➡️ b

Variable assignment (e.g. const char* b = "Baby";)

🍨b y o g a🍆➡️f

Says, create a list of values between 🍨 and 🍆 and assign (➡️) to f (e.g. const char* f[] = {b,y,o,g,a};)

🔂m f🍇 ... 🍉

This line says to loop over the elements in f using the alias m, where the ... is the code between 🍇 and 🍉.

🔂 i 🆕⏩⏩ 0 3❗️🍇 ... 🍉

This line says to loop over the range [0,3), where the ... is the code between 🍇 and 🍉.

😀🍪 ... 🍪️❗️

This line says to print the format specified in ... (e.g. printf("%s\n");)

The code translated to C:

#include <stdio.h>

int main() {
  const char* b = "Baby";
  const char* y = "Daddy";
  const char* o = "Mommy";
  const char* g = "Grandpa";
  const char* a = "Grandma";
  const char* s = " Shark";
  const char* d = " doo";
  const char* f[] = {b,y,o,g,a};
  int m = 0, i = 0;
  for (; m < 5; ++m) {
    for (i = 0; i < 3; ++i) {
      printf("%s%s%s%s%s%s%s%s\n", f[m], s, d, d, d, d, d, d);
    }
    printf("%s%s!\n", f[m], s);
  }
  return 0;
}

Following this, the original code (posted below for posterity) had some issues; mostly that the 🏁🍇🍉 block was not included for those who wish to run it, and the emoji's were not actually properly escaped, to that, here is the actual running version of that code:

Original modified to run: Emojicode, 224 bytes (67 characters)

🏁🍇🍨🔤👶🔤🔤👨🔤🔤🤱🔤🔤👴🔤🔤👵🔤🍆➡️f🔂m f🍇🔂i🆕⏩⏩0 3❗️🍇😀🍪m🔤🦈💩💩💩💩💩💩🔤🍪️❗️🍉😀🍪m🔤🦈!🔤🍪❗️🍉🍉

Expanded out:

🏁🍇
  🍨
    🔤👶🔤
    🔤👨🔤
    🔤🤱🔤
    🔤👴🔤
    🔤👵🔤
  🍆 ➡️ f
  🔂 m f 🍇
    🔂 i 🆕⏩⏩ 0 3❗️🍇
      😀🍪m🔤🦈💩💩💩💩💩💩🔤🍪️❗️
    🍉
    😀🍪m🔤🦈!🔤🍪❗️
  🍉
🍉

Which produces the output:

👶🦈💩💩💩💩💩💩
👶🦈💩💩💩💩💩💩
👶🦈💩💩💩💩💩💩
👶🦈!
👨🦈💩💩💩💩💩💩
👨🦈💩💩💩💩💩💩
👨🦈💩💩💩💩💩💩
👨🦈!
🤱🦈💩💩💩💩💩💩
🤱🦈💩💩💩💩💩💩
🤱🦈💩💩💩💩💩💩
🤱🦈!
👴🦈💩💩💩💩💩💩
👴🦈💩💩💩💩💩💩
👴🦈💩💩💩💩💩💩
👴🦈!
👵🦈💩💩💩💩💩💩
👵🦈💩💩💩💩💩💩
👵🦈💩💩💩💩💩💩
👵🦈!

Run it

Where in you have the individual emoji's representing the words:

👶 -> Baby
👨 -> Daddy
🤱 -> Mommy
👴 -> Grandpa
👵 -> Grandma
🦈 -> Shark
💩 -> doo

Original: Emojicode, 138 bytes (47 characters)

🍨👶👨🤱👴👵🍆➡️f🔂m f🍇🔂i🆕⏩⏩0 3❗️🍇😀m🦈💩💩💩💩💩💩❗️🍉😀m🦈!❗️🍉

Expanded out:

🍨👶👨🤱👴👵🍆➡️f
🔂m f🍇
  🔂 i 🆕⏩⏩ 0 3❗️🍇
    😀 m 🦈💩💩💩💩💩💩❗️
  🍉
  😀 m 🦈!❗️
🍉
\$\endgroup\$
9
  • 33
    \$\begingroup\$ Points for creativity, but this doesn't produce the required output \$\endgroup\$
    – Jo King
    Commented Feb 17, 2019 at 10:23
  • 15
    \$\begingroup\$ Welcome to the site! As JoKing was getting at we require that answers do exactly what the question ask here. This means that while your interpretation of the challenge is creative this answer should either be fixed to produce the correct output or deleted. \$\endgroup\$
    – Wheat Wizard
    Commented Feb 17, 2019 at 14:10
  • 12
    \$\begingroup\$ While this answer is creative, it does not follow the requirements of the challenge, and thus is not valid - the text must be output exactly as stated in the challenge. \$\endgroup\$
    – user45941
    Commented Feb 17, 2019 at 20:17
  • 8
    \$\begingroup\$ Please either modify this answer to produce the correct output, or delete it. \$\endgroup\$
    – mbomb007
    Commented Feb 18, 2019 at 19:55
  • 6
    \$\begingroup\$ Welcome to the site! When I try to run this code online, I get an error. (It also counts 98 characters instead of 94). Am I missing something? \$\endgroup\$
    – DJMcMayhem
    Commented Feb 19, 2019 at 18:28
42
\$\begingroup\$

x86-16 machine code, IBM PC DOS, 108 107 bytes

00000000: bd42 01e8 1600 bd47 01e8 1000 bd4d 01e8  .B.....G.....M..
00000010: 0a00 bd53 01e8 0400 c646 056d b409 b104  ...S.....F.m....
00000020: 8bd5 cd21 ba5b 01cd 21e2 06ba 6701 cd21  ...!.[..!...g..!
00000030: c3b3 06ba 6201 cd21 4b75 fbba 6801 cd21  ....b..!Ku..h..!
00000040: ebde 4261 6279 2444 6164 6479 244d 6f6d  ..Baby$Daddy$Mom
00000050: 6d79 2447 7261 6e64 7061 2420 5368 6172  my$Grandpa$ Shar
00000060: 6b24 2064 6f6f 2421 0d0a 24              k$ doo$!..$

Unassembled:

BD 0142         MOV  BP, OFFSET BABY        ; Baby Shark
E8 011C         CALL VERSE
BD 0147         MOV  BP, OFFSET DADDY       ; Daddy Shark
E8 011C         CALL VERSE
BD 014D         MOV  BP, OFFSET MOMMY       ; Mommy Shark
E8 011C         CALL VERSE
BD 0153         MOV  BP, OFFSET GRAND       ; Grandpa/ma Shark
E8 011C         CALL VERSE
C6 46 05 6D     MOV  BYTE PTR [BP][5], 'm'  ; change 'p' to 'm'
            VERSE:
B4 09           MOV  AH, 9                  ; DOS API display string function
B1 04           MOV  CL, 4                  ; loop verse counter
            LOOP_VERSE:
8B D5           MOV  DX, BP                 ; load shark name from BP
CD 21           INT  21H                    ; display shark name
BA 015B         MOV  DX, OFFSET SHARK       ; load 'Shark'
CD 21           INT  21H                    ; display 'Shark'
E2 06           LOOP LOOP_DOO               ; if not last line, write 'doo's
BA 0167         MOV  DX, OFFSET BANG        ; otherwise end with a bang
CD 21           INT  21H                    ; display !, CRLF
C3              RET                         ; return from CALL or to DOS
            LOOP_DOO:
B3 06           MOV  BL, 6                  ; loop 'doo' 6 times
BA 0162         MOV  DX, OFFSET DOO         ; load 'doo' string
            PRINT_DOO:
CD 21           INT  21H                    ; display 'doo'
4B              DEC  BX                     ; decrement doo count
75 FB           JNZ  PRINT_DOO              ; if not last doo, start again
BA 0168         MOV  DX, OFFSET CRLF        ; load CRLF string
CD 21           INT  21H                    ; display CRLF
EB DE           JMP  LOOP_VERSE             ; repeat verse

BABY    DB  'Baby$'
DADDY   DB  'Daddy$'
MOMMY   DB  'Mommy$'
GRAND   DB  'Grand'
PA      DB  'pa$'
SHARK   DB  ' Shark$'
DOO     DB  ' doo$'
BANG    DB  '!'
CRLF    DB  0DH,0AH,'$'

Try it online!

Output

DOS DIR, SHARK

(TODO: update this screenshot for one less byte...)

\$\endgroup\$
4
  • 11
    \$\begingroup\$ You absolute madman. \$\endgroup\$
    – MGOwen
    Commented Feb 20, 2019 at 0:34
  • 12
    \$\begingroup\$ When you said Download SHARK.COM!, I immediately thought of computer viruses. \$\endgroup\$
    – MilkyWay90
    Commented Feb 20, 2019 at 16:40
  • \$\begingroup\$ @gwaugh I was kidding \$\endgroup\$
    – MilkyWay90
    Commented Feb 20, 2019 at 16:46
  • \$\begingroup\$ @gwaugh But it's 109 bytes \$\endgroup\$
    – MilkyWay90
    Commented Feb 20, 2019 at 16:50
21
\$\begingroup\$

Python 2, 93 bytes

for w in"Baby Daddy Mommy Grandpa Grandma".split():w+=" Shark";print(w+" doo"*6+"\n")*3+w+"!"

Try it online!

94 bytes

for w in"Baby Daddy Mommy Grandpa Grandma".split():print((" doo"*6+"\n%s Shark"%w)*4)[25:]+"!"

Try it online!

\$\endgroup\$
20
\$\begingroup\$

05AB1E, 50 41 bytes

“‡ÍÊТ×myîºpaîºma“#ð«'㢫™v…doo6иyšÐy'!«»

Last part v4FN3Qiy'!«ë…doo6иyšðý}, can definitely be golfed a bit.. And I was right, -9 bytes thanks to @Emigna (even more than I was expecting).

Try it online.

Explanation:

“‡ÍÊТ×myîºpaîºma“ # Push dictionary string "baby daddy mommy grandpa grandma"
 #                 # Split by spaces: ["baby","daddy","mommy","grandpa","grandma"]
  ð«               # Append a space to each
    '㢫          '# Append dictionary string "shark" to each
        ™          # Title-case each word
v                  # Loop `y` over these strings
 …doo              #  Push string "doo"
     6и            #  Repeat it 6 times as list
       yš          #  Prepend the string `y` at the front of the list
         Ð         #  Triplicate this list
 y'!«             '#  Push string `y`, concatted with a "!"
 »                 #  Join everything on the stack by newlines
                   #  (and each list implicitly by spaces)
                   # (and after the loop, output the result implicitly)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why “‡ÍÊТ×myîºpaîºma“ is "baby daddy mommy grandpa grandma" and '㢠is "shark".

\$\endgroup\$
2
  • 2
    \$\begingroup\$ You can golf 9 bytes of that last bit with v…doo6иyšÐy'!«» \$\endgroup\$
    – Emigna
    Commented Feb 16, 2019 at 16:01
  • \$\begingroup\$ @Emigna You even golfed more than I was expected, thanks! Smart way of using the triplicate and »! \$\endgroup\$ Commented Feb 16, 2019 at 17:27
14
\$\begingroup\$

PowerShell, 88 86 85 80 79 76 bytes

-5 bytes thanks to @mazzy
-1 byte thanks to @Joey
-3 bytes thanks to @AdmBorkBork

echo Baby Daddy Mommy Grandpa Grandma|%{,(($a="$_ Shark")+" doo"*6)*3;"$a!"}

Try it online!

We've certainly come a long way.

PowerShell (with Text to Speech), 156 bytes

This is NOT up to spec, but it's kinda funny. Thanks to @rkeet for the idea!

Add-Type -a System.Speech;echo Baby Daddy Mommy Grandpa Grandma|%{(New-Object Speech.Synthesis.SpeechSynthesizer).Speak((($a="$_ Shark")+" doo"*6)*3+" $a")}

.NET Text to speech pronunciation is... well... interesting. Keep this in mind when listening. Enjoy!

\$\endgroup\$
5
  • 2
    \$\begingroup\$ 80 bytes :) \$\endgroup\$
    – mazzy
    Commented Feb 16, 2019 at 7:29
  • 1
    \$\begingroup\$ You can save another byte by assigning "$_ Shark" to a variable and re-using it. \$\endgroup\$
    – Joey
    Commented Feb 18, 2019 at 11:00
  • 2
    \$\begingroup\$ 76 bytes using echo instead of -split. \$\endgroup\$ Commented Feb 19, 2019 at 20:27
  • 1
    \$\begingroup\$ I think you should have a "text to speech" in there as well :p For the hell of it tried to combine it a bit with this code, didn't quite work :-) \$\endgroup\$
    – rkeet
    Commented Feb 20, 2019 at 9:04
  • \$\begingroup\$ @rkeet Challenge accepted! I am currently puzzling this out. \$\endgroup\$
    – GMills
    Commented Feb 20, 2019 at 14:34
13
\$\begingroup\$

SOGL, 40 bytes

o⅝ηvΒvPΝ┘÷ΖnΨ‘θ{"nOe;‘+ū:" doo”6*+TTPPļ!

Try it here!

\$\endgroup\$
12
\$\begingroup\$

Java (JDK), 135 bytes

v->{for(var s:"Baby Daddy Mommy Grandpa Grandma".split(" "))System.out.println(((s+=" Shark")+" doo".repeat(6)+"\n").repeat(3)+s+"!");}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Which JDK version? I'm guessing 8+ (lambdas). \$\endgroup\$ Commented Feb 17, 2019 at 19:46
  • 3
    \$\begingroup\$ @NoOneIsHere Given the repeat method, it's version 11+ \$\endgroup\$ Commented Feb 17, 2019 at 21:44
11
\$\begingroup\$

Haskell, 122 113 108 106 104 bytes

s=" Shark";m=do x<-words"Baby Daddy Mommy Grandpa Grandma";("aaa">>x++s++(s>>" doo")++"\n")++x++s++"!\n"

Try it online!

  • "aaa">>x replicates x 3 times, as "aaa" has length 3.

  • s>>" doo" replicates " doo" 6 times, as " Shark" has length 6!

  • 2 bytes saved thanks to @Fox

  • 2 bytes saved thanks to @Laikoni
\$\endgroup\$
6
  • 2
    \$\begingroup\$ Welcome to the site! We allow just generating a fixed output string as an expression, so you can omit the main=putStr. See also the Haskell rules summary. \$\endgroup\$
    – xnor
    Commented Feb 16, 2019 at 21:54
  • 1
    \$\begingroup\$ Welcome to PPCG. Nice saving with s>>. \$\endgroup\$
    – Shaggy
    Commented Feb 16, 2019 at 22:05
  • \$\begingroup\$ @xnor thanks for the links! \$\endgroup\$ Commented Feb 16, 2019 at 22:09
  • 1
    \$\begingroup\$ m=(stuff) can just be m=stuff for two fewer bytes \$\endgroup\$
    – Fox
    Commented Feb 17, 2019 at 21:42
  • 1
    \$\begingroup\$ 104 bytes by using do-notation: Try it online! \$\endgroup\$
    – Laikoni
    Commented Feb 18, 2019 at 7:55
10
\$\begingroup\$

Retina 0.8.2, 77 75 74 bytes


Baby¶Daddy¶MommyGpaGma
G
¶Grand
.+
$&s$&s$&s$&S!
s
S6$*O¶
O
 doo
S
 Shark

Try it online! Explanation:


Baby¶Daddy¶MommyGpaGma
G
¶Grand

Insert the relations on separate lines.

.+
$&s$&s$&s$&S!¶

Expand into four lines.

s
S6$*O¶
O
 doo
S
 Shark

Expand the placeholders.

69 68 bytes in Retina 1:


Baby¶Daddy¶MommyGpaGma
G
¶Grand
.+
$& Shark
.+
3*$($&6*$( doo)¶)$&!

Try it online! Explanation:


Baby¶Daddy¶MommyGpaGma
G
¶Grand

Insert the relations on separate lines.

.+
$& Shark

Append Shark to each.

.+
3*$($&6*$( doo)¶)$&!

Expand into whole verses.

\$\endgroup\$
9
\$\begingroup\$

Python 3, 105 97 96 bytes

for x in"Baby","Daddy","Mommy","Grandpa","Grandma":z=x+' Shark';print((z+' doo'*6+"\n")*3+z+"!")

Try it online!

A simple Python 3 solution. (9 bytes saved by Jo King and Quintec)

\$\endgroup\$
8
  • 2
    \$\begingroup\$ The parentheses around ' doo'*6 are unnecessary and you have unnecessary whitespace there \$\endgroup\$
    – Quintec
    Commented Feb 16, 2019 at 2:06
  • 1
    \$\begingroup\$ What quintec said... 97 bytes \$\endgroup\$
    – Jo King
    Commented Feb 16, 2019 at 2:07
  • 2
    \$\begingroup\$ @ReverseCold technically where there's no [] it's a tuple not a list, but that's not relevant to this program \$\endgroup\$
    – Stephen
    Commented Feb 16, 2019 at 2:58
  • 2
    \$\begingroup\$ 96 bytes by setting x+' Shark' to a variable \$\endgroup\$
    – Jo King
    Commented Feb 16, 2019 at 8:07
  • 1
    \$\begingroup\$ This seems to work in 2.7 as well? \$\endgroup\$
    – uhoh
    Commented Feb 19, 2019 at 1:54
9
\$\begingroup\$

bash, 78 bytes

printf %s\\n {Baby,Daddy,Mommy,Grand{p,m}a}\ Shark{" `echo doo{,,}{,}`"{,,},!}

TIO

73 bytes if trailing space is allowed

echo '
'{Baby,Daddy,Mommy,Grand{p,m}a}\ Shark{" `echo doo{,,}{,}`"{,,},!}
\$\endgroup\$
7
\$\begingroup\$

Perl 6, 79 78 bytes

(<Baby Daddy Mommmy Grandpa Grandma>X~" Shark"X~ |((" doo"x 6)xx 3),'!')>>.say

Try it online!

Pretty simple.

Explanation:

 <...>X~                                  # Combine family members
        " Shark"X~                        # With "Shark" and
                   |((" doo"x 6)xx 3)     # doo repeated 6 times then 3 times
                                     ,'!' # Then !
(                                        )>>.say  # And print each line
\$\endgroup\$
7
\$\begingroup\$

Ruby, 82 bytes

%w(Baby Daddy Mommy Grandpa Grandma).map{|a|puts [a+" Shark"]*4*(" doo"*6+?\n)+?!}

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ It took me a while to understand that you used the "doo" part as array seperators. Good job :) \$\endgroup\$
    – Idva
    Commented Feb 18, 2019 at 13:11
  • \$\begingroup\$ ?\n can be replaced with $/. \$\endgroup\$
    – Value Ink
    Commented Nov 20, 2019 at 21:27
6
\$\begingroup\$

///, 124 bytes

/*/$!
//)/Grand//(/Baby//'/Mommy//&/Daddy//%/ doo//$/ Shark//#/a")//"/$%%%%%%
/("("("(*&"&"&"&*'"'"'"'*)p#p#p#pa*)m#m#m#ma$!

Try it online!

\$\endgroup\$
6
\$\begingroup\$

JavaScript, 104 bytes

More golfing to follow.

_=>`Baby
Daddy
Mommy
Grandpa
Grandma`.replace(/.+/g,x=>(s=(x+=` Shark`)+` doo`.repeat(6)+`
`)+s+s+x+`!`)

Try It Online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This technically isn't a valid solution since it neither writes to a file or logs it. Though if you make it a valid solution by wrapping with a console.log(), you can make it not a lambda declaration (only 10 character gain) \$\endgroup\$
    – Delioth
    Commented Feb 18, 2019 at 21:13
  • 3
    \$\begingroup\$ @Delioth, returning from a function is perfectly valid on this site. Have a look on Meta for our default I/O rules. \$\endgroup\$
    – Shaggy
    Commented Feb 18, 2019 at 21:43
  • 2
    \$\begingroup\$ I would generally agree, but this question specifically states that the program "writes the following text to the standard output or an arbitrary file" \$\endgroup\$
    – Delioth
    Commented Feb 18, 2019 at 21:51
6
\$\begingroup\$

PostgreSQL, 162 156 138 bytes

select a||' Shark'||replace(b,'1',repeat(' doo',6))from unnest('{Baby,Daddy,Mommy,Grandpa,Grandma}'::text[])a,unnest('{1,1,1,!}'::text[])b

Ungolfed

select 
    a || ' Shark' || replace(b,'1',repeat(' doo',6))
from unnest('{Baby,Daddy,Mommy,Grandpa,Grandma}'::text[]) a
    ,unnest('{1,1,1,!}'::text[]) b

Saved 6 24 bytes thanks to @Nahuel Fouilleul!

  • use || instead of concat()
  • use unnest('{foo,bar}'::text[]) instead of regexp_split_to_table('foo,bar')

DB<>fiddle

\$\endgroup\$
2
  • 2
    \$\begingroup\$ -6 bytes using ||instead of concat View on DB Fiddle \$\endgroup\$ Commented Feb 18, 2019 at 9:22
  • 2
    \$\begingroup\$ select a||' Shark'||replace(b,'1',repeat(' doo',6))from unnest('{Baby,Daddy,Mommy,Grandpa,Grandma}'::text[])a,unnest('{1,1,1,!}'::text[])b \$\endgroup\$ Commented Feb 18, 2019 at 9:48
6
\$\begingroup\$

Emotion, 65 bytes

😇😃😟🥕😤😦😇😅🧖💥😛🥒🥥🧖😨🤕😇😁💟😫😳🤠😇😆💟😫😳🌽🍌😘😁🚵😙🚵💥😘😁🧟👍🧟💥🚣❤🤣🏃😢🤯😒😁😵😔😧🧐🤠😇😅🧖💥😛🥒🥥🧗😧🧐🤠

Explanation

😇😃😟🥕 Push literal doo
😤 Push five copies of the first stack value.
😦 Collapse all stack values into a string seperated by spaces, then push that string.
😇😅🧖💥😛🥒🥥🧖 Push literal  Shark 
😨 Push the difference of the second and first stack values.
🤕 Store the first stack value in the a register.
😇😁💟😫😳🤠 Push literal Grandma
😇😆💟😫😳🌽🍌 Push literal Grandpa
😘😁🚵😙🚵💥 Push literal Mommy
😘😁🧟👍🧟💥 Push literal Daddy
🚣❤ Push literal Baby
🤣 Push literal 6
🏃😢 Push stack values into a list of the size of the first stack value starting with the second stack value.
🤯 Enter an iteration block over the first stack value and push the iteration element register at the begining of each loop.
😒 Push three copies of the first stack value.
😁 Push literal 3
😵 Enter an iteration block over the first stack value.
😔 Push the value contained in the a register.
😧 Push the sum of the second and first stack values.
🧐 Print the first stack value, then a newline.
🤠 Ends a control flow structure.
😇😅🧖💥😛🥒🥥🧗 Push literal  Shark!
😧 Push the sum of the second and first stack values.
🧐 Print the first stack value, then a newline.
🤠 Ends a control flow structure.

Try it online!

\$\endgroup\$
5
\$\begingroup\$

><>, 158 115 bytes

Saved a lot of bytes thanks to Jo King

>4>1-&0'krahS '0l3-.
~ ^oa~<
ooo:?!/1-'ood 'o
\ao'!'^?$6:&~
\!?:o
^'ybaB'
^'yddaD'
^'ymmoM'
^'apdnarG'
^'amdnarG'
;

Try it online! You may also want to paste the code in at fishlanguage.com, where you can see an animation of it swimming running.

\$\endgroup\$
3
  • \$\begingroup\$ 121 bytes, mostly through rearranging the baby/daddy/... to multiple lines instead of one line. There's more to golf though \$\endgroup\$
    – Jo King
    Commented Feb 16, 2019 at 8:58
  • \$\begingroup\$ 115 bytes \$\endgroup\$
    – Jo King
    Commented Feb 16, 2019 at 9:24
  • \$\begingroup\$ @JoKing Ah, thanks. I tend to assume (mostly from working with BitCycle) that fewer lines are better, but in this case that's not true because of the different string lengths. \$\endgroup\$
    – DLosc
    Commented Feb 16, 2019 at 21:27
5
\$\begingroup\$

Haskell, 97 bytes

unlines[x++s++p|x<-words"Baby Daddy Mommy Grandpa Grandma",p<-[a,a,a,"!"]]
s=" Shark"
a=s>>" doo"

Try it online!

This is an optimization of the Haskell solution by starsandspirals. The new trick is to iterate over the rows of each stanza with an inner loop, and join the lines using unlines, saving the need to explicitly insert newlines.

The suffixes of the four lines are [a,a,a,"!"], where a is " doo" replicated 6 times with a=s>>" doo", where starsandspirals cleverly reuses the six-character-long s=" Shark". Writing [a,a,a,...] looks a bit silly, but I'm not seeing a shorter way.

A list-monad version is the same length but it looks cool.

unlines$(++).(++s)<$>words"Baby Daddy Mommy Grandpa Grandma"<*>[a,a,a,"!"]
s=" Shark"
a=s>>" doo"

Try it online!

\$\endgroup\$
4
\$\begingroup\$

C# (Visual C# Interactive Compiler), 153 131 bytes

foreach(var i in"Baby Daddy Mommy Grandpa Grandma".Split()){var a=i+" Shark doo doo doo doo doo doo\n";Write(a+a+a+i+" Shark!\n");}

Thanks to @Destrogio for saving 30 bytes!

Try it online!

\$\endgroup\$
1
4
\$\begingroup\$

whenyouaccidentallylose100endorsementsinnationstates - 123,065 121,716 113,695 100,889 98,554 bytes

The program

I'll golf this later. Done.

I'll golf this more (later) Done.

I'll golf this even more later. DONE.

I'll get the byte count to 5 digits later. YAY.

I'll get the byte count to 4 digits (I don't know if this is possible, but I do know it is impossible to get 3 digits with my current approach).

\$\endgroup\$
3
  • \$\begingroup\$ What the hell is this? I love it \$\endgroup\$
    – adrian
    Commented Feb 19, 2019 at 1:21
  • \$\begingroup\$ @AdrianZhang A programming language hard to program it. Also, the program looks like it's a person screaming ('AAAAAAAAAAA...') \$\endgroup\$
    – MilkyWay90
    Commented Feb 19, 2019 at 1:47
  • \$\begingroup\$ Both links are dead. \$\endgroup\$
    – Oskar Skog
    Commented May 22, 2023 at 3:11
4
\$\begingroup\$

R, 131 122 120 bytes

-9 bytes thanks to Giuseppe

-2 more bytes, also Giuseppe

`?`=c
s="Shark"
for(x in "Baby"?"Daddy"?"Mommy"?"Grandpa"?"Grandma")cat(rep("
"?x?s?rep("doo",6),3)?"
"?x?paste0(s,"!"))

Try it online!

Quite proud of this actually, especially with R being rather poor at handling strings. I started out using cat(sapply(...)), but realized a for loop shaves off a few bytes.

Abusing the "?"=c significantly reduced the amount of parentheses needed.

I also tried to do "*"=rep to repeat the individual lines of the stanzas and the "doos", but that did not shave off any bytes.

111 bytes

Giuseppe and ASCII-only's alternative, (and better) solution that fixes some spacing issues.

write(paste0(rep(c("Baby","Daddy","Mommy","Grandpa","Grandma"),,,4)," Shark",c(rep(strrep(" doo",6),3),"!")),1)

Try it online!

\$\endgroup\$
10
  • 1
    \$\begingroup\$ 122 bytes \$\endgroup\$
    – Giuseppe
    Commented Feb 19, 2019 at 16:06
  • \$\begingroup\$ As always, thank you for your wise input @Giuseppe. I should have noticed those golfs \$\endgroup\$
    – Sumner18
    Commented Feb 19, 2019 at 17:59
  • 1
    \$\begingroup\$ 120 bytes \$\endgroup\$
    – Giuseppe
    Commented Feb 19, 2019 at 19:08
  • 1
    \$\begingroup\$ @Giuseppe wow, vectorization, nice. I forgot R has nice vectorization like this. 114? also 114? \$\endgroup\$
    – ASCII-only
    Commented Feb 21, 2019 at 22:49
  • 1
    \$\begingroup\$ also 114 \$\endgroup\$
    – ASCII-only
    Commented Feb 21, 2019 at 22:55
3
\$\begingroup\$

PHP, 104 bytes

foreach([Baby,Daddy,Mommy,Grandpa,Grandma]as$s)echo$t=$s.str_pad($u=" Shark",30," doo"),"
$t
$t
$s$u!
";

Run with php -nr '<code>' or try it online.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 103 bytes \$\endgroup\$
    – Night2
    Commented Sep 2, 2019 at 11:37
3
\$\begingroup\$

R, 126 125 bytes

cat(paste(rep(c("Baby","Daddy","Mommy","Grandpa","Grandma"),,,4),c(rep("Shark doo doo doo doo doo doo",3),"Shark!")),sep="
")

This doesn't feel as 'clever' as either CT Hall or Sumner18's answers, but by avoiding the overhead of defining variables it comes out smaller.

Try it online!

Edit: Saved 1 byte by using carriage return as per comment by Jonathan Frech

\$\endgroup\$
6
  • \$\begingroup\$ Hello and welcome to PPCG! I have added links to the user's answers you mentioned to better compare your solutions. Congratulations on outgolfing both, could you add a link to an online testing environment for ease of verification? \$\endgroup\$ Commented Feb 19, 2019 at 13:13
  • \$\begingroup\$ Thanks for the edit @JonathanFrech. I have now added a link to test the code online (which added a byte to my answer!). \$\endgroup\$
    – BobbyBean
    Commented Feb 19, 2019 at 14:07
  • \$\begingroup\$ You can use an actual new line instead of \n to bring your byte count one back down again. \$\endgroup\$ Commented Feb 19, 2019 at 14:10
  • \$\begingroup\$ 125 bytes \$\endgroup\$
    – Giuseppe
    Commented Feb 19, 2019 at 16:10
  • 1
    \$\begingroup\$ Well I've been totally outgolfed; sometimes the simplest option is best. Also highlights how difficult it is to work with strings in R. \$\endgroup\$
    – Chthonyx
    Commented Feb 19, 2019 at 17:41
3
\$\begingroup\$

R, 139 138 137 bytes

s='Shark';d='doo';cat(paste(rep(c('Baby','Daddy','Mommy','Grandpa','Grandma'),e=4),c(rep(paste(s,d,d,d,d,d,d),3),paste0(s,'!'))),sep='
')

There's probably a better way to do the 'doo's but I wasn't able to get it.

Edit:
Replaced '\n' with actual new line at JDL's suggestion;
Removed trailing newline at Giuseppe's suggestion.

Try it online

\$\endgroup\$
3
  • \$\begingroup\$ welcome to ppcg! At the very least, replacing the "\n" with a literal newline will save one byte. \$\endgroup\$
    – JDL
    Commented Feb 19, 2019 at 13:34
  • \$\begingroup\$ Thanks, I did so, and then realized my output was bit off so I updated that, sadly it resulted in more bytes. \$\endgroup\$
    – Chthonyx
    Commented Feb 19, 2019 at 15:50
  • \$\begingroup\$ I believe you have a trailing newline for an extra byte \$\endgroup\$
    – Giuseppe
    Commented Feb 19, 2019 at 16:08
3
\$\begingroup\$

Plain TeX, 147 Bytes

\input pgffor\def\D{doo~}\def\d{\D\D\D\D\D\D}\def\S{Shark}\def\y{\x~\S~\d\par}\foreach\x in{Baby,Mommy,Daddy,Grandma,Grandpa}{\y\y\y\x~\S!\par}\bye

Rather disappointing, but I haven't posted a TeX answer in ages. Loops are very verbose in teX (and looping over strings isn't even built-in so even this is a bit of a stretch)

\$\endgroup\$
3
\$\begingroup\$

C (gcc), 123 122 bytes

-1 byte thanks to ceilingcat

#define A" doo doo"
f(i){for(i=20;i--;)printf("%.7s Shark%s\n","GrandmaGrandpaMommy\0 Daddy\0 Baby"+i/4*7,i%4?A A A:"!");}

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ What are the rules for C? No need for main(), or #include for printf? \$\endgroup\$
    – BoBTFish
    Commented Feb 21, 2019 at 8:19
  • \$\begingroup\$ @BoBTFish: Not C-specific but generally it is allowed to use any function (name doesn't matter, indeed it can be an unnamed lambda or similar). And languages are defined by their (any) implementation, since this works on gcc (only generates warnings, but compiles fine) it is valid. \$\endgroup\$ Commented Feb 22, 2019 at 14:27
  • \$\begingroup\$ I realised the lack of #include was only an error because I was still compiling as C++, but I still couldn't get it to compile without renaming your function to main. \$\endgroup\$
    – BoBTFish
    Commented Feb 22, 2019 at 15:30
3
\$\begingroup\$

Jelly, 42 bytes

“¡N³»ẋ6Wẋ3;”!ṭ€;Y
“¡ʂɓṙṢ®ÑR+£ṭỤṙ»Ḳ瀓¤⁾ċ»Y

Try it online!

How?

“¡N³»ẋ6Wẋ3;”!ṭ€;Y - Link 1: make a verse: familyMember; space+animalName
                  -                        e.g. "Baby"; " Shark"
“¡N³»             - dictionary word " doo"
     ẋ6           - repeat 6 times -> " doo doo doo doo doo doo"
       W          - wrap in a list -> [" doo d..."]
        ẋ3        - repeat 3 times -> [" doo d..."," doo d..."," doo d..."]
           ”!     - literal '!' character
          ;       - concatenate    -> [" doo d..."," doo d..."," doo d...","!"]
               ;  - concatenate inputs ["Baby Shark"]
             ṭ€   - tack for €ach  -> [["Baby Shark"," doo d..."],...,["Baby Shark","!"]]
                Y - join with newline characters
 
“¡ʂɓṙṢ®ÑR+£ṭỤṙ»Ḳ瀓¤⁾ċ»Y - Main Link: no arguments
“¡ʂɓṙṢ®ÑR+£ṭỤṙ»          - dictionary words "Baby"+" Daddy"+" Mommy"+" Grandpa"+" Grandma"
               Ḳ         - split at spaces -> ["Baby","Daddy","Mommy","Grandpa","Grandma"]
                  “¤⁾ċ»  - dictionary word " Shark"
                ç€       - call last Link (1) as a dyad for €ach
                       Y - join with newline characters
                         - implicit print
\$\endgroup\$
3
\$\begingroup\$

05AB1E, 39 38 bytes

”‡ÍÊТ×myîºpaîºma”#„o€·À6×3и'!ª”㢔ìâ»

Try it online!

”‡ÍÊТ×myîºpaîºma”                # compressed string "Baby Daddy Mommy Grandpa Grandma"
                  #               # split on spaces
„o€·                              # dictionary string "o do"
    À                             # rotated left: " doo"
     6×                           # string-repeat 6 times: " doo doo doo doo doo doo"
       3и                         # list-repeat 3 times
         '!ª                      # append "!" to that list
            ”ã¢”ì                 # prepend "Shark" to each element of that list
â                                 # cartesian product
 »                                # join by newlines
                                  # implicit output
\$\endgroup\$
3
+100
\$\begingroup\$

APL (Dyalog Unicode), 72 bytes (SBCS)

↑,(,∘' Shark'¨'BabyDaddyMommyGrandpaGrandma'(∊⊂⊣)⎕A)∘.,'!',⍨3⍴⊂24⍴' doo'

Try it online!

Explanation:

↑,(,∘' ..'¨'...'(∊⊂⊣)⎕A)∘.,'!',⍨3⍴⊂24⍴' doo'
                                   24⍴' doo'⍝ repeat 'doo' 6 times
                                  ⊂         ⍝ box the 'doo's
                                3⍴          ⍝ make three copies
                           '!',⍨            ⍝ append a `!` at the end
           '...'(∊⊂⊣)⎕A                     ⍝ split the long string on capitals
   ,∘' ..'¨                                 ⍝ append to all family members
                        ∘.,                 ⍝ construct a table where each row is
                                            ⍝ a full verse of the song
↑,                                          ⍝ flatten the resulting verse table

-28 thanks to @Adám

-2 bytes (-14 before; but I did a few golfs before checking the golfed version) thanks to @Razetime

\$\endgroup\$
3
  • \$\begingroup\$ -14 \$\endgroup\$
    – Razetime
    Commented Dec 13, 2020 at 15:27
  • \$\begingroup\$ -28 \$\endgroup\$
    – Adám
    Commented Dec 13, 2020 at 16:58
  • \$\begingroup\$ @Adám that's a whole lot smaller, I'll analyze that in a short while. Thanks. \$\endgroup\$ Commented Dec 13, 2020 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.