|
| 1 | +package house |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | +) |
| 6 | + |
| 7 | +func Verse(v int) string { |
| 8 | + rhyme := "This is the " |
| 9 | + end := verses[0].object + " that " + verses[0].action + "." |
| 10 | + |
| 11 | + if v == 1 { |
| 12 | + return rhyme + end |
| 13 | + } |
| 14 | + |
| 15 | + rhyme += verses[v-1].object |
| 16 | + for ; v > 1; v-- { |
| 17 | + rhyme += "\nthat " + verses[v-1].action + " the " |
| 18 | + |
| 19 | + if v-1 == 1 { |
| 20 | + rhyme += end |
| 21 | + } else { |
| 22 | + rhyme += verses[v-2].object |
| 23 | + } |
| 24 | + } |
| 25 | + return rhyme |
| 26 | +} |
| 27 | + |
| 28 | +func Song() string { |
| 29 | + allverses := []string{} |
| 30 | + |
| 31 | + for v := 1; v <= len(verses); v++ { |
| 32 | + allverses = append(allverses, Verse(v)) |
| 33 | + } |
| 34 | + return strings.Join(allverses, "\n\n") |
| 35 | +} |
| 36 | + |
| 37 | +var verses = []verse{ |
| 38 | + verse{object: "house", action: "Jack built"}, |
| 39 | + verse{object: "malt", action: "lay in"}, |
| 40 | + verse{object: "rat", action: "ate"}, |
| 41 | + verse{object: "cat", action: "killed"}, |
| 42 | + verse{object: "dog", action: "worried"}, |
| 43 | + verse{object: "cow with the crumpled horn", action: "tossed"}, |
| 44 | + verse{object: "maiden all forlorn", action: "milked"}, |
| 45 | + verse{object: "man all tattered and torn", action: "kissed"}, |
| 46 | + verse{object: "priest all shaven and shorn", action: "married"}, |
| 47 | + verse{object: "rooster that crowed in the morn", action: "woke"}, |
| 48 | + verse{object: "farmer sowing his corn", action: "kept"}, |
| 49 | + verse{object: "horse and the hound and the horn", action: "belonged to"}, |
| 50 | +} |
| 51 | + |
| 52 | +type verse struct { |
| 53 | + object string |
| 54 | + action string |
| 55 | +} |
0 commit comments