There's a hole in the bottom of the sea

48

5

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!

Sok

Posted 2019-01-30T14:46:13.853

Reputation: 5 592

6

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.)

– Jonathan Allan – 2019-01-30T16:33:09.583

6Ho, ro, the rattlin' bog, the bog down in the valley-o. – fəˈnɛtɪk – 2019-01-30T22:22:57.310

4For comparison (though not a programming language) gzip -5 compresses it to 186 bytes (and bzip2 and xz seem to do worse). – Daniel Schepler – 2019-01-30T23:34:48.513

@DanielSchepler Bubblegum :P – ASCII-only – 2019-01-31T03:13:40.260

2Congrats, from another developer parent :) – AJFaraday – 2019-01-31T14:26:37.583

1I want to adapt this song to 05AB1E... "There's a hole in oh-five-ay-bee-one-ee!" – Magic Octopus Urn – 2019-01-31T16:40:35.783

As KC string compression challenges go, I've had more fun with this one than most others in a while so +1 from me. – Shaggy – 2019-02-01T00:06:16.200

@Shaggy Thanks for the lovely comment, I'm glad to have given you something fun to think about :o) – Sok – 2019-02-01T06:23:00.500

Next time use Maxwell's poem: 2(u) (Under the Sea, Under the Sea)

– Mazura – 2019-02-02T02:23:57.580

Answers

23

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

dzaima

Posted 2019-01-30T14:46:13.853

Reputation: 19 048

14But....but how? – SomeShinyObject – 2019-01-31T04:06:08.697

8Incredible. How even-- – Austin Burk – 2019-01-31T05:04:51.640

1HNQ strikes again! :\ – Shaggy – 2019-02-01T01:30:02.163

4Would you mind adding an explanation? Curious to see how it works. – Kevin Cruijssen – 2019-02-01T08:18:30.243

@KevinCruijssen added – dzaima – 2019-02-01T15:20:53.783

19

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

recursive

Posted 2019-01-30T14:46:13.853

Reputation: 8 616

2Would you mind adding an explanation? Curious to see how it works. – Kevin Cruijssen – 2019-02-01T08:18:32.310

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. – recursive – 2019-02-01T15:50:47.620

1@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. – recursive – 2019-02-05T04:00:27.910

16

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

Nahuel Fouilleul

Posted 2019-01-30T14:46:13.853

Reputation: 5 582

5There's a bottom of the sea. The facts check out, +1 – Jo King – 2019-01-31T13:33:53.067

:), there's also this variation starting with There's a sea but it's longer

– Nahuel Fouilleul – 2019-02-01T13:25:55.813

13

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

TFeld

Posted 2019-01-30T14:46:13.853

Reputation: 19 246

"hole, t%shole\n"%a[1:] saves a byte – Jonathan Allan – 2019-01-30T16:29:05.520

You can save a byte by dropping the zip

– Rod – 2019-01-30T18:26:45.613

@JonathanAllan Thanks :) – TFeld – 2019-01-30T18:55:26.463

@Rod Thanks, :-) – TFeld – 2019-01-30T18:55:38.747

'oi'[s[5]<'n'] will be an old alternative too: Featuring 'io'['g'in s]! – Erik the Outgolfer – 2019-01-30T22:51:15.790

@EriktheOutgolfer Thanks! :D – TFeld – 2019-01-31T07:46:24.563

13

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!

Giacomo Garabello

Posted 2019-01-30T14:46:13.853

Reputation: 1 419

2Could you write ,*b="_TH<0$\31\r" instead? – Daniel Schepler – 2019-01-30T23:21:44.780

Would it save any bytes to define " in the "? – OldBunny2800 – 2019-01-31T19:51:25.890

@OldBunny2800 no, it would be longer! in this case you need at least 6 occurrences to be effective...

– Giacomo Garabello – 2019-02-01T08:16:29.520

12

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

Emigna

Posted 2019-01-30T14:46:13.853

Reputation: 50 798

2

You can remove the leading õ, because apparently it outputs an empty string by default when a swap is used with nothing on the stack. I couldn't find anything else to golf; very nice answer!

– Kevin Cruijssen – 2019-01-31T14:58:02.480

1@KevinCruijssen: Oh yeah, I didn't consider that as there's usually input. Thanks :) – Emigna – 2019-01-31T16:52:38.100

11

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.

AdmBorkBork

Posted 2019-01-30T14:46:13.853

Reputation: 41 581

-3 bytes :) Try it online!

– mazzy – 2019-01-31T09:39:29.880

@mazzy That's a clever trick. I'll need to keep that in mind, because I use -split quite a bit for getting words. – AdmBorkBork – 2019-01-31T12:52:17.373

Two forgotten bytes – Veskah – 2019-01-31T21:43:53.743

180 bytes – Veskah – 2019-01-31T23:40:05.867

@Veskah Awesome. And now beating Python by a byte, too. :D – AdmBorkBork – 2019-02-01T13:25:22.313

start="175">

  • Try it online!
  • – mazzy – 2019-02-01T17:00:34.427

    1

    start="174">

  • Try it online!
  • – mazzy – 2019-02-01T17:14:24.703

    @mazzy Nice bit of variable shuffling. Thanks! – AdmBorkBork – 2019-02-01T17:48:49.653

    9

    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!

    Arnauld

    Posted 2019-01-30T14:46:13.853

    Reputation: 111 334

    8

    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.

    Nahuel Fouilleul

    Posted 2019-01-30T14:46:13.853

    Reputation: 5 582

    7

    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
    

    Shaggy

    Posted 2019-01-30T14:46:13.853

    Reputation: 24 623

    7

    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.

    Beefster

    Posted 2019-01-30T14:46:13.853

    Reputation: 6 651

    5

    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.

    Neil

    Posted 2019-01-30T14:46:13.853

    Reputation: 95 035

    5

    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!

    Kirill L.

    Posted 2019-01-30T14:46:13.853

    Reputation: 6 693

    5

    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.

    Titus

    Posted 2019-01-30T14:46:13.853

    Reputation: 13 814

    4

    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!

    cleblanc

    Posted 2019-01-30T14:46:13.853

    Reputation: 3 360

    265 bytes – ceilingcat – 2019-02-01T23:09:35.363

    4

    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!

    Oliver

    Posted 2019-01-30T14:46:13.853

    Reputation: 7 160

    4

    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!

    Jo King

    Posted 2019-01-30T14:46:13.853

    Reputation: 38 234

    4

    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!

    Level River St

    Posted 2019-01-30T14:46:13.853

    Reputation: 22 049

    4

    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"]
        )
    

    Max Yekhlakov

    Posted 2019-01-30T14:46:13.853

    Reputation: 601

    1Some 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=. – nimi – 2019-01-31T19:04:29.140

    ... All in all 215 bytes Try it online!

    – nimi – 2019-01-31T19:04:45.927

    1

    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!

    – nimi – 2019-02-01T17:14:40.690

    4

    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.

    Neil

    Posted 2019-01-30T14:46:13.853

    Reputation: 95 035

    3

    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!

    Luis felipe De jesus Munoz

    Posted 2019-01-30T14:46:13.853

    Reputation: 9 639

    1Te second T on the 3rd line of each verse should be lowercase. – Shaggy – 2019-01-31T14:16:32.790

    3

    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.

    Artemis still doesn't trust SE

    Posted 2019-01-30T14:46:13.853

    Reputation: 525

    198 bytes – Sara J – 2019-03-30T09:06:57.390

    @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. – Artemis still doesn't trust SE – 2019-03-30T09:14:18.817

    @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 – ASCII-only – 2019-03-31T11:01:44.203

    193 – ASCII-only – 2019-03-31T11:05:10.893

    @ASCII-only I know, but I thought that python somehow made sure that they continued to refer to the same object. – Artemis still doesn't trust SE – 2019-03-31T21:56:59.440

    @ArtemisFowl why. that's counterintuitive – ASCII-only – 2019-03-31T23:51:48.443

    @ASCII-only I know, I just subconsciously assummed it. I never really thought about it. – Artemis still doesn't trust SE – 2019-04-01T18:53:36.590

    2

    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!

    Οurous

    Posted 2019-01-30T14:46:13.853

    Reputation: 7 916

    2

    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.

    Neil

    Posted 2019-01-30T14:46:13.853

    Reputation: 95 035

    2

    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
    

    Stephen

    Posted 2019-01-30T14:46:13.853

    Reputation: 12 293

    2

    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!

    Xcali

    Posted 2019-01-30T14:46:13.853

    Reputation: 7 671

    194? – ASCII-only – 2019-01-31T08:25:58.310

    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. – Xcali – 2019-01-31T23:59:32.690

    190? – ASCII-only – 2019-02-01T00:00:59.810

    well this didn't work. neither did this – ASCII-only – 2019-02-01T00:17:36.177

    closer – ASCII-only – 2019-02-01T00:23:30.317

    also, just realized there's a 154 byte answer lol – ASCII-only – 2019-02-01T00:30:20.463

    :), i didn't see this answer before posting – Nahuel Fouilleul – 2019-02-01T10:05:16.570

    That's OK. Yours is a lot better. That's what I was trying to get to, but wasn't able to figure it out. – Xcali – 2019-02-01T16:09:57.823

    2

    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.

    dana

    Posted 2019-01-30T14:46:13.853

    Reputation: 2 541

    1I'm sorry to have reminded you that it exists :o) – Sok – 2019-01-31T08:21:53.967

    .Any() -> !=""? – ASCII-only – 2019-02-01T01:42:53.297

    also 223 – ASCII-only – 2019-02-01T01:44:32.920

    and you don't need the space after in in the foreach >_> – ASCII-only – 2019-02-01T01:50:47.217

    @ASCIIOnly - Thanks for the tips :) – dana – 2019-02-01T04:34:37.317

    220 bytes by getting rid of foreach – my pronoun is monicareinstate – 2019-09-07T06:52:21.843

    @someone - nice trick and glad to see one of my old answers getting some attention. – dana – 2019-09-07T12:09:35.227

    2

    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)

    Beefster

    Posted 2019-01-30T14:46:13.853

    Reputation: 6 651

    2

    ///, 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 /// 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
    

    Tanner Swett

    Posted 2019-01-30T14:46:13.853

    Reputation: 531

    2

    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

    sheß

    Posted 2019-01-30T14:46:13.853

    Reputation: 241

    1

    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) ...

    Olivier Dulac

    Posted 2019-01-30T14:46:13.853

    Reputation: 209

    1

    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!

    Destroigo

    Posted 2019-01-30T14:46:13.853

    Reputation: 401

    3Unfortunately your answer is currently invalid, as it doesn't repeat the first line of each verse. – Sok – 2019-01-30T22:57:06.953

    Missed it! Now fixed, ty Sok. – Destroigo – 2019-01-31T15:18:04.600

    Really liked the "oi"[1/k] part for switching between on/in. Ty recursive. – Destroigo – 2019-02-01T14:30:01.573

    1

    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!

    Java Gonzar

    Posted 2019-01-30T14:46:13.853

    Reputation: 173

    there are two problems the spaces before the commas and the uppercase after comma, otherwise you can check translation of my answers 282 bytes

    – Nahuel Fouilleul – 2019-01-31T15:14:20.720

    1269 bytes using lambda notation – Nahuel Fouilleul – 2019-01-31T15:18:22.040

    @Shaggy You are right, it is fixed now :) – Java Gonzar – 2019-01-31T17:21:51.297

    @NahuelFouilleul 264 bytes

    – Kevin Cruijssen – 2019-02-01T18:47:28.183

    261 bytes – ceilingcat – 2019-02-01T23:04:34.433

    Good for you guys :) – Java Gonzar – 2019-02-04T08:49:41.067

    1

    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

    Sara J

    Posted 2019-01-30T14:46:13.853

    Reputation: 2 576