Skip to content

Commit 191f3de

Browse files
committed
GO Track twelve-days solution
1 parent 25640f9 commit 191f3de

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

viktor/twelve-days/twelve_days.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package twelve
2+
3+
var gifts = []struct {
4+
day, gift string
5+
}{
6+
{"first", "a Partridge in a Pear Tree"},
7+
{"second", "two Turtle Doves"},
8+
{"third", "three French Hens"},
9+
{"fourth", "four Calling Birds"},
10+
{"fifth", "five Gold Rings"},
11+
{"sixth", "six Geese-a-Laying"},
12+
{"seventh", "seven Swans-a-Swimming"},
13+
{"eighth", "eight Maids-a-Milking"},
14+
{"ninth", "nine Ladies Dancing"},
15+
{"tenth", "ten Lords-a-Leaping"},
16+
{"eleventh", "eleven Pipers Piping"},
17+
{"twelfth", "twelve Drummers Drumming"},
18+
}
19+
20+
func Song() string {
21+
song := ""
22+
for i := 1; i <= len(gifts); i++ {
23+
if i != len(gifts) {
24+
song += Verse(i) + "\n"
25+
} else {
26+
song += Verse(i)
27+
}
28+
29+
}
30+
return song
31+
}
32+
33+
func Verse(v int) string {
34+
result := "On the " + gifts[v-1].day + " day of Christmas my true love gave to me: "
35+
for i := v; i > 0; i-- {
36+
result += gifts[i-1].gift
37+
if i == 2 {
38+
result += ", and "
39+
} else if i > 2 {
40+
result += ", "
41+
}
42+
}
43+
44+
return result + "."
45+
}

0 commit comments

Comments
 (0)