summaryrefslogtreecommitdiff
path: root/go/house/house.go
blob: c3b353a36e67781ed5a647b5adf3938556f50799 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package house

import "strings"

func Embed(relPhrase, nounPhrase string) string {
	return relPhrase + " " + nounPhrase
}

func Verse(subject string, relPhrases []string, nounPhrase string) string {
	return subject + " " + strings.Join(append(relPhrases, nounPhrase), " ")
}

var items = [][]string{
	{"lay in", "the house that Jack built."},
	{"ate", "the malt"},
	{"killed", "the rat"},
	{"worried", "the cat"},
	{"tossed", "the dog"},
	{"milked", "the cow with the crumpled horn"},
	{"kissed", "the maiden all forlorn"},
	{"married", "the man all tattered and torn"},
	{"woke", "the priest all shaven and shorn"},
	{"kept", "the rooster that crowed in the morn"},
	{"belonged to", "the farmer sowing his corn"},
	{"", "the horse and the hound and the horn"},
}

func Song() string {
	var s []string
	for k, v := range items {
		s = append(s, "This is "+v[1])
		for i := k - 1; i >= 0; i-- {
			s = append(s, "that "+strings.Join(items[i], " "))
		}
		if k != len(items)-1 {
			s = append(s, "")
		}
	}
	return strings.Join(s, "\n")
}