4
\$\begingroup\$

This question already has an answer here:

So, there's a famous children's rhyme...

This is the house that Jack built.

This is the malt 
That lay in the house that Jack built.

This is the rat 
That ate the malt
That lay in the house that Jack built.

This is the cat 
That killed the rat
That ate the malt 
That lay in the house that Jack built.

This is the dog 
That worried the cat
That killed the rat 
That ate the malt
That lay in the house that Jack built.

This is the cow with the crumpled horn
That tossed the dog 
That worried the cat
That killed the rat 
That ate the malt
That lay in the house that Jack built.

This is the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog that worried the cat
That killed the rat that ate the malt
That lay in the house that Jack built.

This is the man all tattered and torn
That kissed the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog that worried the cat
That killed the rat that ate the malt
That lay in the house that Jack built.

This is the judge all shaven and shorn
That married the man all tattered and torn
That kissed the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog 
That worried the cat
That killed the rat 
That ate the malt
That lay in the house that Jack built.

This is the rooster that crowed in the morn
That woke the judge all shaven and shorn
That married the man all tattered and torn
That kissed the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog 
That worried the cat
That killed the rat 
That ate the malt
That lay in the house that Jack built.

This is the farmer sowing his corn
That kept the rooster that crowed in the morn
That woke the judge all shaven and shorn
That married the man all tattered and torn
That kissed the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog 
That worried the cat
That killed the rat 
That ate the malt
That lay in the house that Jack built.

This is the horse and the hound and the horn
That belonged to the farmer sowing his corn
That kept the rooster that crowed in the morn
That woke the judge all shaven and shorn
That married the man all tattered and torn
That kissed the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog 
That worried the cat
That killed the rat 
That ate the malt
That lay in the house that Jack built.

Obviously, it's pretty process-based, you could totally write code for this, right?


  • Write some code which outputs the full text of "The house that Jack built".
  • Standard rules and loopholes and stuff.
  • Any language you like.
  • Try to do it in the smallest number of bytes.
  • I always like to see TIO links.
  • The case must match the rhyme.
  • Each line of the rhyme must be on a new line of text.
  • White-space before and after the line is fine.
  • No punctuation, except the full stop at the end of each verse.

Edit:

Earlier versions of this question contained an issue with this line

This is the rooster that crowed the morn

It was inconsistently applied.

To be clear; this should be one line on every occurrence, and should be added at once.


Further edit:

It's been declared that this question is a duplicate of:

We're no strangers to code golf, you know the rules, and so do I

However, while you could take the same approach, compressing the text as much as possible. There's also a chance to take a procedural approach to this rhyme, following the structure of the rhyme itself. Some of the solutions take this approach, so I'd say it is a similar, but distinct challenge for this reason.

This answer suggests that it's actually better to take the approach to this question which would not work for Rick Astley.

It is, however, a duplicate of the old lady song, and the 12 days of Christmas. I've voted to close it. (although, those two were not declared duplicate of each other).

\$\endgroup\$

