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.159 tracks/go/exercises/house/example.go
trackler-2.2.1.158 tracks/go/exercises/house/example.go
trackler-2.2.1.157 tracks/go/exercises/house/example.go
trackler-2.2.1.156 tracks/go/exercises/house/example.go
trackler-2.2.1.155 tracks/go/exercises/house/example.go
trackler-2.2.1.154 tracks/go/exercises/house/example.go
trackler-2.2.1.153 tracks/go/exercises/house/example.go
trackler-2.2.1.152 tracks/go/exercises/house/example.go
trackler-2.2.1.151 tracks/go/exercises/house/example.go
trackler-2.2.1.150 tracks/go/exercises/house/example.go
trackler-2.2.1.149 tracks/go/exercises/house/example.go
trackler-2.2.1.148 tracks/go/exercises/house/example.go
trackler-2.2.1.147 tracks/go/exercises/house/example.go
trackler-2.2.1.146 tracks/go/exercises/house/example.go
trackler-2.2.1.145 tracks/go/exercises/house/example.go
trackler-2.2.1.144 tracks/go/exercises/house/example.go
trackler-2.2.1.143 tracks/go/exercises/house/example.go
trackler-2.2.1.142 tracks/go/exercises/house/example.go
trackler-2.2.1.141 tracks/go/exercises/house/example.go
trackler-2.2.1.140 tracks/go/exercises/house/example.go