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

23
\$\begingroup\$

SOGL, 103 94 93 bytes

Ψ ~Δ№Q‘离vζh‛←&M⁶╥7[P≈╔6≡⁸(φΔ\⅔Σ‚>≡ā⁷⁽○¹‘Ξ⁵K4s³‘⁽Bθ2n{@∑" the ”+Κ:bΚē‽:C}TPb"n@²‘+Tō, upcPøP

Try it here!

...‘                 push "bottom of the sea" - kept for the loop, here for 
    ...‘             push "hole in log in bump on frog on wart on hair on fly on flea on smile on"
        ...‘         push "there's a "
            ⁽        uppercase the 1st letter of that
             B       save "There's a " in B
              θ      split the long data string on spaces
               2n    split in arrays of length 2

{                     for each of those:
 @∑                   join the current array with spaces - e.g. "hole in"
   " the ”+           append " the " to it
           Κ          prepend that to "bottom of the sea" (or whatever it is now)
            :         create a copy
             bΚ       prepend B to it - finishes current line
               ē‽:C}  if (E++), save a copy of that in C (for the last line)

TP                   print the current line twice
  b"...‘+            B + "hole" - "There's a hole"
         T           output that, keeping item
          ō,         output ", "
             up      print the kept item lowercased
               cP    print the contents of C
                 øP  print an empty line
\$\endgroup\$
5
  • 14
    \$\begingroup\$ But....but how? \$\endgroup\$ Jan 31, 2019 at 4:06
  • 8
    \$\begingroup\$ Incredible. How even-- \$\endgroup\$ Jan 31, 2019 at 5:04
  • 1
    \$\begingroup\$ HNQ strikes again! :\ \$\endgroup\$
    – Shaggy
    Feb 1, 2019 at 1:30
  • 4
    \$\begingroup\$ Would you mind adding an explanation? Curious to see how it works. \$\endgroup\$ Feb 1, 2019 at 8:18
  • \$\begingroup\$ @KevinCruijssen added \$\endgroup\$
    – dzaima
    Feb 1, 2019 at 15:20
19
\$\begingroup\$

Stax, 90 87 75 bytes

¥▌▼h4█☻■Ω1gçΔ¶Zjµ│☺X▄)/╞▄╒)¥jêLqα╧ñu┌⌂½╧ûⁿ↕O◘╔╪kl<æàbπïfuσ♪╫qΓ╪ûQ├╘Te♥Æó♣ƒE

Run and debug it

Unpacked, ungolfed, and commented it looks like this.

`;$w]i"50h1&V~OP>F$`            compressed literal for "There's a hole in the bottom of the sea"
X                               store in register X without popping
zG                              push an empty string and jump to the target (trailing }) 
`hfUiVx}.|j~vG12])Bxk?v zF`j    split "log bump frog wart hair fly flea smile" into array of words
F                               for each word, execute the following
  i. o. i?                      (i ? " o" : " i") where i is the 0-based iteration index
  +                             concatenate to the word
  `_o9!`+                       concatenate "n the "
  G                             jump to target below, resume next foreach iteration when finished
}                               this is the target of `G`, execution resumes when finished
  As|@                          insert substring at position 10
  QQ                            peek and print with newlines twice
  x14(                          trim string to leftmost 14 characters
  q                             peek and print without newlines
  ., p                          print ", " without newline
  vP                            lowercase 14 characters and print with newline
  xP                            push value of register X, then print with newline
  zP                            print blank line

Run this one

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Would you mind adding an explanation? Curious to see how it works. \$\endgroup\$ Feb 1, 2019 at 8:18
  • \$\begingroup\$ I will but I still have the feeling that a totally different approach will do better. After I succeed or fail in that I'll explain whatever's left. \$\endgroup\$
    – recursive
    Feb 1, 2019 at 15:50
  • 1
    \$\begingroup\$ @KevinCruijssen: I had a feeling that that there was a much better approach. Sure enough, I totally re-wrote it, and saved another 12 bytes of bloat. I added some explanation as well. \$\endgroup\$
    – recursive
    Feb 5, 2019 at 4:00
16
\$\begingroup\$

Perl 5, 158 154 bytes

$_="There's a bottom of the sea
";for$,(<{{hole,log}" i",{bump,frog,wart,hair,fly,flea,smile}" o"}>){s/a/a $,n the/;say$_.$_.($t||=s/.{14}/$&, \l$&
$&/r)}

