From fd5567d4a4f78d497b2705381aa87f782b399a19 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 14 Jan 2019 17:49:51 +0100 Subject: add magic8 --- magic8/main.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 magic8/main.go diff --git a/magic8/main.go b/magic8/main.go new file mode 100644 index 0000000..3936ef5 --- /dev/null +++ b/magic8/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "math/rand" + "time" +) + +type affirmative string + +func (m affirmative) String() string { return "[+] " + string(m) } + +type nonCommittal string + +func (m nonCommittal) String() string { return "[?] " + string(m) } + +type negative string + +func (m negative) String() string { return "[-] " + string(m) } + +type magic []fmt.Stringer + +func (m magic) String() string { + rand.Seed(time.Now().UnixNano()) + n := rand.Intn(len(m)) + return m[n].String() +} + +var fortune = magic{ + // affirmative + affirmative("It is certain."), + affirmative("It is decidedly so."), + affirmative("Without a doubt."), + affirmative("Yes - definitely."), + affirmative("You may rely on it."), + + affirmative("As I see it, yes."), + affirmative("Most likely."), + affirmative("Outlook good."), + affirmative("Yes."), + affirmative("Signs point to yes."), + + // non-committal + nonCommittal("Reply hazy, try again."), + nonCommittal("Ask again later."), + nonCommittal("Better not tell you now."), + nonCommittal("Cannot predict now."), + nonCommittal("Concentrate and ask again."), + + // negative + negative("Don't count on it."), + negative("My reply is no."), + negative("My sources say no."), + negative("Outlook not so good."), + negative("Very doubtful."), +} + +func main() { + fmt.Println(fortune) +} -- cgit v1.2.3