From 0162fa190cdf0a3b7b5ce27855b7b67fd26278aa Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 26 Aug 2016 03:53:38 +0200 Subject: Sovle house --- go/house/house.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 go/house/house.go (limited to 'go') diff --git a/go/house/house.go b/go/house/house.go new file mode 100644 index 0000000..c3b353a --- /dev/null +++ b/go/house/house.go @@ -0,0 +1,40 @@ +package house + +import "strings" + +func Embed(relPhrase, nounPhrase string) string { + return relPhrase + " " + nounPhrase +} + +func Verse(subject string, relPhrases []string, nounPhrase string) string { + return subject + " " + strings.Join(append(relPhrases, nounPhrase), " ") +} + +var items = [][]string{ + {"lay in", "the house that Jack built."}, + {"ate", "the malt"}, + {"killed", "the rat"}, + {"worried", "the cat"}, + {"tossed", "the dog"}, + {"milked", "the cow with the crumpled horn"}, + {"kissed", "the maiden all forlorn"}, + {"married", "the man all tattered and torn"}, + {"woke", "the priest all shaven and shorn"}, + {"kept", "the rooster that crowed in the morn"}, + {"belonged to", "the farmer sowing his corn"}, + {"", "the horse and the hound and the horn"}, +} + +func Song() string { + var s []string + for k, v := range items { + s = append(s, "This is "+v[1]) + for i := k - 1; i >= 0; i-- { + s = append(s, "that "+strings.Join(items[i], " ")) + } + if k != len(items)-1 { + s = append(s, "") + } + } + return strings.Join(s, "\n") +} -- cgit v1.2.3