154 bytes

158 bytes

\$\endgroup\$
2
  • 5
    \$\begingroup\$ There's a bottom of the sea. The facts check out, +1 \$\endgroup\$
    – Jo King
    Jan 31, 2019 at 13:33
  • \$\begingroup\$ :), there's also this variation starting with There's a sea but it's longer \$\endgroup\$ Feb 1, 2019 at 13:25
13
\$\begingroup\$

Python 2, 202 190 187 185 183 182 181 bytes

s="bottom of the sea\n"
a="There's a "
for w in'hole log bump frog wart hair fly flea smile'.split():s=w+" %sn the "%'io'['g'in s]+s;print(a+s)*2+a+"hole, t%shole\n"%a[1:]+a+s[-30:]

Try it online!

Old alternatives to 'io'['g'in s] (13 bytes):

  • 14: 'oi'[s[5]<'n']
  • 15: 'io'[len(s)>30], 'ioo'[len(s)%3], 'ooi'[len(s)%4], and 'io'[w[1]=='o']

Saved:

  • -1 byte, thanks to Jonathan Allan
  • -1 byte, thanks to Rod
  • -1 byte, thanks to Erik the Outgolfer
\$\endgroup\$
3
  • \$\begingroup\$ "hole, t%shole\n"%a[1:] saves a byte \$\endgroup\$ Jan 30, 2019 at 16:29
  • \$\begingroup\$ You can save a byte by dropping the zip \$\endgroup\$
    – Rod
    Jan 30, 2019 at 18:26
  • \$\begingroup\$ 'oi'[s[5]<'n'] will be an old alternative too: Featuring 'io'['g'in s]! \$\endgroup\$ Jan 30, 2019 at 22:51
13
\$\begingroup\$

C (gcc), 261 246 236 bytes

#define X" on the "
char*a="smile"X"flea"X"fly"X"hair"X"wart"X"frog"X"bump"X"log in the hole in the bottom of the sea\n";f(i){for(i=0;i<9;)printf("T%s%sT%1$s%2$sT%1$shole, t%1$shole\nT%1$s%3$s\n","here's a ",a+"_TH<0$\31\r"[i++],a+95);}

-15 bytes, Thanks to Daniel Schepler
-10 bytes, Thanks to ceilingcat

Try it online!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Could you write ,*b="_TH<0$\31\r" instead? \$\endgroup\$ Jan 30, 2019 at 23:21
  • \$\begingroup\$ Would it save any bytes to define " in the "? \$\endgroup\$
    – AAM111
    Jan 31, 2019 at 19:51
  • \$\begingroup\$ @OldBunny2800 no, it would be longer! in this case you need at least 6 occurrences to be effective... \$\endgroup\$ Feb 1, 2019 at 8:16
12
\$\begingroup\$

05AB1E, 103 100 99 97 96 93 92 bytes

Saved a byte thanks to Kevin Cruijssen

“¥ÊˆŽ bumpÑå‡îtíÁ¤†îÌea¹²“#v’T€Î's a ’s„oiN2‹èy“ÿ ÿn€€ ÿ“©“—耂€€í™“JDN_iDU}X14£Dl‚„, ýXõ»,®

Try it online!

Explanation

“¥ÊˆŽ bumpÑå‡îtíÁ¤†îÌea¹²“#v starts a loop over the list ["hole", "log", "bump", "frog", "wart", "hair", "fly", "flea", "smile"]. The words are compressed using the 05AB1E dictionary.

On each we do:

’T€Î's a ’    # push the string "There's a "
s             # move the string from the previous iteration to the top of the stack
              # will be an empty string the first iteration since there is no input
„oiN2‹è       # push "i" for the first 2 iterations and "o" otherwise
y             # push the current word
“ÿ ÿn€€ ÿ“    # use interpolacing to create the meat of the current iteration string
              # meaning "hole in the ", "log in the hole in the " and so on