marked as duplicate by AJFaraday, user202729, caird coinheringaahing, Toto, Stephen Leppik Apr 12 '18 at 12:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ Related \$\endgroup\$ – Shaggy Apr 12 '18 at 10:38
  • \$\begingroup\$ If another KC challenge is found with text that is accumulating prefixing or suffixes, I'd consider that a duplicate. \$\endgroup\$ – xnor Apr 12 '18 at 11:11
  • \$\begingroup\$ Related accumulating KC poem, possible duplicate. Also related. \$\endgroup\$ – xnor Apr 12 '18 at 11:20
  • \$\begingroup\$ @xnor Fair play, looks like a duplicate to me. \$\endgroup\$ – AJFaraday Apr 12 '18 at 11:21
  • \$\begingroup\$ As @user202729 said, your rule "Each line of the rhyme must be on a new line of text." and the lines with dog, cat, rat, and malt in the verses of the man and maiden contradict each other (and also make every current answer invalid except for the encoded ones. I would suggest putting those that ... on newline That ... as well to keep things in the same pattern, or add a rule in bold to make it clearly those two verses are different from the rest of the rhyme. \$\endgroup\$ – Kevin Cruijssen Apr 12 '18 at 12:38
4
\$\begingroup\$

JavaScript (ES6), 356 bytes

Procedural approach.

_=>`house th5 Jack built.
|malt6lay in|r565e|c56kill2dog6worri2cow with0crumpled h16toss2maiden3forl16milk2man3t5tered4 t16kiss2judge3shaven4 sh16marri2rooster6crowed in0m16woke|farmer sowing his c16kept|horse40hound40h16belonged to`.replace(/\d/g,n=>` the ,orn,ed|, all , and,at,
That `.split`,`[n]).split`|`.map(s=>`This is`+(p=' the '+s+p),p='').join`
`

Try it online!


Simple compression, 429 bytes

Using RegPack.

_=>[...'IKLMNOPQRSUVWXYZ[]^_0qxz{}~'].reduce((s,c)=>(l=s.split(c)).join(l.pop()),`TNis_ZOlt }{rQ z^}{cQ Sz^ }KM}]M}xI[I~Z0ZYZLrseULundU{hWbelongV toY~{judgeRshavenU shWmarriV[MP}PZ{ the z
ThQ xOidenRforlWmilkV]qworriV{cQS 0{rooster XcrowV in{mWwoke~_Luse XJack built.^QeOlt]{cow with{crumplV hWtossVK[OnRtQterVU tWkissVxZ

TNisY{farmer sowing NcWkept0XthQ WornzVedU andSzkillV{rQR all QatPzlay in_O{maNhis Mzqz^L{hoK{dog IXqX^}`)

Try it online!

\$\endgroup\$
  • 1
    \$\begingroup\$ Lol, common Arnauld, you can do much better than this. ;) \$\endgroup\$ – Kevin Cruijssen Apr 12 '18 at 9:32
  • \$\begingroup\$ @KevinCruijssen Actually, my first guess is that a procedural approach would not be much shorter. (At least in JS and without a dictionary.) \$\endgroup\$ – Arnauld Apr 12 '18 at 9:38
  • 1
    \$\begingroup\$ @KevinCruijssen Finally saved ~19% with the procedural approach, which is better than I expected. \$\endgroup\$ – Arnauld Apr 12 '18 at 11:11
  • \$\begingroup\$ "Each line of the rhyme must be on a new line of text." This is not the case here. Any online diff tool will show it. \$\endgroup\$ – Olivier Grégoire Apr 12 '18 at 12:34
  • \$\begingroup\$ No, I don't care about which line feed is used. However... some verses have That tossed the dog that worried the cat and your output is That tossed the dog\nThat worried the cat. Same for the rat/malt line: some verses don't separate those. \$\endgroup\$ – Olivier Grégoire Apr 12 '18 at 12:58
2
\$\begingroup\$

Python 2, 398 397 bytes

for i in range(12):print'\nThis is the',''.join(dict(zip('012345','\nThat , the ,orn,ed, all , and'.split(','))).get(c,c)for c in'1'.join('horse51hound51h20belong3 to|farmer sowing his c20kept|rooster that crow3 in1m20woke|judge4shaven5 sh20marri3|man4tatter35 t20kiss3|maiden4forl20milk3|cow with1crumpl3 h20toss3|dog0worri3|cat0kill3|rat0ate|malt0lay in|house that Jack built.'.split('|')[~i:]))

Try it online!


Python 2, 401 398 bytes

for i in range(12):print'\nThis is the',' the '.join('horse and the hound and the horn?belonged to|farmer sowing his corn?kept|rooster that crowed in the morn?woke|judge all shaven and shorn?married|man all tattered and torn?kissed|maiden all forlorn?milked|cow with the crumpled horn?tossed|dog?worried|cat?killed|rat?ate|malt?lay in|house that Jack built.'.split('|')[~i:]).replace('?','\nThat ')

