The house that Jack built

4

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

AJFaraday

Posted 2018-04-12T09:18:41.637

Reputation: 10 466

Question was closed 2018-04-12T12:08:06.280

Related – Shaggy – 2018-04-12T10:38:01.190

If another KC challenge is found with text that is accumulating prefixing or suffixes, I'd consider that a duplicate. – xnor – 2018-04-12T11:11:24.860

Related accumulating KC poem, possible duplicate. Also related. – xnor – 2018-04-12T11:20:09.617

@xnor Fair play, looks like a duplicate to me. – AJFaraday – 2018-04-12T11:21:59.313

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. – Kevin Cruijssen – 2018-04-12T12:38:33.717

@KevinCruijssen Dupe anyway? ... – user202729 – 2018-04-12T12:39:25.353

It is a duplicate – AJFaraday – 2018-04-12T12:39:37.973

@user202729 I know, that's also the reason why I haven't edited my answer yet. Ah well.. – Kevin Cruijssen – 2018-04-12T12:42:16.497

It was fun while it lasted. – AJFaraday – 2018-04-12T12:42:45.810

Answers

4

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!

Arnauld

Posted 2018-04-12T09:18:41.637

Reputation: 111 334

1Lol, common Arnauld, you can do much better than this. ;) – Kevin Cruijssen – 2018-04-12T09:32:56.183

@KevinCruijssen Actually, my first guess is that a procedural approach would not be much shorter. (At least in JS and without a dictionary.) – Arnauld – 2018-04-12T09:38:01.327

1@KevinCruijssen Finally saved ~19% with the procedural approach, which is better than I expected. – Arnauld – 2018-04-12T11:11:52.113

"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. – Olivier Grégoire – 2018-04-12T12:34:49.490

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. – Olivier Grégoire – 2018-04-12T12:58:12.173

@OlivierGrégoire Oh, I guess you're talking about the RegPack'ed version. It's based on the original version of the challenge and I didn't reflect the changes that were made afterwards. – Arnauld – 2018-04-12T13:06:02.370

@OlivierGrégoire (now fixed, saving 9 bytes) – Arnauld – 2018-04-12T13:13:04.127

2

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

TFeld

Posted 2018-04-12T09:18:41.637

Reputation: 19 246

Though would not print'\nThis is the' be shorter than +'\n'? – Jonathan Frech – 2018-04-12T10:46:49.253

@JonathanFrech Yeah, thanks :) – TFeld – 2018-04-12T10:52:32.510

2

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!

Emigna

Posted 2018-04-12T09:18:41.637

Reputation: 50 798

2

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 "

Kevin Cruijssen

Posted 2018-04-12T09:18:41.637

Reputation: 67 575

If you use a diff tool (such as DiffChecker), you'll see several differences between your text and the original one.

– Olivier Grégoire – 2018-04-12T12:32:18.443

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

– Kevin Cruijssen – 2018-04-12T12:40:03.563

1There's also a "belonged the" that should be "belonged to the". – Olivier Grégoire – 2018-04-12T12:43:51.633

@OlivierGrégoire Fixed. – Kevin Cruijssen – 2018-04-12T12:45:57.977

1

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!

Neil

Posted 2018-04-12T09:18:41.637

Reputation: 95 035

@AJFaraday Sorry, it must have broken during golfing – Neil – 2018-04-12T11:12:27.353

@AJFaraday Thanks, I see the problem now, should be fixed. – Neil – 2018-04-12T11:13:18.127

1

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!

Quantum64

Posted 2018-04-12T09:18:41.637

Reputation: 371