49
\$\begingroup\$

Whilst trying (and failing) have persuade my infant son to eat his dinner, I tried singing to him. Mid way through this song I realised the formulaic structure might lend itself well to code golfing!

The task is to write a program or function which accepts no input and produces the following text:

There's a hole in the bottom of the sea
There's a hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a log in the hole in the bottom of the sea
There's a log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a bump on the log in the hole in the bottom of the sea
There's a bump on the log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a frog on the bump on the log in the hole in the bottom of the sea
There's a frog on the bump on the log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a fly on the hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a fly on the hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a flea on the fly on the hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a flea on the fly on the hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

There's a smile on the flea on the fly on the hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a smile on the flea on the fly on the hair on the wart on the frog on the bump on the log in the hole in the bottom of the sea
There's a hole, there's a hole
There's a hole in the bottom of the sea

Challenge rules:

  • The text may be printed or returned as function output
  • Each verse is separated by a single empty line
  • Trailing whitespace is OK as long as it does not change the layout (so no leading whitespace or extra spaces between words)
  • Trailing newlines are OK too.
  • No leading newlines.
  • All languages welcomed, and this is , so the shortest answer in bytes for each language wins!
\$\endgroup\$
9
  • 6
    \$\begingroup\$ Similar to There Was an Old Lady (other similar challenges e.g. this have been closed as duplicates, although I don't think they necessarily should.) \$\endgroup\$ Jan 30, 2019 at 16:33
  • 6
    \$\begingroup\$ Ho, ro, the rattlin' bog, the bog down in the valley-o. \$\endgroup\$ Jan 30, 2019 at 22:22
  • 5
    \$\begingroup\$ For comparison (though not a programming language) gzip -5 compresses it to 186 bytes (and bzip2 and xz seem to do worse). \$\endgroup\$ Jan 30, 2019 at 23:34
  • 2
    \$\begingroup\$ Congrats, from another developer parent :) \$\endgroup\$
    – AJFaraday
    Jan 31, 2019 at 14:26
  • 1
    \$\begingroup\$ I want to adapt this song to 05AB1E... "There's a hole in oh-five-ay-bee-one-ee!" \$\endgroup\$ Jan 31, 2019 at 16:40

35 Answers 35

1
2
1
\$\begingroup\$

Shell, 291 bytes

echo 'smile,flea,fly,hair,wart,frog,bump,log,hole'|awk -F, 'BEGIN{z="here'\''s a ";a="T"z;c=a "hole";b=" in the bottom of the sea"}function f(n){printf a $n;for(j=n+1;j<=NF;j++){printf " on the " $j};print b;}{for(i=NF;i>=1;i--){printf (i<NF)?"\n":"";f(i);f(i);print c", t" z "hole";f(NF)}}'

I'm sure it can be golfed further (definitions of vars & function) ...

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

Java (OpenJDK 8), 320 344 bytes

Long but wanted to try with java, no streams and java 8 things.

*Edited to fix some problems.

static String w(){String[]a={"hole","log","bump","frog","wart","hair","fly","flea","smile"};String n="T",m="t",q=" ",t="here's a ",s="bottom of the sea \n",y="in the ",o="on the ",b=t+a[0],f="",v,l="\n",c=y+s,h=a[0]+q+c,z=n+b+", "+m+b+q+l+n+b+q+c;for (int i=0;i<9;i++){v=n+t;for(int j=i;j>0;j--){v+=a[j]+q+(j>1?o:y);}v+=h;f+=v+v+z+l;}return f;}

Try it online!

\$\endgroup\$
6
  • \$\begingroup\$ there are two problems the spaces before the commas and the uppercase after comma, otherwise you can check translation of my answers 282 bytes \$\endgroup\$ Jan 31, 2019 at 15:14
  • 1
    \$\begingroup\$ 269 bytes using lambda notation \$\endgroup\$ Jan 31, 2019 at 15:18
  • \$\begingroup\$ @Shaggy You are right, it is fixed now :) \$\endgroup\$ Jan 31, 2019 at 17:21
  • \$\begingroup\$ @NahuelFouilleul 264 bytes \$\endgroup\$ Feb 1, 2019 at 18:47
  • \$\begingroup\$ 261 bytes \$\endgroup\$
    – ceilingcat
    Feb 1, 2019 at 23:04
1
\$\begingroup\$

C# (.NET Core), 315, 320, 290 bytes

EDIT: Forgot to repeat the first line. :C

EDIT2: Thanks to recursive for -30 bytes! Switched to using a .Split() to form the string array and added a really cool switch for flipping between "in" and "on".

s=>{var b="hole/log/bump/frog/wart/hair/fly/flea/smile/here's a / in the bottom of the sea\n".Split('/');string c=b[9]+b[0],t="";for(int k,j=0;j<9;t=""){t+="T"+b[9];for(k=j++;k>-1;k--)t+=b[k]+(k<1?"":" "+"oi"[1/k]+"n the ");t+=b[10];t+=t+"T"+c+", t"+c+"\n"+"T"+c+b[10]+"\n";s+=t;}return s;}

Try it online!

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Unfortunately your answer is currently invalid, as it doesn't repeat the first line of each verse. \$\endgroup\$
    – Sok
    Jan 30, 2019 at 22:57
  • \$\begingroup\$ Missed it! Now fixed, ty Sok. \$\endgroup\$
    – Destroigo
    Jan 31, 2019 at 15:18
  • 1
    \$\begingroup\$ Few tweaks for you: tio.run/##LZAxa8MwEIX3/IpDS2xkR/… \$\endgroup\$
    – recursive
    Feb 1, 2019 at 0:38
  • \$\begingroup\$ Really liked the "oi"[1/k] part for switching between on/in. Ty recursive. \$\endgroup\$
    – Destroigo
    Feb 1, 2019 at 14:30
1
\$\begingroup\$

ink, 231 229 bytes

LIST W=hole,log,bump,frog,wart,hair,fly,flea,smile
VAR T="here's a "
~temp H=T+"hole"
VAR B="bottom of the sea"
-(i)~W=W((i+1)/2)
T{T}<>
-(k){W} {W-2:o|i}n the <>
~W--
{W:->k}{B}
{i%2:->i}
T{H}, t{H}
T{H} in the {B}
\ 
{i<17:->i}

Try it online!

  • -2 bytes by changing "{T}hole" to T+"hole" and removing a rogue space
\$\endgroup\$
0
\$\begingroup\$

Zsh, 162 bytes

set hole in the 'bottom of the sea'
0="There's a "
alias D="<<<\"$0\$@
$0\$@
$0$1, ${0:l}$1
$0$*
\"&&4=$"@
D
for 1 (log bump frog wart hair fly flea smile)D&&2=on

Attempt This Online!

\$\endgroup\$
1
2

Your Answer

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

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