-
Notifications
You must be signed in to change notification settings - Fork 0
/
segmented.go
161 lines (154 loc) · 2.26 KB
/
segmented.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Copyright (c) 2023 Brandon Jordan
*/
package ttuy
import "strings"
type segments struct {
a string
b string
c string
d string
e string
f string
g string
h string
}
var numbers map[string]segments
// Segmented transforms n into a series of characters resembling a segmented display.
// It accepts numbers 0-9 and colons. Example: "20:00"
func Segmented(n string) string {
if len(numbers) == 0 {
numbers = make(map[string]segments)
}
makeNumbers()
var nums = strings.Split(n, "")
var line1 string
var line2 string
var line3 string
var line4 string
for _, number := range nums {
line1 += " " + numbers[number].a + " "
}
for _, number := range nums {
line2 += numbers[number].f + numbers[number].g + numbers[number].b + " "
}
for _, number := range nums {
line3 += numbers[number].e + numbers[number].h + numbers[number].c + " "
}
for _, number := range nums {
line4 += " " + numbers[number].d + " "
}
return strings.Join([]string{line1, line2, line3, line4}, eol)
}
func makeNumbers() {
numbers["0"] = segments{
a: lower,
b: line,
c: line,
d: upper,
e: line,
f: line,
g: " ",
h: " ",
}
numbers["1"] = segments{
a: " ",
b: line,
c: line,
d: " ",
e: " ",
f: " ",
g: " ",
h: " ",
}
numbers["2"] = segments{
a: lower,
b: line,
c: " ",
d: upper,
e: line,
f: " ",
g: lower,
h: " ",
}
numbers["3"] = segments{
a: lower,
b: line,
c: line,
d: upper,
e: " ",
f: " ",
g: lower,
h: " ",
}
numbers["4"] = segments{
a: " ",
b: line,
c: line,
d: " ",
e: " ",
f: line,
g: lower,
h: " ",
}
numbers["5"] = segments{
a: lower,
b: " ",
c: line,
d: upper,
e: " ",
f: line,
g: lower,
h: " ",
}
numbers["6"] = segments{
a: lower,
b: " ",
c: line,
d: upper,
e: line,
f: line,
g: lower,
h: " ",
}
numbers["7"] = segments{
a: lower,
b: line,
c: line,
d: " ",
e: " ",
f: " ",
g: " ",
h: " ",
}
numbers["8"] = segments{
a: lower,
b: line,
c: line,
d: upper,
e: line,
f: line,
g: lower,
h: " ",
}
numbers["9"] = segments{
a: lower,
b: line,
c: line,
d: upper,
e: " ",
f: line,
g: lower,
h: " ",
}
numbers[":"] = segments{
a: " ",
b: " ",
c: " ",
d: " ",
e: " ",
f: " ",
g: bullet,
h: bullet,
}
}