-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (52 loc) · 1.3 KB
/
main.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
package main
import (
"flag"
"fmt"
"log"
"os"
"strconv"
"strings"
)
var digitLength = 7
var digitWidth = 5
func main() {
fmt.Println(os.Args)
if len(os.Args) != 2 && len(os.Args) != 4 {
log.Println("Need only one input number")
log.Println(os.Args)
os.Exit(1)
}
symbolFlag := flag.Bool("symbol", false, "set custom symbol for the art")
flag.Parse()
var symbol, number string
if *symbolFlag {
number = os.Args[3]
symbol = os.Args[2]
}
if _, err := strconv.ParseUint(number, 10, 64); err != nil {
log.Println("Input argument is integer non-convertible: ", err.Error())
os.Exit(1)
}
digs := prepareDigits(symbol)
sb := strings.Builder{}
for i := 0; i < 7; i++ {
for _, num := range number {
sb.WriteString(digs[int(num-48)][i] + " ")
}
if i != digitLength-1 {
sb.WriteByte('\n')
}
}
asteriskBorder := strings.Repeat("*", len(number)*(digitWidth+1)-1)
fmt.Printf("%s\n%s\n%s", asteriskBorder, sb.String(), asteriskBorder)
}
func prepareDigits(symbol string) map[int][]string {
artNumbers := strings.Trim(digits, "\n")
numbers := make(map[int][]string)
for i, digit := range strings.Split(artNumbers, "\n\n") {
for _, digitString := range strings.Split(digit, "\n") {
numbers[i] = append(numbers[i], fmt.Sprintf("%-5s", digitString))
}
}
return numbers
}