Sha256: 8eb11b99c705f8fa31f7d75bb2d12427da95cc5d13de64a96e4271f062e50be4

Contents?: true

Size: 1.45 KB

Versions: 122

Compression:

Stored size: 1.45 KB

Contents

package house

var songLines = []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",
}

// Recursive Solution

func Verse(v int) (verse string) {
	v--
	i := len(songLines) - v
	verse += buildVerse(songLines[i:], "This is ")
	verse += "the house that Jack built."
	return
}

func buildVerse(songLines []string, cur string) string {
	if len(songLines) == 0 {
		return cur
	}
	cur += songLines[0]
	cur += " "
	return buildVerse(songLines[1:], cur)
}

func Song() (song string) {
	for i := 0; i <= len(songLines); i++ {
		song += Verse(i + 1)
		if i < len(songLines) {
			song += "\n\n"
		}
	}
	return
}

// Iterative Solution

// func Verse(v int) (verse string) {
//     v--
//     verse += "This is "
//     verse += strings.Join(songLines[len(songLines)-v:], " ")
//     if v > 0 {
//         verse += " "
//     }
//     verse += "the house that Jack built."
//     return
// }
//
// func Song() (song string) {
//     for i := 0; i <= len(songLines); i++ {
//         song += Verse(i + 1)
//         if i < len(songLines) {
//             song += "\n\n"
//         }
//     }
//     return
// }

Version data entries

122 entries across 122 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/go/exercises/house/example.go
trackler-2.2.1.179 tracks/go/exercises/house/example.go
trackler-2.2.1.178 tracks/go/exercises/house/example.go
trackler-2.2.1.177 tracks/go/exercises/house/example.go
trackler-2.2.1.176 tracks/go/exercises/house/example.go
trackler-2.2.1.175 tracks/go/exercises/house/example.go
trackler-2.2.1.174 tracks/go/exercises/house/example.go
trackler-2.2.1.173 tracks/go/exercises/house/example.go
trackler-2.2.1.172 tracks/go/exercises/house/example.go
trackler-2.2.1.171 tracks/go/exercises/house/example.go
trackler-2.2.1.170 tracks/go/exercises/house/example.go
trackler-2.2.1.169 tracks/go/exercises/house/example.go
trackler-2.2.1.167 tracks/go/exercises/house/example.go
trackler-2.2.1.166 tracks/go/exercises/house/example.go
trackler-2.2.1.165 tracks/go/exercises/house/example.go
trackler-2.2.1.164 tracks/go/exercises/house/example.go
trackler-2.2.1.163 tracks/go/exercises/house/example.go
trackler-2.2.1.162 tracks/go/exercises/house/example.go
trackler-2.2.1.161 tracks/go/exercises/house/example.go
trackler-2.2.1.160 tracks/go/exercises/house/example.go