Try it online!


Saved

  • -3 bytes, thanks to Jonathan Frech
\$\endgroup\$
  • \$\begingroup\$ Though would not print'\nThis is the' be shorter than +'\n'? \$\endgroup\$ – Jonathan Frech Apr 12 '18 at 10:46
  • \$\begingroup\$ @JonathanFrech Yeah, thanks :) \$\endgroup\$ – TFeld Apr 12 '18 at 10:52
2
\$\begingroup\$

05AB1E, 256 245 241 bytes

“x´ž€†0ƒé€Š Jackíš.xâì0íàltx¨Ù0ÄŠxܳ0—Äx€„ssed0‹·x«Ëed0Ч€Ž0 crumpledÑÛx·—ed0움Ÿ€‡lornx¢¢0…Ž€Ÿ»ättered€ƒ€„rnx woke0¡Ë€Ÿ shaven€ƒ shornx¤°0ÝËoster€Š crowed€†0›árnxÊÂed€„0ÃË€Êwing€ËÃÅx0ƒ0 hound€ƒ0ÑÛ“0’ €€’:'x¡'€Š™ìηʒRćD'€€kG¦}„€Œ€ˆªì¸ì»¶«,

Try it online!

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

Java 8, 666 649 640 636 625 bytes

$->{String y="This is",x="That ",w="orn\n",A="~house that Jack built.\n\n",B="~malt\n",D="~rat\n",F="~cat\n",H="~dog\n",J="~cow with~crumpled h"+w,L="~maiden all forl"+w,N="~man all tattered and t"+w,P="~judge all shaven and sh"+w,R="~rooster that crowed in~m"+w,T="~farmer sowing his c"+w,r=y+A,a[]={B,"lay in"+A,D,"ate"+B,F,"killed"+D,H,"worried"+F,J,"tossed"+H,L,"milked"+J,N,"kissed"+L,P,"married"+N,R,"woke"+P,T,"kept"+R,"~horse and~hound and~h"+w,"belonged to"+T};for(int i:"123425642786429:8642;<:8642=><:8642?@><:8642AB@><:8642CDB@><:8642EFDB@><:8642".getBytes())r+=(i%2>0?y:x)+a[i-49];return r.replace("~"," the ");}

Well..

NOTE: It's just like every other (non-encoded) answer incorrect for the verses about the maiden and man, where the lines of the dog and cat, as well as rat and malt are on a single line, instead of new-line separated.. I'm just too lazy to fix it, since it's closed as a dupe anyway.

Explanation:

Try it online.

$->{                  // Method with empty unused parameter and String return-type
  String y="This is", //  Temp-String "This is"
         x="That ",   //  Temp-String "That "
         w="orn\n",   //  Temp-String "orn\n"
                      //  " the ...\n" temp Strings:
  A="~house that Jack built.\n\n",
  B="~malt\n",
  D="~rat\n",
  F="~cat\n",
  H="~dog\n",
  J="~cow with~crumpled h"+w,
  L="~maiden all forl"+w,
  N="~man all tattered and t"+w,
  P="~judge all shaven and sh"+w,
  R="~rooster that crowed in~m"+w,
  T="~farmer sowing his c"+w,
  r=y+A,              //  Result-String, starting at:
                      //   This is the house that Jack built.\n\n
  a[]={               //  String-array, containing:
    B,                //   the malt\n
    "lay in"+A,       //   lay in the house that Jack built.\n\n
    D,                //   the rat\n
    "ate"+B,          //   ate the malt\n
    F,                //   the cat\n
    "killed"+D,       //   killed the rat\n
    H,                //   the dog\n
    "worried"+F,      //   worried the cat\n
    J,                //   the cow with the crumpled horn\n
    "tossed"+H,       //   tossed the dog\n
    L,                //   the maiden all forlorn\n
    "milked"+J,       //   milked the cow with the crumpled horn\n
    N,                //   the man all tattered and torn\n
    "kissed"+L,       //   kissed the maiden all farlorn\
    P,                //   the judge all shaven and shorn\n
    "married"+N,      //   married the man all tattered and torn\n
    R,                //   the rooster that crowed in the morn\n
    "woke"+P,         //   woke the judge all shaven and shorn\n
    T,                //   the farmer sowing his corn\n
    "kept"+R,         //   kept the rooster that crowed in the morn\n
    "~horse and~hound and~h"+w,
                      //   the horse and the hound and the horn\n
    "belonged to"+T}; //   belonged to the farmer sowing his corn\n
  for(int i:"123425642786429:8642;<:8642=><:8642?@><:8642AB@><:8642CDB@><:8642EFDB@><:8642".getBytes())
                      //  Loop over the bytes of the String above
    r+=(i%2>0?y       //   If `i` is odd: Append "This is "
        :x)           //   Else (`i` is even): Append "That " instead
       +a[i-49];      //   And also append the string from the array at index `i-49`
  return r.replace("~"," the ");}
                      //  Return the result, with all "~" replaced with " the "
