Sha256: 838b525d20dc6272432f3a2b44cd0d8107b26f033acb0f42beb9adc3d750feed

Contents?: true

Size: 1.11 KB

Versions: 44

Compression:

Stored size: 1.11 KB

Contents

package house

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

func Verse(subject string, relPhrases []string, nounPhrase string) string {
	return subject + " " + recurse(relPhrases, nounPhrase)
}

func recurse(relPhrases []string, nounPhrase string) string {
	if len(relPhrases) == 0 {
		return nounPhrase
	}
	return Embed(relPhrases[0], recurse(relPhrases[1:], nounPhrase))
}

func Song() string {
	relPhrases := []string{
		"the horse and the hound and the horn\nthat belonged to",
		"the farmer sowing his corn\nthat kept",
		"the rooster that crowed in the morn\nthat woke",
		"the priest all shaven and shorn\nthat married",
		"the man all tattered and torn\nthat kissed",
		"the maiden all forlorn\nthat milked",
		"the cow with the crumpled horn\nthat tossed",
		"the dog\nthat worried",
		"the cat\nthat killed",
		"the rat\nthat ate",
		"the malt\nthat lay in",
	}
	subject := "This is"
	nounPhrase := "the house that Jack built."
	s := subject + " " + nounPhrase
	for c := len(relPhrases) - 1; c >= 0; c-- {
		s += "\n\n" + Verse(subject, relPhrases[c:], nounPhrase)
	}
	return s
}

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
trackler-2.0.5.7 tracks/go/exercises/house/example.go
trackler-2.0.5.6 tracks/go/exercises/house/example.go
trackler-2.0.5.5 tracks/go/exercises/house/example.go
trackler-2.0.5.4 tracks/go/exercises/house/example.go
trackler-2.0.5.3 tracks/go/exercises/house/example.go
trackler-2.0.5.2 tracks/go/exercises/house/example.go
trackler-2.0.5.1 tracks/go/exercises/house/example.go
trackler-2.0.5.0 tracks/go/exercises/house/example.go
trackler-2.0.4.0 tracks/go/exercises/house/example.go
trackler-2.0.3.9 tracks/go/exercises/house/example.go
trackler-2.0.3.8 tracks/go/exercises/house/example.go
trackler-2.0.3.7 tracks/go/exercises/house/example.go
trackler-2.0.3.6 tracks/go/exercises/house/example.go
trackler-2.0.3.5 tracks/go/exercises/house/example.go
trackler-2.0.3.4 tracks/go/exercises/house/example.go
trackler-2.0.3.3 tracks/go/exercises/house/example.go
trackler-2.0.3.2 tracks/go/exercises/house/example.go
trackler-2.0.3.1 tracks/go/exercises/house/example.go
trackler-2.0.3.0 tracks/go/exercises/house/example.go
trackler-2.0.2.0 tracks/go/exercises/house/example.go