70
\$\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\$
  • 6
    \$\begingroup\$ Is a newline between each stanza (each shark) acceptable? (That's always how I've seen the lyrics written) \$\endgroup\$ – Quintec Feb 16 at 2:00
  • 6
    \$\begingroup\$ Eh, missing a few verses, like all the ones about the swimmers swimming and losing limbs in shark attacks. \$\endgroup\$ – mbomb007 Feb 16 at 17:23
  • 2
    \$\begingroup\$ "doo doo doo doo doo doo" is really over-simplified. \$\endgroup\$ – R.. Feb 17 at 23:54
  • 27
    \$\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 Feb 18 at 17:22
  • 5
    \$\begingroup\$ How many people's days ruined now that this is on HNQs? \$\endgroup\$ – CactusCake Feb 18 at 19:49

60 Answers 60

8
\$\begingroup\$

SOGL, 40 bytes

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

Try it here!

\$\endgroup\$
73
\$\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\$
  • 31
    \$\begingroup\$ Points for creativity, but this doesn't produce the required output \$\endgroup\$ – Jo King Feb 17 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 Feb 17 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\$ – Mego Feb 17 at 20:17
  • 8
    \$\begingroup\$ Please either modify this answer to produce the correct output, or delete it. \$\endgroup\$ – mbomb007 Feb 18 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 Feb 19 at 18:28
32
\$\begingroup\$

IBM PC DOS, 8088 assembly, 115 114 109 108 bytes

bd43 01e8 1600 bd48 01e8 1000 bd4e 01e8 0a00 bd54 01e8 0400 c646 056d b409 b103
8bd5 cd21 ba5c 01cd 21e3 1249 b306 ba63 01cd 214b 75fb ba69 01cd 21eb e3ba 6801
cd21 c342 6162 7924 4461 6464 7924 4d6f 6d6d 7924 4772 616e 6470 6124 2053 6861
726b 2420 646f 6f24 210d 0a24

Unassembled:

    MOV  BP, OFFSET BABY        ; Baby Shark
    CALL VERSE
    MOV  BP, OFFSET DADDY       ; Daddy Shark
    CALL VERSE
    MOV  BP, OFFSET MOMMY       ; Mommy Shark
    CALL VERSE
    MOV  BP, OFFSET GRAND       ; Grandpa/ma Shark
    CALL VERSE
    MOV  BYTE PTR [BP+5], 'm'   ; change 'p' to 'm'                 
                                ; fall through for last VERSE                               

; display a shark verse
; input: BP: address of shark name string
; output: display full verse for shark
VERSE   PROC
        MOV  AH, 9              ; DOS API display string function
        MOV  CL, 3              ; loop verse three times
LOOP_VERSE:
        MOV  DX, BP             ; load shark name from BP
        INT  21H                ; display shark name
        MOV  DX, OFFSET SHARK   ; load 'Shark'
        INT  21H                ; display 'Shark'
        JCXZ LAST_VERSE         ; if last verse, skip to !
        DEC  CX                 ; decrement verse count
        MOV  BL, 6              ; loop 'doo' 6 times
        MOV  DX, OFFSET DOO     ; load 'doo' string
LOOP_DOO:
        INT  21H                ; display 'doo'
        DEC  BX                 ; decrement doo count
        JNZ  LOOP_DOO           ; if not zero, start again
        MOV  DX, OFFSET CRLF    ; load CRLF string
        INT  21H                ; display CRLF
        JMP  LOOP_VERSE
LAST_VERSE:
        MOV  DX, OFFSET BANG    ; display !, CRLF
        INT  21H
        RET
VERSE   ENDP

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,'$'

Output

DOS DIR, SHARK

Download SHARK.COM!

  • -5 bytes thanks to @Deadcode
\$\endgroup\$
  • 6
    \$\begingroup\$ You absolute madman. \$\endgroup\$ – MGOwen Feb 20 at 0:34
  • 6
    \$\begingroup\$ When you said Download SHARK.COM!, I immediately thought of computer viruses. \$\endgroup\$ – MilkyWay90 Feb 20 at 16:40
  • \$\begingroup\$ @gwaugh I was kidding \$\endgroup\$ – MilkyWay90 Feb 20 at 16:46
  • \$\begingroup\$ @gwaugh But it's 109 bytes \$\endgroup\$ – MilkyWay90 Feb 20 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\$