\$\endgroup\$
  • \$\begingroup\$ If you use a diff tool (such as DiffChecker), you'll see several differences between your text and the original one. \$\endgroup\$ – Olivier Grégoire Apr 12 '18 at 12:32
  • \$\begingroup\$ @OlivierGrégoire Yeah, noticed that as well after I saw user202729's comment. Since it's closed as dupe, and every answer except for the two encoded ones have the same issue I just ignored it for now.. \$\endgroup\$ – Kevin Cruijssen Apr 12 '18 at 12:40
  • 1
    \$\begingroup\$ There's also a "belonged the" that should be "belonged to the". \$\endgroup\$ – Olivier Grégoire Apr 12 '18 at 12:43
  • \$\begingroup\$ @OlivierGrégoire Fixed. \$\endgroup\$ – Kevin Cruijssen Apr 12 '18 at 12:45
1
\$\begingroup\$

Retina, 322 308 bytes


0horse20hound20h3belonged to0farmer sowing his c3kept0rooster that crowed in0m3woke0judge all shaven2 sh3married0man all tattered2 t3kissed0maiden all forl3milked0cow with0crumpled h3tossed0dog1worried0cat1killed0rat1ate0malt1lay in0house that Jack built.
3
orn1
1
¶That 
L^$`0.*
This is$&$'¶
2
 and
0
 the 

Try it online!

\$\endgroup\$
  • \$\begingroup\$ @AJFaraday Sorry, it must have broken during golfing \$\endgroup\$ – Neil Apr 12 '18 at 11:12
  • \$\begingroup\$ @AJFaraday Thanks, I see the problem now, should be fixed. \$\endgroup\$ – Neil Apr 12 '18 at 11:13
1
\$\begingroup\$

Jstx, 293 bytes

↕Δ"▌ÇÇÉÇ◙ëÇÇÇÇÇÇǬÜëºΣ£•☼▀2.─&│E╧=▒√║∙►ybⁿ☯╫QΔ(☺¥ë2↕☯k`u3xò6┘[↨:ªh°♀êΔ╘δ‼δ@W$A⌐ΘsΘ↕║∞Φ⌡▌b⌐M±uc9╖#→δ¡9¼▀Ö╪♠¬╢æ¥.≈ëzTH♂⌡Q┐àÿî♥τ◄≈«‼û4_≤╛─◄→♂U┌█2Üüà╓ªçδ»Aÿ▄╜9■q▒iö♦4s⌐±[╗:áxÿº•╗.é÷╫╙σG¼╧[]┌>5←◙÷ö╣↨>≤±Bøz→▲√┐•♫◘╚←<∟⌡₧o?PB|Å╩↔Θ↨Γ»H☻▒╩z`6_ⁿ#∩⌂ε╦╬SNΦ9└├↓¥n-d┴≤α┐'F+~<,+╒↑│░»|M☯½☺E}°]dπ☻Ñö°á╠üdhP▼{Bßë

Try it online!

\$\endgroup\$

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