©             # store a copy in the register for the next iteration
“—耂€€í™“    # push the string "bottom of the sea"
JD            # join the whole line together and duplicate it
N_iDU}        # if this is the first iteration, store a copy of the line in X
X14£          # push the first 14 chars of X, which is "There's a hole"
Dl            # make a lower-case copy
‚„, ý         # join the original with the lowercase copy on ", ", forming line 3
X             # push X which is line 4
õ             # push and empty string, to create the line break between sections
»,            # join the whole section on newlines and print
®             # push the register for the next iteration
\$\endgroup\$
2
11
\$\begingroup\$

PowerShell, 194 188 185 180 174 bytes

$z=$a="in the bottom of the sea"
$b="here's a"
$h="$b hole"
echo hole log bump frog wart hair fly flea smile|%{,"T$b $_ $a"*2
$a='oi'[!$j++]+"n the $_ $a"
"T$h, t$h
T$h $z
"}

Try it online!

Can't quite seem to catch Python...

Basically, sets a few common strings to $h, $a, $z, and $b, then goes through a loop through each of the items (hole, log, ... flea, smile), each iteration outputting the appropriate verse. There's a little bit of logic with !$j++ in the middle to account for the in/on switch that happens. Otherwise, all the strings are just left on the pipeline, and the default Write-Output gives us newlines for free.

-6 bytes thanks to Arnauld.
-3 bytes thanks to mazzy.
-5 bytes thanks to Veskah.
-6 bytes thanks to mazzy.

\$\endgroup\$
8
  • \$\begingroup\$ -3 bytes :) Try it online! \$\endgroup\$
    – mazzy
    Jan 31, 2019 at 9:39
  • \$\begingroup\$ @mazzy That's a clever trick. I'll need to keep that in mind, because I use -split quite a bit for getting words. \$\endgroup\$ Jan 31, 2019 at 12:52
  • \$\begingroup\$ Two forgotten bytes \$\endgroup\$
    – Veskah
    Jan 31, 2019 at 21:43
  • \$\begingroup\$ 180 bytes \$\endgroup\$
    – Veskah
    Jan 31, 2019 at 23:40
  • 1
    \$\begingroup\$ 174. Try it online! \$\endgroup\$
    – mazzy
    Feb 1, 2019 at 17:14
9
\$\begingroup\$

JavaScript (ES6),  201 194 189 188  187 bytes

Saved 1 byte thanks to @Shaggy

_=>`14log4bump5frog5wart5hair5fly5flea5smile5`.replace(/.+?\d/g,w=>`T0${(p=w+3+p)+p}1, t01
T01432
`.replace(/\d/g,n=>`here's a |hole|bottom of the sea
|n the | i| o`.split`|`[n]),p=`2T0`)

Try it online!


JavaScript (ES6), 235 bytes

Simply RegPack'ed.

_=>[..."Z[]^_$cdjkqvxz{}~"].reduce((p,c)=>(l=p.split(c)).join(l.pop()),`Tj{{}qq}$$}~~}dd}__}xx}cc}[[v~ frogz$}v
Z{kZz on^x flyz_v], tj]Zkq log in^{k] in^ bottom of^ seajhere's ad wartz~c fleazx$ bumpzq_ hairzd^ the] hole[ smilezcZ
Tj`)

Try it online!

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

Bash, 168 160 bytes

r="There's a bottom of the sea
";for i in {hole,log}\ in {bump,frog,wart,hair,fly,flea,smile}\ on;{
r=${r/a/a $i the};t=${r:0:14};echo "$r$r${u=$t, ${t,}
$r}";}

160 bytes

168 bytes

Translated from my other answer in Perl.

\$\endgroup\$
7
\$\begingroup\$

Japt -Rx, 126 116 113 112 111 109 107 bytes

It turns out that golfing a string compression challenge while on your phone down the boozer is incredibly difficult - who'd've thunk?!

`T's»dâ ÈÞ­omºfdÈ a`rdS
tE8
¯E
`logn¿mpnfgnØnirnf§nf¤Úè`qÍË2ÆiAV¯E©8 iF¯E ÔqVri'oÃpW+v iSi,)UPÃc

Test it

                                              :The first 3 lines get assigned to variables U, V & W, respectively
`...`                                         :The compressed string "There'sdadholedindthedbottomdofdthedsea"
     rdS                                      :Replace all "d"s with spaces