17
\$\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
    \$\begingroup\$ You can golf 9 bytes of that last bit with v…doo6иyšÐy'!«» \$\endgroup\$ – Emigna Feb 16 at 16:01
  • \$\begingroup\$ @Emigna You even golfed more than I was expected, thanks! Smart way of using the triplicate and »! \$\endgroup\$ – Kevin Cruijssen Feb 16 at 17:27
15
\$\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\$
  • 2
    \$\begingroup\$ 80 bytes :) \$\endgroup\$ – mazzy Feb 16 at 7:29
  • 1
    \$\begingroup\$ You can save another byte by assigning "$_ Shark" to a variable and re-using it. \$\endgroup\$ – Joey Feb 18 at 11:00
  • 2
    \$\begingroup\$ 76 bytes using echo instead of -split. \$\endgroup\$ – AdmBorkBork Feb 19 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 Feb 20 at 9:04
  • \$\begingroup\$ @rkeet Challenge accepted! I am currently puzzling this out. \$\endgroup\$ – Gabriel Mills Feb 20 at 14:34
10
\$\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\$
  • \$\begingroup\$ Which JDK version? I'm guessing 8+ (lambdas). \$\endgroup\$ – NoOneIsHere Feb 17 at 19:46
  • 3
    \$\begingroup\$ @NoOneIsHere Given the repeat method, it's version 11+ \$\endgroup\$ – Olivier Grégoire Feb 17 at 21:44
9
\$\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\$
  • 2
    \$\begingroup\$ The parentheses around ' doo'*6 are unnecessary and you have unnecessary whitespace there \$\endgroup\$ – Quintec Feb 16 at 2:06
  • 1
    \$\begingroup\$ What quintec said... 97 bytes \$\endgroup\$ – Jo King Feb 16 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 Feb 16 at 2:58
  • 2
    \$\begingroup\$ 96 bytes by setting x+' Shark' to a variable \$\endgroup\$ – Jo King Feb 16 at 8:07
  • 1
    \$\begingroup\$ This seems to work in 2.7 as well? \$\endgroup\$ – uhoh Feb 19 at 1:54
9
\$\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\$
  • 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 Feb 16 at 21:54
  • 1
    \$\begingroup\$ Welcome to PPCG. Nice saving with s>>. \$\endgroup\$ – Shaggy Feb 16 at 22:05
  • \$\begingroup\$ @xnor thanks for the links! \$\endgroup\$ – starsandspirals Feb 16 at 22:09
  • 1
    \$\begingroup\$ m=(stuff) can just be m=stuff for two fewer bytes \$\endgroup\$ – Fox Feb 17 at 21:42
  • 1
    \$\begingroup\$ 104 bytes by using do-notation: Try it online! \$\endgroup\$ – Laikoni Feb 18 at 7:55
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\$

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\$
  • 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 Feb 18 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 Feb 18 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 Feb 18 at 21:51
7
\$\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\$
6
\$\begingroup\$

///, 124 bytes

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

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\$
  • \$\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 Feb 16 at 8:58
  • \$\begingroup\$ 115 bytes \$\endgroup\$ – Jo King Feb 16 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 Feb 16 at 21:27
5
\$\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\$
  • 1
    \$\begingroup\$ -6 bytes using ||instead of concat View on DB Fiddle \$\endgroup\$ – Nahuel Fouilleul Feb 18 at 9:22
  • 1
    \$\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\$ – Nahuel Fouilleul Feb 18 at 9:48
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\$

Ruby, 82 bytes

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

Try it online!

\$\endgroup\$
  • \$\begingroup\$ It took me a while to understand that you used the "doo" part as array seperators. Good job :) \$\endgroup\$ – Idva Feb 18 at 13: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\$
  • 1
    \$\begingroup\$ 122 bytes \$\endgroup\$ – Giuseppe Feb 19 at 16:06
  • \$\begingroup\$ As always, thank you for your wise input @Giuseppe. I should have noticed those golfs \$\endgroup\$ – Sumner18 Feb 19 at 17:59
  • 1
    \$\begingroup\$ 120 bytes \$\endgroup\$ – Giuseppe Feb 19 at 19:08
  • 1
    \$\begingroup\$ @Giuseppe wow, vectorization, nice. I forgot R has nice vectorization like this. 114? also 114? \$\endgroup\$ – ASCII-only Feb 21 at 22:49
  • 1
    \$\begingroup\$ also 114 \$\endgroup\$ – ASCII-only Feb 21 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\$
3
\$\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\$
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\$
  • \$\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\$ – Jonathan Frech Feb 19 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 Feb 19 at 14:07
  • \$\begingroup\$ You can use an actual new line instead of \n to bring your byte count one back down again. \$\endgroup\$ – Jonathan Frech Feb 19 at 14:10
  • \$\begingroup\$ 125 bytes \$\endgroup\$ – Giuseppe Feb 19 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\$ – CT Hall Feb 19 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\$
  • \$\begingroup\$ welcome to ppcg! At the very least, replacing the "\n" with a literal newline will save one byte. \$\endgroup\$ – JDL Feb 19 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\$ – CT Hall Feb 19 at 15:50
  • \$\begingroup\$ I believe you have a trailing newline for an extra byte \$\endgroup\$ – Giuseppe Feb 19 at 16:08
3
\$\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\$
  • \$\begingroup\$ What the hell is this? I love it \$\endgroup\$ – Adrian Zhang Feb 19 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 Feb 19 at 1:47
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\$
  • \$\begingroup\$ What are the rules for C? No need for main(), or #include for printf? \$\endgroup\$ – BoBTFish Feb 21 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\$ – ბიმო Feb 22 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 Feb 22 at 15:30
2
\$\begingroup\$

cQuents, 93 89 bytes

|
#20&bk)~" Shark"~(" doo"6,Z,Z,bk)~" Shark!"
:"Baby","Daddy","Mommy","Grandpa","Grandma"

Try it online!

Note that as of posting TIO is not updated to the latest version, so the TIO link may not work.

Explanation

|                               Set delimiter to newline
#20                             n = 20
   &                            Output first n terms in sequence
                                k = 1
                                First term is
    bk)~" Shark"                 kth term from the third line concatenated to " Shark"
                ~(" doo"6,        concatenated to " doo" repeated 6 times
Z,Z,                            Second and third terms equal the first term
    bk)~" Shark!"               Fourth term is the kth term from the third line concatenated to " Shark!"
                                k += 1, restart

Third line                      5 terms, each a string
\$\endgroup\$
2
\$\begingroup\$

JavaScript (Node.js), 132 bytes

Probably very golf-able. Generates the "doo doo" line, then creates three of those with the "!" line after, and repeats this for each shark.

a=""
c=" doo"
for(b of["Baby","Daddy","Mommy","Grandpa","Grandma"]){b+=" Shark"
t=b+c+c+c+c+c+c+"\n"
a+=t+t+t+b+"!\n"}console.log(a)

Try it online!

\$\endgroup\$
  • \$\begingroup\$ A slightly changed solution in Javascript, no gain though: a="";c=" doo";for(b of["Baby","Daddy","Mommy","Grandpa","Grandma"]){b+=" Shark";t=b+c.repeat(6)+"\n";a+=t+t+t+b+"!\n"}console.log(a) \$\endgroup\$ – BogdanBiv Feb 19 at 8:52
2
\$\begingroup\$

jq, 87 characters

" Shark"as$s|("Baby Daddy Mommy Grandpa Grandma"/" ")[]|(.+$s+" doo"*6+"\n")*3+.+$s+"!"

Sample run:

bash-4.4$ jq -nr '" Shark"as$s|("Baby Daddy Mommy Grandpa Grandma"/" ")[]|(.+$s+" doo"*6+"\n")*3+.+$s+"!"'
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!

Try it online!

\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

PHP, 153 147 bytes

<?php $s='Shark';$d=str_pad('',23,'doo ');foreach(explode(' ','Baby Daddy Mommy Grandpa Grandma')as$a){echo str_repeat("$a $s $d\n",3),"$a $s!\n";}

Thanks to @manatwork for saving 6 bytes by pointing out str_pad('',23'doo '); is shorter than rtrim(str_repeat('doo ',6));

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Unfortunately even $d='doo doo doo doo doo doo' is shorter than that rtrim()+str_repeat() combination. :( But fortunately $d=str_pad('',23,'doo ') is even shorter. For more optimization tips, see Tips for golfing in PHP. \$\endgroup\$ – manatwork Feb 18 at 15:33
  • \$\begingroup\$ @manatwork Thanks for pointing that out, I've updated the post to reflect \$\endgroup\$ – EvanBarbour3 Feb 18 at 16:17
  • 1
    \$\begingroup\$ In meantime found some time to play a bit more: Try it online! \$\endgroup\$ – manatwork Feb 18 at 16:44
  • \$\begingroup\$ 113 bytes. Welcome to PPCG! \$\endgroup\$ – Shaggy Feb 18 at 23:44
  • 2
    \$\begingroup\$ 109 bytes \$\endgroup\$ – Shaggy Feb 18 at 23:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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