-
Notifications
You must be signed in to change notification settings - Fork 0
/
feynman.go
68 lines (55 loc) · 1.13 KB
/
feynman.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package feynman
import (
"fmt"
"math/big"
"math/rand"
"time"
)
type solution interface{}
var basicTypes = [...]string{
"int",
"string",
"float",
"interface",
"boolean",
}
func randomIntegerWithSeed(max int) int {
source := rand.NewSource(time.Now().Unix())
r := rand.New(source)
num := r.Intn(max)
return num
}
func getType(t string) interface{} {
switch t {
case "int":
return 42
case "string":
return "the answer"
case "float":
return 42.0
case "interface":
return 42
case "boolean":
return true
default:
return "still 42!"
}
}
// Step 1: Write the problem down!
func write(p string) { fmt.Printf("Problem statement: %s\n", p) }
// Step 2: Think really hard about the problem!
func think() solution {
fmt.Println("Thinking really hard...")
maxTime := randomIntegerWithSeed(big.MaxExp)
thinkingTime := time.Duration(maxTime)
time.Sleep(thinkingTime) // Think for maxTime in nanoseconds!
n := randomIntegerWithSeed(len(basicTypes))
s := getType(basicTypes[n])
return s
}
// Step 3: Solve the problem!
func Solve(p string) {
write(p)
ans := think()
fmt.Printf("The answer to your problem is %v!\n", ans)
}