tE8                                           :Substring of U from 0-based index 14 (E), of length 8 (="  in the ")
¯E                                            :Slice U to index 14 (="There's a hole")
`...`                                         :The compressed string "lognbumpnfrognwartnhairnflynfleasmilent"
     qÍ                                       :Split on "n" (note that the last element is irrelevant)
       Ë                                      :Map each element at 0-based index E in array F
        2Æ                                    :  Map the range [0,2)
          iA                                  :    Insert the following in U at index 10
            V¯                                :      V sliced to index
              E©8                             :        Logical AND of E and 8 (=0 on first iteration, 8 on all others)
                  i                           :      Prepend
                   F¯E                        :        Slice F to index E
                       Ô                      :        Reverse
                        q                     :        Join with
                         Vri'o                :          Replace "i" with "o" in V
                              Ã               :  End map
                               p              :  Push
                                W+            :    W appended with
                                  v           :      W lowercased
                                    iSi,      :      Prepended with a space prepended with a comma
                                        )     :    End append
                                         UP   :    U and an empty string
                                           Ã  :End map
                                            c :Flatten
                                              :Implicitly join with newlines, trim & output
\$\endgroup\$
7
\$\begingroup\$

XML, 719 673 603 514 493 486 bytes

<!DOCTYPE a[<!ENTITY T "There's a"><!ENTITY O " on the"><!ENTITY a " hole in the bottom of the sea
"><!ENTITY b " log in the&a;"><!ENTITY c " bump&O;&b;"><!ENTITY d " frog&O;&c;"><!ENTITY e " wart&O;&d;"><!ENTITY f " hair&O;&e;"><!ENTITY g " fly&O;&f;"><!ENTITY i " flea&O;&g;"><!ENTITY z "&T; hole, there's a hole
&T;&a;
">]><a>&T;&a;&T;&a;&z;&T;&b;&T;&b;&z;&T;&c;&T;&c;&z;&T;&d;&T;&d;&z;&T;&e;&T;&e;&z;&T;&f;&T;&f;&z;&T;&g;&T;&g;&z;&T;&i;&T;&i;&z;&T; smile&O;&i;&T; smile&O;&i;&z;</a>

You can "execute" it with xmlstarlet sel -t -m '//a' -v . -n <xml_file_here>.

This would be a lot easier if XML wasn't so verbose, but on the bright side, this is less than 25% the size of the original text.

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

Retina 0.8.2, 150 bytes


THsmile oNflea oNfly oNhair oNwart oNfrog oNbump oNlog iNE
N
$&$'¶TH
O^$`

.+
$&¶$&¶THW, tHW¶THE¶
H
here's a 
E
W iNbottom of the sea
W
hole
N
n the 

Try it online! Explanation:


THsmile oNflea oNfly oNhair oNwart oNfrog oNbump oNlog iNE

Insert the last verse.

N
$&$'¶TH

Compute all the verses.

O^$`

Put the verses in the correct order.

.+
$&¶$&¶THW, tHW¶THE¶

Complete each verse and add the chorus.

H
here's a 
E
W iNbottom of the sea
W
hole
N
n the 

Expand some placeholders.

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

R, 237 231 bytes

i=" in the "
for(j in 0:8)cat(f<-c(t<-"There's a ",paste(c("log","bump","frog","wart","hair","fly","flea","smile")[j:0],collapse=" on the "),if(j)i,h<-"hole",i,b<-"bottom of the sea
"),f,t,h,", there's a ",h,"
",t,h,i,b,"
",sep="")

Try it online!

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

PHP, 180 178 bytes

foreach([hole,log,bump,frog,wart,hair,fly,flea,smile]as$w)echo$a=T.($b="here's a ").($s="$w ".io[++$i>2]."n the $s").$c="bottom of the sea
",$a,T,$b.=hole,", t$b
T$b in the $c
";

Run with -nr or try it online.

Yields warnings in PHP 7.2; to fix, put quotes around
the array elements, io, hole and the two standalone T.

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

C (gcc), 334 328 307 299 bytes

char*s="here's a \0smile 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\n";i;k=105;a[]={0,1,1,1,1,0,1,2,2};main(j){for(;i<9;k-=11+a[i++])do{printf("T%s%s",s,s+k);}while(j++&1||!printf("T%shole, t%shole\nT%s%s\n",s,s,s,s+105));}

Try it online!

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

Perl 6, 166 bytes

($/=@(($!="There's a")X [\R,](<hole log bump frog wart hair fly flea smile>Z(<i o>[$++>1]~"n the")xx*)X"bottom of the sea
")).map:{say "$_$_$! hole, {$!.lc} hole
$0"}

Try it online!

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

Japt -R, 142 bytes

`—¤clogc¿mpcfžgcØÖŽrcf§cf¤acsÚè`qc
`ˆ e Þ­om  e  a`
`T”œ's a `
£W+U¯YÄ ÔËE?"io"gE<Y +`n e `:P +Dø+` {V}
` ²+W+`—¤, t”œ's a —¤
{W}—¤ {V+R

Try it online!

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

Batch, 267 bytes

@echo off
set r=i
set t= There's a hole
set s=bottom of the sea
for %%w in (hole log bump frog wart hair fly flea smile)do call:c %%w
exit/b
:c
set s=%1 %r%n the %s%
echo%t:~,11%%s%
echo%t:~,11%%s%
echo%t%,%t:T=t%
echo%t%%s:~-25%
echo(
if %1==log set r=o

t contains a string repeated in the chorus, s contains most of the verse line, while r chooses between in the and on the. In the verses, only the first 11 characters of t is needed, while in the first chorus line the second copy of t has its T lowercased and the second chorus line reuses the last 25 characters of s.

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

Ruby, 173 170 bytes

a="T#{["here's a hole"]*3*"%s"%[", t","
T"]+c=" in the "}bottom of the sea

"
b=a[31,39]
%w{log bump frog wart hair fly flea smile x}.map{|i|puts b,b,a;b[9]+=i+c;c[1]=?o}

Try it online!

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

Haskell, 243 215 bytes

Reduced to 215 bytes with great help from nimi

c[[l n,l n,'T'#h++", "++'t'#h,l 8,""]|n<-[8,7..0]]
t#u=t:"here's a "++u
h="hole"
c=concat
l n='T'#c(drop n$map(++" on the ")(words"smile flea fly hair wart frog bump")++["log in the ",h," in the bottom of the sea"])

Try it online!

(Old 243 byte version is here).

A quite straightforward solution.

-- main function producing a list of lines
v = concat [[
    l n,
    l n, -- second line of each verse equals to its first line
    'T' # h ++ ", " ++ 't' # h,
    l 8, -- last line of each verse is the same in all verses
    ""
  ] | n <- [8,7..0]]

-- a small helper to construct similar strings 
t # u = t : "here's a " ++ u

h = "hole"

-- construct a first line of n-th verse (with n = 8 is the first and n = 0 is the last one)
-- Every such line begins with a constant prefix followed by expanding list of nested entities
l n = 'T' # concat (
      drop n $
         map (++ " on the ") (words "smile flea fly hair wart frog bump")
         ++ ["log in the ", h, " in the bottom of the sea"]
    )
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Some tips: a) you use s only once, so you can inline it. b) you always prepend and append something to t, so you can make it a (infix) function: t#u=t:"here's a "++u. c) constructing the big list in function l with map(++" on the ")(words"smile flea ..." is shorter. Also: move everything appended to that list into the list itself. d) the list of numbers to drop now runs from 8 down to 0 (single digit numbers!) e) now inlining i also save some bytes. f) no need to name your main function. According to our meta, Haskell values are considered proper functions, so drop the v=. \$\endgroup\$
    – nimi
    Jan 31, 2019 at 19:04
  • \$\begingroup\$ ... All in all 215 bytes Try it online! \$\endgroup\$
    – nimi
    Jan 31, 2019 at 19:04
  • 1
    \$\begingroup\$ Another 3 bytes to save: instead of the list comprehension you can use >>= (concatMap) from the list monad and inline concat in function l. Try it online! \$\endgroup\$
    – nimi
    Feb 1, 2019 at 17:14
3
\$\begingroup\$

JavaScript (Babel Node), 239 bytes

-7 bytes from @Oliver *.*

(x=0,r='hole0log0bump0frog0wart0hair0fly0flea0smile'.split`0`).map(a=>(t=(i="There's a ")+a+r.slice(0,x++).reverse().map((h,_)=>` ${"io"[_<x-2|0]}n the ${h}`).join``+(o=` in the bottom of the sea
`))+t+(`${k=i+"hole"}, ${k}
`)+k+o).join`
`

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Te second T on the 3rd line of each verse should be lowercase. \$\endgroup\$
    – Shaggy
    Jan 31, 2019 at 14:16
3
\$\begingroup\$

Python 3, 213 206 198 193 bytes

k='n the ';o=e='bottom of the sea\n';b="There's a ";h='hole'
for j in[h]+'log bump frog wart hair fly smile'.split():o=j+' '+'io'['g'in o]+k+o;print(b+o+b+o+b+h+', t'+b[1:]+h+'\n'+b+h+' i'+k+e)

Try it online!


-15 bytes thanks to @Sara
-5 bytes thanks to @ASCII-only

Probably a bit more golfable, but not much.

\$\endgroup\$
7
  • \$\begingroup\$ 198 bytes \$\endgroup\$
    – Sara J
    Mar 30, 2019 at 9:06
  • \$\begingroup\$ @SaraJ Thanks. I was under the (clearly mistaken) impression that o=e= would make both o and e refer to the same object. I also thought split would be longer. \$\endgroup\$
    – Miriam
    Mar 30, 2019 at 9:14
  • \$\begingroup\$ @ArtemisFowl o and e do refer to the same object... it's just that strings are immutable in Python so things like += will create a new copy instead of mutating the existing one \$\endgroup\$
    – ASCII-only
    Mar 31, 2019 at 11:01
  • \$\begingroup\$ 193 \$\endgroup\$
    – ASCII-only
    Mar 31, 2019 at 11:05
  • \$\begingroup\$ @ASCII-only I know, but I thought that python somehow made sure that they continued to refer to the same object. \$\endgroup\$
    – Miriam
    Mar 31, 2019 at 21:56
2
\$\begingroup\$

Clean, 267 bytes

import StdEnv,Text,Data.List
t="here's a "
h="hole"
b=" in the bottom of the sea"
f=foldr((+)o\s#p="T"+t+join" on the "(reverse s)+" in the "+h+b
=join"\n"[p,p,"T"+t+h+", t"+t+h+"\nT"+t+h+b+"\n\n"])""(tl(inits["log","bump","frog","wart","hair","fly","flea","smile"]))

Try it online!

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

cQuents, 238 219 bytes

|@
#36::"T"~c1)~j\rbk));@ )~c2,Z,"T"~c1)~"hole, t"~c1)~"hole","T"~c1)~c2)~@

::"","log in the","bump"~c3,"frog"~c3,"wart"~c3,"hair"~c3,"fly"~c3,"flea"~c3,"smile"~c3
:"here's a ","hole in the bottom of the sea"," on the"

Try it online!

This challenge made me finally implement lists and strings in my language. This language is built for integer sequences, so it did pretty well!

Explanation

:"here's a ","hole in the bottom of the sea"," on the"

    helper line: c1), c2), and c3) access the three terms in this list

::"","log in the","bump"~c3,"frog"~c3,"wart"~c3,"hair"~c3,"fly"~c3,"flea"~c3,"smile"~c3

    helper line: yields a list containing the first n terms in it, accessed with bx)
    for example, the first three terms are:

"","log in the","bump"~c3

    so b3) would yield ["","log in the","bump on the"] (~ is concatenation and c3 is " on the")


|@
#36::"T"~c1)~j\rbk));@ )~c2,Z,"T"~c1)~"hole, t"~c1)~"hole","T"~c1)~c2)~@


|@
                              join sequence on literal newline
#36::                         output first 36 terms in sequence joined together
                              following are the 4 terms in the sequence, which will cycle through 9 times (for a total of 36 terms)
"T"~c1)~j\rbk));@ )~c2,       first term
"T"~c1)~                      "T" concat "here's a " concat
        j\rbk));@ )           the first k terms of b, reversed, and joined on " "
                   ~c2,       concat "hole in the bottom of the sea"
Z,                            second term - same as previous
"T"~c1)~"hole, t"~c1)~"hole", third term
"T"~c1)~                      "T" concat "here's a " concat
        "hole, t"~c1)~"hole", "hole, t" concat "here's a " concat "hole"
"T"~c1)~c2)~@
                              fourth term - "T" concat "here's a " concat "hole on the bottom of the sea" concat newline
\$\endgroup\$
2
\$\begingroup\$

Perl 5, 194 bytes

@ASCII-only shaved off 6 bytes with literal newlines and a \l trick I forgot about

$"=" on the ";say+($b=($e="There's a ").hole,$c=" in the bottom of the sea",$/)x2,$.="$b, \l$b
$b$c
";say"$e@a[-$_..-1] in the hole$c
"x2,$.for 1..(@a=qw/smile flea fly hair wart frog bump log/)

Try it online!

\$\endgroup\$
8
  • \$\begingroup\$ 194? \$\endgroup\$
    – ASCII-only
    Jan 31, 2019 at 8:25
  • \$\begingroup\$ Yup. Nice work. I should have remembered the newlines for certain. I've seen the \l before, but never had a reason to use it, so never thought of it. \$\endgroup\$
    – Xcali
    Jan 31, 2019 at 23:59
  • \$\begingroup\$ 190? \$\endgroup\$
    – ASCII-only
    Feb 1, 2019 at 0:00
  • \$\begingroup\$ well this didn't work. neither did this \$\endgroup\$
    – ASCII-only
    Feb 1, 2019 at 0:17
  • \$\begingroup\$ closer \$\endgroup\$
    – ASCII-only
    Feb 1, 2019 at 0:23
2
\$\begingroup\$

Charcoal, 115 106 bytes

≔There's a holeθEE⁹⁺…θχ⪫⮌…⪪”↶±∧⟲!↶⁼,(_⎇RB↧ω⪪zθⅉQθ`✳&⬤⸿◧σ⁻y▷»ΣK▶↙⁻υX`SξQ6 /ι⁹Wq”x⁺²ιn the ⟦ιι⁺⁺θ, ↧θ⁺θ✂ι±²⁵

Try it online! Link is to verbose version of code. Edit: Saved 9 bytes by copying my Batch code for the last line of the chorus. Explanation:

≔There's a holeθ

Save the string There's a hole, which is used twice as-is, a third time in lower case, and also a fourth time but just the first 10 characters.

⪪”↶±∧⟲!↶⁼,(_⎇RB↧ω⪪zθⅉQθ`✳&⬤⸿◧σ⁻y▷»ΣK▶↙⁻υX`SξQ6 /ι⁹Wq”x

Split the string bottom of the seaxhole ixlog ixbump oxfrog oxwart oxhair oxfly oxflea oxsmile o on xs.

E⁹⁺…θχ⪫⮌…...⁺²ιn the 

Loop over the 9 verses, taking the first i+2 elements of the array, reversing them, joining them with n the, and prefixing There's a to the result.

E...⟦ιι⁺⁺θ, ↧θ⁺θ✂ι±²⁵

Expand each line into a verse by duplicating the line and constructing the chorus. Each line of the verse is then implicitly printed on each own line, and each verse is implicitly separated by a blank line.

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

V, 184 170 bytes

4iThere's a hole in the bottom of the sea
kky5w5eá,lpD5brtHj4yyGp4w8ion the 2briilog 3bibump 3bifrog 3biwart 3bihair 3bifly 3biflea 3bismile 7ñ4yykp4wd3wñ8ñÄ5jñ

Try it online!

Explanation:

  • 4iThere's a hole in the bottom of the sea<\n><esc> Insert "Theres' a hole in the bottom of the sea" 4 times.
  • kk Move to the third line
  • y5w copy "There's a hole"
  • 5eá, insert a comma after "There's a hole"
  • lp paste after the comma
  • D delete the rest of the line
  • 5brt lowercase the second T
  • Hj4yy copy 4 lines from the second line
  • Gp Paste everything after the first line
  • 4w8ion the <esc>(at the end of the first verse) move to first "hole" in second verse and insert "on the " 8 times
  • 2briilog <esc> move backwards to the last "on", replace the o with an i and then insert "log "
  • 3bibump <esc>3bifrog <esc>3biwart <esc>3bihair <esc>3bifly <esc>3biflea <esc>3bismile <esc> Move backwards through the line, inserting the appropriate words between each "on the"
  • 7ñ4yykp4wd3wñ execute 4yykp4wd3w 7 times
    • 4yykp duplicate the verse before this one
    • 4wd3w move to the first word after "There's a hole" and delete 3 words
  • 8ñÄ5jñ duplicate the first line of each verse after the first (there are 8 of these to do)
\$\endgroup\$
2
\$\begingroup\$

LaTeX, 265 268 characters

\documentclass{book}\input{pgffor}\def\i{bottom of the sea}\let~\i\def\b{here's a }\def\h{hole}\def\s#1{ in}\begin{document}\foreach\x in{\h\s,log\s,bump,frog,wart,hair,fly,flea,smile}{\xdef~{\x{ on} the ~}T\b~\\T\b~\\T\b\h, t\b\h\\T\b\h\,in the \i\par}\enddocument

compiles into a nice PDF, with paragraph indentations and everything.

Ungolfed and commented:

\documentclass{book}
\input{pgffor}
\def\i{bottom of the sea}   %for re-use in the last two verses 
\let~\i                     %here I keep attaching words
\def\b{here's a }               
\def\h{hole}
\def\s#1{ in}               %this replaces the next token with "in", useful for log and hole where "in" is used instead of"on"
\begin{document}
\foreach\x in{\h\s,log\s,bump,frog,wart,hair,fly,flea,smile}{
    \xdef~{\x{ on} the ~}   %keep attaching words and on/on to ~
    T\b~\\                  %verse 1
    T\b~\\                  %verse 2
    T\b\h, t\b\h\\          %verse 3
    T\b\h\,in the \i\par    %verse 4
}
\enddocument

Of output:

enter image description here

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

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

string b="There's a ",d="hole in the bottom of the sea\n",e,f;" log bump frog wart hair fly flea smile".Split().Any(s=>Write((e=b+(f=s!=""?s+(f!=""?" o":" i")+"n the "+f:s)+d)+e+b+$@"hole, there's a hole
{b+d}
")is int);

Try it online!

-5 bytes thanks to @ASCIIOnly and -2 bytes thanks to @someone!

I have a small child and can assure you this song is equal parts catchy and annoying.

\$\endgroup\$
7
  • 1
    \$\begingroup\$ I'm sorry to have reminded you that it exists :o) \$\endgroup\$
    – Sok
    Jan 31, 2019 at 8:21
  • \$\begingroup\$ .Any() -> !=""? \$\endgroup\$
    – ASCII-only
    Feb 1, 2019 at 1:42
  • \$\begingroup\$ also 223 \$\endgroup\$
    – ASCII-only
    Feb 1, 2019 at 1:44
  • \$\begingroup\$ and you don't need the space after in in the foreach >_> \$\endgroup\$
    – ASCII-only
    Feb 1, 2019 at 1:50
  • \$\begingroup\$ @ASCIIOnly - Thanks for the tips :) \$\endgroup\$
    – dana
    Feb 1, 2019 at 4:34
2
\$\begingroup\$

Slashalash, 216 bytes

/V/\/\///U/\/ VS/TCVR/iBVQUtheVPUoBVOUholeVN/RASVM/ASO, tCO
SA
VL/RMSVKUlog VJUbumpPKVIUfrogPJVHUwartPIVGUhairPHVFUflyPGVEUfleaPFVDUsmilePEVC/here's aVB/nQVA/O R bottom ofQ sea
/SASMSKNKLJNJLINILHNHLGNGLFNFLENELDNDRM

Try it online!

This sort of task is the one and only thing that Slashalash is reasonably good at. :D Hey, the result is shorter than C, C# or Java!

The output from this program ends in two trailing line breaks; hope that's not a deal-breaker.

Anyway, there's no real cleverness here. I simply identified repeated strings and defined one-character shortcuts for them, and repeated until I didn't see any more repeated strings. I did this in a more-or-less naive and greedy fashion. I did, however, intentionally define a shortcut for "smile on the flea on the ... sea", followed by "flea on the fly on the ... sea", and so forth, in order to form a chain of shortcuts. The result is that the whole sequence of new nouns is clearly visible in the code, and I find that pretty pleasing. :)

After V and U are replaced, we have the following more readable code:

/S/TC//R/iB//Q/ the//P/ oB//O/ hole//N/RAS//M/ASO, tCO
SA
//L/RMS//K/ log //J/ bumpPK//I/ frogPJ//H/ wartPI//G/ hairPH//F/ flyPG//E/ fleaPF//D/ smilePE//C/here's a//B/nQ//A/O R bottom ofQ sea
/SASMSKNKLJNJLINILHNHLGNGLFNFLENELDNDRM
\$\endgroup\$

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.