Skip to content

Commit 9df3f5e

Browse files
committed
GO Track house solution
1 parent f7be269 commit 9df3f5e

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

viktor/house/house.go

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)