Skip to content

Instantly share code, notes, and snippets.

@agoalofalife
Last active April 18, 2017 14:52
Show Gist options
  • Save agoalofalife/f44a1fc1e0a25842261ebae4e8f24d06 to your computer and use it in GitHub Desktop.
Save agoalofalife/f44a1fc1e0a25842261ebae4e8f24d06 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"fmt"
"os"
"path/filepath"
"strings"
)
var bigDigits = [][]string{
{" 000 ",
" 0 0 ",
"0 0",
"0 0",
"0 0",
" 0 0 ",
" 000 "},
{" 1 ",
"11 ",
" 1 ",
" 1 ",
" 1 ",
" 1 ",
"111"},
{" 222 ",
"2 2",
" 2 ",
" 2 ",
" 2 ",
" 2 ",
"22222 "},
{" 333 ",
"3 3",
" 3",
" 33 ",
" 3",
"3 3",
" 333 "},
{"4 4",
"4 4",
"4 4",
"44444",
" 4",
" 4",
" 4"},
{"55555",
"5 ",
"5 ",
" 555 ",
" 5",
"5 5",
" 555 "},
{" 666 ",
"6 ",
"6 ",
"6666 ",
"6 6",
"6 6",
" 666 "},
{"7777",
" 7",
" 7 ",
" 7 ",
" 7 ",
"7 ",
"7 "},
{" 888 ",
"8 8",
"8 8",
" 888 ",
"8 8",
"8 8",
" 888 "},
{" 999 ",
"9 9",
"9 9",
" 9999",
" 9 ",
" 9 ",
" 9 "}}
func main() {
var(
stringOfDigits string
stateBar bool
upLine string
)
if len(os.Args) == 1 {
fmt.Printf("usage: %s [-b|--bar] <number>\n", filepath.Base(os.Args[0]))
os.Exit(1)
}
if os.Args[1] == "-b" || os.Args[1] == "--bar" {
stringOfDigits, stateBar = os.Args[2], true
} else{
stringOfDigits = os.Args[1]
}
downLine := 0
for row := range bigDigits[0] {
line := ""
for column := range stringOfDigits {
digit := stringOfDigits[column] - '0'
if 0 <= digit && digit <= 9 {
if row == 0 && stateBar == true{
upLine += strings.Repeat("*", len(bigDigits[digit][row]) + 1)
downLine += len(bigDigits[digit][row]) + 1
}
line += bigDigits[digit][row] + " "
} else {
log.Fatal("invalid number, is it a whole number?")
}
}
if row == 0 {
fmt.Println( upLine )
}
fmt.Println( line )
}
fmt.Print(strings.Repeat("*", downLine))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment