64
\$\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
  • 25
    \$\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

55 Answers 55

2
\$\begingroup\$

Javascript, 125 123 bytes

['Baby','Daddy','Mommy','Grandpa','Grandma'].flatMap(x=>[...[,,,].fill(' doo'.repeat(6)),'!'].map(y=>x+' Shark'+y)).join`
`

Try it online!

\$\endgroup\$
2
\$\begingroup\$

JavaScript (134 126 bytes)

-2 bytes thanks to Stephen! -6 bytes thanks to mgthomas99!

["Baby","Daddy","Mommy","Grandma","Grandpa"].forEach(a=>console.log((a+" shark"+" doo".repeat(6)+"\n").repeat(3)+a+" Shark!"))

JS Fiddle

\$\endgroup\$
  • \$\begingroup\$ Can save two bytes: a + " -> a+" \$\endgroup\$ – Stephen Feb 18 at 16:36
  • \$\begingroup\$ Wow I was working on a JS solution and barely managed to get to 170 bytes. Your use of repeat is genius! \$\endgroup\$ – Matthew Ludwig Feb 18 at 22:51
  • 1
    \$\begingroup\$ You can save 2 bytes by removing the parentheses around the arrow function parameters (so that (a)=> becomes a=>). You can save another 2 bytes by removing the braces around the arrow function body. I'm also not certain you need the explicit newline at the end of the console.log statement, and removing that should save you another 2 bytes. \$\endgroup\$ – mgthomas99 Feb 19 at 9:53
  • \$\begingroup\$ The first shark should be capitalised \$\endgroup\$ – Jo King Mar 22 at 5:26
1
\$\begingroup\$

Attache, 79 bytes

$Baby'$Daddy'$Mommy'$Grandpa'$Grandma+" Shark":>Print@{(_+" doo"*6+lf)*3+_+"!"}

Try it online!

An attempt at compressing the above iteration array is NTS@N=>Split[S@FromBase[Ords@")!-ZOW]NE.kK3(*F(a3\\z6fXD_\\yEM"-32,95],"00"], which is significantly longer than the trivial encoding above. Compressing the string using base conversion in its entirety would likely come out to be longer.

Alternatives

81 bytes: Print@{(_+" doo"*6+lf)*3+_+"!"}=>($Baby'$Daddy'$Mommy'$Grandpa'$Grandma+" Shark")

82 bytes: Output!{(_+" doo"*6+lf)*3+_+"!"}=>($Baby'$Daddy'$Mommy'$Grandpa'$Grandma+" Shark")

86 bytes: Output!(""'3&(" doo"*6+lf)'"!")&Join=>($Baby'$Daddy'$Mommy'$Grandpa'$Grandma+" Shark")

87 bytes: Output!(""'3&(" doo"*6+lf)'"!")&Join@`+&" Shark"=>$Baby'$Daddy'$Mommy'$Grandpa'$Grandma

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

Japt -R, 55 bytes

Pretty naïve first pass.

`baß'adÝcomæ²T\`èT\`µ`qi Ë'!i4Æ` Srk`iDhDÎuÃqRi6ç` ºo

Test it

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

J, 85 bytes

echo('Shark'(,&'!',~(24$' doo')(3#,:)@,~])@,~]);.2'Baby Daddy Mommy Grandpa Grandma '

Try it online!

Note: This assumes a blank line between stanzas is ok. If that's not the case, prepending ,/ to my solution for +2 bytes.

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

Stax, 43 bytes

ÇÉ╕µM%╠2'§t╪╝½ôòn=n╢/╬╦Φ▲Vêø■T⌂g^N┴W.ìC↕ƒ·Φ

Run and debug it

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

Perl 5, 84 bytes

print (map{join(" doo"x6,("\n$_ Shark")x4),"!"}qw(Baby Daddy Mommy Grandpa Grandma))

Try it online!

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

Jelly, 51 bytes

;“¤⁾ċ»;“¡N³»ẋ6¤;”¶ẋ3;;“ß<Ė»
“þɗ“¡þ"“£H$“æf⁵“æeⱮ»Ç€Y

Try it online!

Jelly isn't the best for string manipulation. Still pretty good.

If you expand out the strings to their ungolfed form, the code looks like this:

;“ Shark”;“ doo”ẋ6¤;“¶”ẋ3;;“ Shark!”
“Baby“Daddy“Mommy“Grandpa“Grandma”Ç€Y

(The string compression was done using user202729's compressor).

;“ Shark”;“ doo”ẋ6¤;“¶”ẋ3;;“ Shark!”   Helper Link; take a string and format it into a stanza
;“ Shark”                              Append " Shark" to the string
         ;                             Join
                  ¤                    Previous links as a single nilad
          “ doo”                       " doo"
                ẋ6                            repeated 6 times
                   ;“¶”                Append a newline
                       ẋ3              Repeat 3 times
                         ;             Append the string
                          ;“ Shark!”   Append " Shark!"
“Baby“Daddy“Mommy“Grandpa“Grandma”Ç€Y  Main link
“Baby“Daddy“Mommy“Grandpa“Grandma”     ["Baby", "Daddy", "Mommy", "Grandpa", "Grandma"]
                                  ǀ   For each of these words, format it into the stanza with that family position
                                    Y  Join by newlines
\$\endgroup\$
1
\$\begingroup\$

Clean, 134 bytes

import StdEnv,Text
r=repeatn
f=join"\n"[e+" Shark"+concat s\\e<-split" ""Baby Daddy Mommy Grandpa Grandma",s<-r 3(r 6" doo")++[["!"]]]

Try it online!

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

VBA (Excel), 152 118 bytes

-34 bytes. Thanks @TaylorScott

Using Immediate Window.

a=Split("Baby Daddy Mommy Grandpa Grandma"):b=" Shark":c=" doo":For d=0To 19:?a(Int(d/4))b &IIf((d+1)Mod 4=0,"!",Join(Split(String$(6,"."),"."),c)):Next

a=Split("Baby Daddy Mommy Grandpa Grandma"):b=" Shark":For d=0To 19:?a(d\4)b;IIf((d+1)Mod 4,[Rept(" doo",6)],"!"):Next
\$\endgroup\$
  • 1
    \$\begingroup\$ You should use integer division instead of casting an int over division - so Int(d/4) goes to d\4 , you can rearrange the arguements of the IIf statement to get rid of the =0 and then you can convert that really nifty join split statement with a Rept statement. All together this becomes a=Split("Baby Daddy Mommy Grandpa Grandma"):b=" Shark":For d=0To 19:?a(d\4)b;IIf((d+1)Mod 4,[Rept(" doo",6)],"!"):Next for 118 Bytes \$\endgroup\$ – Taylor Scott Feb 18 at 22:03
  • \$\begingroup\$ Totally forgot Rept function lol. Your answer is way better than mine you should've post it as your own answer. Anyways, thanks for cutting off huge bytes to my wall of code. lol. d\4 <-- Didn't know this until now. Thanks! :D \$\endgroup\$ – remoel Feb 19 at 4:48
  • 1
    \$\begingroup\$ I get far more joy out of helping others get better with VBA, than I do writing it myself - Cheers \$\endgroup\$ – Taylor Scott Feb 19 at 21:54
1
\$\begingroup\$

F# (.NET Core), 179 bytes

["Baby";"Daddy";"Mommy";"Grandpa";"Grandma"]|>Seq.map(fun i->([0..2]|>Seq.map(fun _->i+" Shark doo doo doo doo doo doo")|>String.concat "\n")+"\n"+i+" Shark!")|>String.concat "\n"

Try it online!

No input, export to a string and to std output in a console.

145 bytes

for i in["Baby";"Daddy";"Mommy";"Grandpa";"Grandma"]do(for _ in[0..2]do printfn"%s"(i+" Shark doo doo doo doo doo doo"));printfn"%s"(i+" Shark!")

Try it online!

No input, export to std output

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

F# (.NET Core), 160 156 bytes

let c,r,s=String.concat,List.replicate," Shark"
let p n=r 3(c" "(n+s::r 6"doo"))@[n+s+"!"]
["Baby";"Daddy";"Mommy";"Grandpa";"Grandma"]|>Seq.collect p|>c"
"

Try it online!

And based on @aloisdg version, I get this one:

F# (.NET Core), 130 129 bytes

let p,d=printfn"%s Shark%s"," doo doo"
for i in["Baby";"Daddy";"Mommy";"Grandpa";"Grandma"]do(for _ in"123"do p i (d+d+d));p i"!"

Try it online!

Gaining 1 more char by changine [0..2] by "123" wich is also a sequence of 3 items...

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

groovy, 96 bytes

'Baby Daddy Mommy Grandpa Grandma'.split().any{n="$it Shark";println((n+" doo"*6+'\n')*3+n+'!')}

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Protip: esc -> s -> g on the TryItOnline page for a well formatted post \$\endgroup\$ – ASCII-only Feb 19 at 22:37
  • \$\begingroup\$ close \$\endgroup\$ – ASCII-only Feb 20 at 0:06
  • \$\begingroup\$ also close \$\endgroup\$ – ASCII-only Feb 20 at 1:17
1
\$\begingroup\$

T-SQL, 151 bytes

SELECT REPLACE(a.value+' Shark'+b.value,'Q',REPLICATE(' doo',6))
FROM STRING_SPLIT('Baby,Daddy,Mommy,Grandpa,Grandma',',')a,STRING_SPLIT('Q,Q,Q,!',',')b

Line break for readability only.

SQL's built-in function names are annoyingly long.

STRING_SPLIT works in SQL 2016 and later.

Order isn't 100% guaranteed without an ORDER BY, but this seemed to work in my testing.

\$\endgroup\$
  • \$\begingroup\$ It seems sql answers are not popular, very nice answer. Which means a lot comming from me \$\endgroup\$ – t-clausen.dk Apr 4 at 21:31
  • \$\begingroup\$ Thanks, @t-clausen.dk! \$\endgroup\$ – BradC Apr 4 at 22:00
1
\$\begingroup\$

brainfuck, 627 593 573 bytes

Initialise Array with "Baby\0Daddy\0Mommy\0Grandpa\0Grandma"
Loop runs 71 times
++[++++++++++++++++++
    Get array cells to approximately correct values
    >>>+>>+++++>>+++++>>-->>>>+>>+++++>>+++++>>+++++>>-->>>>+>>-->>-->>-->>-->>>>+>>-->>+++++>>-->>+++++>>-->>+++++>>>>+>>-->>+++++>>-->>+++++>>-->>+++++
    [[<<]<<]>
]
Finish getting cells to correct values
>>>---->>->>>>++++++++>>+>>-->>->>++>>++>>++++++++>>+>>+++++++>>-->>---->>---->>++++++++>>+>>+>>+>>->>--->>++>>->>->>+>>+>>+>>->>--->>++>>---->>-
Inject ones between each cell in the array
[-<+<]>[>>]+

Initialise an exclamation mark; newline; and the string " Shark"
>>>+++++++++++[+++++++
    >------->+>>+>----->+++>+++>---->+++
    <<<<<<<<<
]
>->-->>--->++>->-------->-->++
[<]
Go to the end of the "Baby" Array to loop
<<<<<<[
    >>>
    Loop 3 times
    +++[-
        Go to the first value of the baby array
        <<<[<<]>>>
        Print the word out
        [.>>]
        Go to the shark array
        >[>>]>>>>>
        Print " Shark"
        [.>]
        <[<]
        Loop 6 times
        ++++++[-
            Print a space
            >.
            Change the 'a' in " Shark" to a 'd' and print
            >>>+++.---
            Change the 'r' in " Shark" to an 'o' and print twice
            >---..+++
            <<<<<
        ]
        Print newline
        <<.
        <
    ]
    Go to start of baby array
    <<<[<<]>>
    Print and consume the first string in the array
    ->[.[-]>->]
    Go to shark string
    >[>>]>>>>>
    Print " Shark"
    [.>]
    <[<]
    Print "!\n"
    <.<.
    <<<<
]

-20B thanks to Jo King

Try it online!

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

C (compiled with VC++ (Visual Studio 2017)) 536Bytes

#include "stdafx.h"
#define d "doo "
#define p(x) printf(x);
#define n p("\n")
#define b p(f[i])p(" Shark ")
#define l(x,y) for(int x=0;x<y;x++)
void main(){const char*f[]={"Baby","Daddy","Mommy","Grandpa","Grandma"};l(i,5){l(k,3){b;l(j,6)p(d)n}b;p("\b!\n")}}

this is my naive try: it started from the "good version" where everything is done the neat and tidy way and i just removed the blanks, semicolons where possible and curly braces if possible. i changed main from int to void in order to be able to leave out the return Statement in the end if using a different Compiler (say gcc) the stdafx.h can be ommitted (visual Studio throws an error though (or i just dont know how to do it better...)) although then the use of printf means you either have to include stdio.h instead (=1byte win) or you have to use a Compiler flag to add this to the build path although not mentioned in the Code.... if its no dealbreaker if the exclamation mark is one space away from Baby Shark then the \b can be ommitted (=2 Byte win)

\$\endgroup\$
  • \$\begingroup\$ removing the space between include and " makes a 1byte win. and removing the space between ) and for makes another Maybe you can squeeze out a bit more by modifing the l makro to make curly braces and therefor take one Argument more (=the loopbody) \$\endgroup\$ – der bender Feb 17 at 22:26
  • \$\begingroup\$ Would also work with a non const char array, no? \$\endgroup\$ – B. Go Apr 5 at 15:41
  • \$\begingroup\$ i used to compile that with visual studio and that throws an error if not. maybe other compilers aint that strict \$\endgroup\$ – der bender Apr 5 at 15:43
0
\$\begingroup\$

Wolfram Language (Mathematica), 145 bytes

Nothing special, still thinking of a shorter method.

a={"Baby","Daddy","Mommy","Grandpa","Grandma"};c=" Shark";b=c<>StringJoin@Table[" doo",6];Do[Do[Print[a[[i]]<>b],3];Print[a[[i]]<>c<>"!"];,{i,5}]

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 141? \$\endgroup\$ – ASCII-only Feb 19 at 8:42
  • \$\begingroup\$ 137? \$\endgroup\$ – ASCII-only Feb 19 at 8:46
  • 1
    \$\begingroup\$ 95? \$\endgroup\$ – ASCII-only Feb 19 at 12:15
  • 2
    \$\begingroup\$ also 95 but stolen from Haskell answer \$\endgroup\$ – ASCII-only Feb 19 at 12:37
  • 1
    \$\begingroup\$ @ASCII-only nice improvements. I think that you can take credit for those though, you went a long way from where I started! \$\endgroup\$ – Kai Feb 19 at 15:58
0
\$\begingroup\$

Emacs Lisp, 177 bytes

(defmacro w()`(princ(concat i" Shark doo doo doo doo doo doo\n")))
(defmacro z()`(princ(concat i" Shark!\n")))
(loop for i in'("Baby""Daddy""Mommy""Grandpa")do(and(w)(w)(w)(z)))
\$\endgroup\$
0
\$\begingroup\$

C# (Visual C# Interactive Compiler), 139 bytes

"Baby Daddy Mommy Grandpa Grandma".Split().ToList().ForEach(x=>{string a=" doo",m=x+$" Shark{a+a+a+a+a+a}\n";Write(m+m+m+x+" Shark!\n");});

Try it online!

Any thoughts on improvements? I started aiming for a Linq-based solution with a SelectMany but the deferred execution failed me, along with string.join and return x; being quite verbose syntax

\$\endgroup\$
0
\$\begingroup\$

Swift 4, 149 bytes

var s=" Shark";for i in["Baby","Daddy","Mommy","Grandpa","Grandma"]{for _ in 0...2{print(i+s+(0..<6).map({_ in" doo"}).reduce("",+))};print(i+s+"!")}

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 126 \$\endgroup\$ – ASCII-only Feb 20 at 3:53
  • \$\begingroup\$ 119 \$\endgroup\$ – ASCII-only Feb 20 at 4:02
0
\$\begingroup\$

Japt -R, 58 57 bytes

`BabysDaddysMommysGÎÀpGÎÀµ`qÅ˱` Srk` +` ºo`³²+R ³+D+'!

Run it online

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

Wolfram Language (Mathematica), 95 bytes

Do[Print[a," Shark"<>If[i>3,"!",Table[" doo",6]]],{a,{Baby,Daddy,Mommy,Grandpa,Grandma}},{i,4}]

Try it online!

\$\endgroup\$
0
\$\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\$

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.