Da ist ein Loch im Meeresboden

48

Während ich versuchte (und versagte), meinen kleinen Sohn zum Abendessen zu überreden, versuchte ich, ihm etwas vorzusingen. Auf halbem Weg durch dieses Lied wurde mir klar, dass sich die Formelstruktur gut zum Code-Golfen eignet!

Die Aufgabe besteht darin, ein Programm oder eine Funktion zu schreiben, die keine Eingabe akzeptiert und den folgenden Text erzeugt:

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

Herausforderungsregeln:

  • Der Text kann ausgedruckt oder als Funktionsausgabe zurückgegeben werden
  • Jeder Vers wird durch eine einzelne Leerzeile getrennt
  • Das nachgestellte Leerzeichen ist in Ordnung, solange das Layout nicht geändert wird (also kein führendes Leerzeichen oder zusätzliche Leerzeichen zwischen Wörtern).
  • Nachgestellte Zeilenumbrüche sind ebenfalls in Ordnung.
  • Keine führenden Zeilenumbrüche.
  • Alle Sprachen sind willkommen, und das ist , also gewinnt die kürzeste Antwort in Bytes für jede Sprache!
Sok
quelle
6
Ähnlich wie Es gab eine alte Dame (andere ähnliche Herausforderungen, z. B. diese wurden als Duplikate geschlossen, obwohl ich nicht denke, dass sie unbedingt sollten.)
Jonathan Allan
6
Ho, ro, das Klappermoor, das Moor unten im Tal.
30.
4
Zum Vergleich (obwohl keine Programmiersprache) gzip -5komprimiert es auf 186 Bytes ( bzip2und xzscheint es noch schlimmer zu machen).
Daniel Schepler
2
Herzlichen Glückwunsch von einem anderen Entwickler Eltern :)
AJFaraday
1
Ich möchte dieses Lied an 05AB1E anpassen ... "Es gibt ein Loch in oh-five-ay-bee-one-ee!"
Magic Octopus Urn

Antworten:

23

SOGL , 103 94 93 Bytes

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

Probieren Sie es hier aus!

...‘                 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
quelle
14
Aber ... aber wie?
SomeShinyObject
8
Unglaublich. Wie auch ...
Austin Burk
1
HNQ schlägt wieder zu! : \
Shaggy
4
Würde es Ihnen etwas ausmachen, eine Erklärung hinzuzufügen? Neugierig, wie es funktioniert.
Kevin Cruijssen
@ KevinCruijssen hinzugefügt
dzaima
19

Stax , 90 87 75 Bytes

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

Führen Sie es aus und debuggen Sie es

Ausgepackt, ungolfed und kommentiert sieht es so aus.

