-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzebra_domain.go
122 lines (100 loc) · 1.97 KB
/
zebra_domain.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package zebra
import (
"strconv"
)
type domainer interface {
toDomainVal() uint8
}
type nationality uint8
const (
norwegian nationality = iota + 1
spaniard
englishman
ukrainian
japanese
)
func (n nationality) toDomainVal() uint8 { return uint8(n) }
func (n nationality) String() string {
return []string{"-", "Norwegian", "Spaniard", "Englishman", "Ukrainian", "Japanese"}[n]
}
func ownerOf(item domainer, assignment ...uint8) string {
index, _ := indexOf(item, assignment...)
return nationality(assignment[index%5]).String()
}
type color uint8
const (
green color = iota + 1
ivory
red
yellow
blue
)
func (c color) toDomainVal() uint8 { return uint8(c) }
func (c color) String() string { return []string{"-", "green", "ivory", "red", "yellow", "blue"}[c] }
type drink uint8
const (
water drink = iota + 1
coffee
milk
tea
orangeJuice
)
func (d drink) toDomainVal() uint8 { return uint8(d) }
func (d drink) String() string {
return []string{"-", "water", "coffee", "milk", "tea", "orange juice"}[d]
}
type smoke uint8
const (
oldGold smoke = iota + 1
chesterfields
kools
parliaments
luckyStrike
)
func (s smoke) toDomainVal() uint8 { return uint8(s) }
func (s smoke) String() string {
return []string{"Old Gold", "Chesterfields", "Kools", "Parliaments", "Lucky Strike"}[s]
}
type pets uint8
const (
snails pets = iota + 1
dog
fox
horse
zebra
)
func (p pets) toDomainVal() uint8 { return uint8(p) }
func (p pets) String() string { return []string{"-", "snails", "dog", "fox", "horse", "zebra"}[p] }
type number uint8
const (
house1 number = iota + 1
house2
house3
house4
house5
)
func (n number) toDomainVal() uint8 { return uint8(n) }
func (n number) String() string {
if n == 0 {
return "-"
}
return strconv.Itoa(int(n))
}
func category(d domainer) int {
switch d.(type) {
case nationality:
return 0
case color:
return 1
case drink:
return 2
case smoke:
return 3
case pets:
return 4
case number:
return 5
default:
return -1
}
}