`;$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

Führen Sie dieses aus

rekursiv
quelle
2
Würde es Ihnen etwas ausmachen, eine Erklärung hinzuzufügen? Neugierig, wie es funktioniert.
Kevin Cruijssen
Ich werde es tun, aber ich habe immer noch das Gefühl, dass ein völlig anderer Ansatz es besser machen wird. Wenn mir das gelingt oder nicht gelingt, erkläre ich, was noch übrig ist.
rekursiver
1
@ KevinCruijssen: Ich hatte das Gefühl, dass es einen viel besseren Ansatz gibt. Klar, ich habe es komplett neu geschrieben und weitere 12 Bytes an Aufblähung gespart. Ich habe auch eine Erklärung hinzugefügt.
rekursiver
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
quelle
5
There's a bottom of the sea. Die Fakten überprüfen, +1
Jo King
:), es gibt auch diese Variante beginnend mit, There's a seaaber es ist länger
Nahuel Fouilleul
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:]

Probieren Sie es online!

Alte Alternativen zu 'io'['g'in s](13 Bytes):

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

Gerettet:

  • -1 Byte, danke an Jonathan Allan
  • -1 Byte, danke an Rod
  • -1 Byte, danke an Erik den Outgolfer
TFeld
quelle
"hole, t%shole\n"%a[1:]speichert ein Byte
Jonathan Allan
Sie können ein Byte speichern, indem Sie den zip
Rod
@ JonathanAllan Danke :)
TFeld
@ Rod Danke, :-)
TFeld
'oi'[s[5]<'n']wird auch eine alte Alternative sein: Featuring 'io'['g'in s]!
Erik der Outgolfer
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, danke an Daniel Schepler
-10 Bytes, danke an ceilingcat

Probieren Sie es online!

Giacomo Garabello
quelle
2
Könnten Sie ,*b="_TH<0$\31\r"stattdessen schreiben ?
Daniel Schepler
Würde es irgendwelche Bytes speichern, um "in" zu definieren?
OldBunny2800
@ OldBunny2800 nein, es wäre länger ! in diesem Fall müssen Sie mindestens 6 Vorkommen wirksam sein ...
Giacomo Garabello
12

05AB1E , 103 100 99 97 96 93 92 Bytes

Dank Kevin Cruijssen ein Byte gespart

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

Probieren Sie es online!

Erläuterung

“¥ÊˆŽ bumpÑå‡îtíÁ¤†îÌea¹²“#vstartet eine Schleife über der Liste ["hole", "log", "bump", "frog", "wart", "hair", "fly", "flea", "smile"]. Die Wörter werden mit dem Wörterbuch 05AB1E komprimiert.

Bei jedem machen wir:

’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
quelle
2
Sie können das führende entfernen õ, da es anscheinend standardmäßig eine leere Zeichenfolge ausgibt, wenn ein sWAP mit nichts auf dem Stapel verwendet wird . Ich konnte nichts anderes zum Golfen finden; sehr nette antwort!
Kevin Cruijssen
1
@ KevinCruijssen: Oh ja, ich habe das nicht in Betracht gezogen, da es normalerweise Eingaben gibt. Danke :)
Emigna
11

PowerShell , 194 188 185 180 174 Byte

$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
"}

Probieren Sie es online!

Kann nicht ganz scheinen, Python zu fangen ...

Grundsätzlich setzt ein paar gemeinsame Zeichenketten $h, $a, $z, und $b, dann durch eine Schleife durch jedes der Elemente geht ( hole, log... flea, smile), wobei jede Iteration die entsprechende verse ausgibt. Es gibt ein bisschen Logik !$j++in der Mitte, um den in/ on-Schalter zu erklären , der passiert. Andernfalls Write-Outputverbleiben alle Zeichenfolgen in der Pipeline, und die Standardeinstellung gibt uns kostenlose Zeilenumbrüche.

-6 Bytes dank Arnauld.
-3 Bytes dank mazzy.
-5 Bytes dank Veskah.
-6 bytes dank mazzy.

AdmBorkBork
quelle
-3 Bytes :) Probieren Sie es online!
mazzy
@mazzy Das ist ein kluger Trick. Das muss ich mir merken, denn ich benutze -splitziemlich viel, um Worte zu finden.
AdmBorkBork
180 Bytes
Veskah
9

JavaScript (ES6),  201 194 189 188  187 Bytes

1 Byte dank @Shaggy gespeichert

_=>`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`)

Probieren Sie es online!


JavaScript (ES6), 235 Byte

Einfach neu verpackt .

_=>[..."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`)

Probieren Sie es online!

Arnauld
quelle
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

Übersetzt von meiner anderen Antwort in Perl.

Nahuel Fouilleul
quelle
7

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

Es stellt sich heraus, dass es unglaublich schwierig ist, eine Herausforderung beim Komprimieren von Saiten zu spielen, während Sie auf Ihrem Handy den Boozer runterfahren - wer hätte gedacht ?!

`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

Probier es aus

                                              :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
Zottelig
quelle
7

XML, 719 673 603 514 493 486 Byte

<!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>

Sie können es mit "ausführen" xmlstarlet sel -t -m '//a' -v . -n <xml_file_here>.

Dies wäre viel einfacher, wenn XML nicht so ausführlich wäre, aber das ist weniger als 25% der Größe des Originaltexts.

Beefster
quelle
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 

Probieren Sie es online! Erläuterung:


THsmile oNflea oNfly oNhair oNwart oNfrog oNbump oNlog iNE

Füge den letzten Vers ein.

N
$&$'¶TH

Berechnen Sie alle Verse.

O^$`

Bringe die Verse in die richtige Reihenfolge.

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

Vervollständige jeden Vers und füge den Refrain hinzu.

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

Erweitern Sie einige Platzhalter.

Neil
quelle
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="")

Probieren Sie es online!

Kirill L.
quelle
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
";

Laufen Sie mit -nroder versuchen Sie es online .

Gibt Warnungen in PHP 7.2 aus; Um dies zu beheben, setzen Sie Anführungszeichen um
die Array - Elemente, io, holeund die zwei eigenständige T.

Titus
quelle
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));}

Probieren Sie es online!

Cleblanc
quelle
265 bytes
ceilingcat
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"}

Probieren Sie es online!

Scherzen
quelle
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

Probieren Sie es online!

Oliver
quelle
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

tEnthält eine Zeichenfolge, die im Refrain wiederholt wird. sEnthält den größten Teil der Verszeile, während rzwischen in theund gewählt wird on the. In den Versen werden nur die ersten 11 Zeichen von tbenötigt, während in der ersten Refrainzeile die zweite Kopie von tdie TKleinbuchstaben hat und die zweite Refrainzeile die letzten 25 Zeichen von wiederverwendet s.

Neil
quelle
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}

Probieren Sie es online!

Level River St
quelle
4

Haskell , 243 215 Bytes

Mit Hilfe von Nimi auf 215 Byte reduziert

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

Probieren Sie es online!

(Alte 243-Byte-Version ist hier ).

Eine recht unkomplizierte Lösung.

-- 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
quelle
1
Einige Tipps: a) Sie verwenden snur einmal, damit Sie es inline können. b) Sie immer prepend und Anfügen etwas zu t, so kann man es sich um eine (Infix) Funktion machen: t#u=t:"here's a "++u. c) Die Erstellung der großen Liste in Funktion lmit map(++" on the ")(words"smile flea ..."ist kürzer. Außerdem: Verschieben Sie alles, was an diese Liste angehängt ist, in die Liste. d) Die Liste der Nummern, die gelöscht werden sollen, läuft jetzt von 8unten nach unten 0(einstellige Nummern!). e) Jetzt werden iauch einige Bytes gespeichert. f) Sie müssen Ihre Hauptfunktion nicht benennen. Gemäß unserer Meta werden Haskell-Werte als ordnungsgemäße Funktionen angesehen v=.
nimi
... Alles in allem 215 Bytes Probieren Sie es online!
nimi
1
Weitere 3 Bytes zum Speichern: Anstelle des Listenverständnisses können Sie >>=(concatMap) aus der Liste Monade und Inline concatin Funktion verwenden l. Probieren Sie es online!
nimi
3

JavaScript (Babel Node) , 239 Bytes

-7 Bytes von @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`
`

Probieren Sie es online!

Luis Felipe De Jesus Munoz
quelle
1
Die Sekunde Tin der dritten Zeile jedes Verses sollte in Kleinbuchstaben geschrieben sein.
Shaggy
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)

Probieren Sie es online!


-15 Bytes dank @Sara
-5 Bytes dank nur @ ASCII

Wahrscheinlich ein bisschen mehr Golf, aber nicht viel.

Artemis Fowl
quelle
198 Bytes
Sara J
@ SaraJ Danke. Ich war unter dem (eindeutig falsch) Eindruck , dass o=e=beide machen würde ound ebeziehen sich auf das gleiche Objekt. Ich dachte auch, Split würde länger dauern.
Artemis Fowl
@ArtemisFowl ound e sie beziehen sich auf das gleiche Objekt ... es ist nur , dass Strings in Python unveränderlich sind so Dinge wie +=eine neue Kopie erstellen , anstatt von Mutieren der bestehenden
ASCII-only
193
Nur ASCII
@ ASCII-only Ich weiß, aber ich dachte, dass Python irgendwie dafür gesorgt hat, dass sie sich weiterhin auf dasselbe Objekt beziehen.
Artemis Fowl
2

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

Probieren Sie es online!

Οurous
quelle
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"

Probieren Sie es online!

Diese Herausforderung brachte mich dazu, endlich Listen und Zeichenketten in meiner Sprache zu implementieren. Diese Sprache ist für ganzzahlige Sequenzen gebaut, also hat es ziemlich gut geklappt!

Erläuterung

:"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
quelle
2

Perl 5 , 194 Bytes

@ ASCII-only 6 Bytes mit wörtlichen Zeilenumbrüchen und einem \lTrick, den ich vergessen habe, abgeschnitten

$"=" 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/)

Probieren Sie es online!

Xcali
quelle
194?
Nur ASCII-
Jep. Gute Arbeit. Ich hätte mich mit Sicherheit an die Zeilenumbrüche erinnern sollen. Ich habe das \lvorher gesehen, hatte aber nie einen Grund, es zu benutzen, also habe ich nie daran gedacht.
Xcali
190?
Nur ASCII
näher
ASCII
2

Charcoal , 115 106 Bytes

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

Probieren Sie es online! Link ist eine ausführliche Version des Codes. Edit: 9 Bytes durch Kopieren meines Batch-Codes für die letzte Zeile des Refrains gespeichert. Erläuterung:

≔There's a holeθ

Speichern Sie die Zeichenfolge There's a hole, die zweimal unverändert verwendet wird, ein drittes Mal in Kleinbuchstaben und ein viertes Mal, aber nur die ersten 10 Zeichen.

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

Teilen Sie die Zeichenfolge bottom of the seaxhole ixlog ixbump oxfrog oxwart oxhair oxfly oxflea oxsmile oauf xs.

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

Durchlaufen Sie die 9 Verse, nehmen Sie die ersten i+2Elemente des Arrays, kehren Sie sie um, fügen Sie sie zusammen n theund stellen Sie There's adem Ergebnis ein Präfix voran .

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

Erweitern Sie jede Zeile zu einem Vers, indem Sie die Zeile duplizieren und den Refrain konstruieren. Jede Zeile des Verses wird dann implizit auf jede eigene Zeile gedruckt, und jeder Vers wird implizit durch eine Leerzeile getrennt.

Neil
quelle
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ñ

Probieren Sie es online!

Erläuterung:

  • 4iThere's a hole in the bottom of the sea<\n><esc> Füge 4 Mal "Theres 'ein Loch in den Grund des Meeres" ein.
  • kk Gehen Sie in die dritte Zeile
  • y5w Kopie "Da ist ein Loch"
  • 5eá, Nach "Da ist ein Loch" ein Komma einfügen
  • lp Einfügen nach dem Komma
  • D Löschen Sie den Rest der Zeile
  • 5brt Kleinbuchstaben das zweite T
  • Hj4yy Kopieren Sie 4 Zeilen aus der zweiten Zeile
  • Gp Fügen Sie alles nach der ersten Zeile ein
  • 4w8ion the <esc>(am Ende des ersten Verses) gehe zum ersten "Loch" im zweiten Vers und füge "auf" das Achtfache ein
  • 2briilog <esc> gehe zurück zum letzten "on", ersetze das o mit einem i und füge dann "log" ein
  • 3bibump <esc>3bifrog <esc>3biwart <esc>3bihair <esc>3bifly <esc>3biflea <esc>3bismile <esc> Gehen Sie rückwärts durch die Zeile und fügen Sie die entsprechenden Wörter zwischen den einzelnen "auf der" ein.
  • 7ñ4yykp4wd3wñ4yykp4wd3w7 mal ausführen
    • 4yykp duplizieren Sie den Vers vor diesem
    • 4wd3w gehe zum ersten Wort nach "Da ist ein Loch" und lösche 3 Wörter
  • 8ñÄ5jñ Dupliziere die erste Zeile jedes Verses nach der ersten (es gibt 8 davon zu tun)
Beefster
quelle
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

Probieren Sie es online!

Diese Art von Aufgabe ist das Einzige, was /// einigermaßen gut kann. : D Hey, das Ergebnis ist kürzer als C, C # oder Java!

Die Ausgabe dieses Programms endet in zwei nachgestellten Zeilenumbrüchen. Ich hoffe, das ist kein Deal-Breaker.

Jedenfalls gibt es hier keine wirkliche Klugheit. Ich identifizierte einfach wiederholte Zeichenfolgen und definierte Ein-Zeichen-Verknüpfungen für sie und wiederholte, bis ich keine wiederholten Zeichenfolgen mehr sah. Ich habe das mehr oder weniger naiv und gierig gemacht. Ich habe jedoch absichtlich eine Abkürzung für "Lächeln auf dem Floh auf dem ... Meer" definiert, gefolgt von "Floh auf dem ... Meer" und so weiter, um eine Kette von Abkürzungen zu bilden . Das Ergebnis ist, dass die gesamte Abfolge neuer Substantive im Code deutlich sichtbar ist, und das finde ich ziemlich erfreulich. :)

Nach dem Ersetzen von V und U haben wir den folgenden besser lesbaren 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
quelle
2

LaTeX, 265 268 Zeichen

\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

Kompiliert ein nettes PDF mit Absatzeinrückungen und allem.

Ungolfed und kommentiert:

\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

Der Ausgabe:

Bildbeschreibung hier eingeben

sheß
quelle
2

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

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

Probieren Sie es online!

-5 Bytes dank @ASCIIOnly und -2 Bytes dank @someone!

Ich habe ein kleines Kind und kann Ihnen versichern, dass dieses Lied zu gleichen Teilen eingängig und nervig ist.

Dana
quelle
1
Es tut mir leid, Sie daran erinnert zu haben, dass es existiert: o)
Sok
.Any()-> !=""?
Nur ASCII
auch 223
ASCII
und du brauchst das Leerzeichen nicht danach inin der foreach> _>
ASCII-only
@ASCIIOnly - Danke für die Tipps :)
Dana