Skip to content

Instantly share code, notes, and snippets.

@sndnvaps
Created December 3, 2012 13:55
Show Gist options
  • Save sndnvaps/4195191 to your computer and use it in GitHub Desktop.
Save sndnvaps/4195191 to your computer and use it in GitHub Desktop.
bigDigist with bar
package main
import (
"fmt"
"log"
"os"
"path/filepath"
)
var bigDigits = [][]string{
{ " 000 ",
" 0 0 ",
" 0 0 ",
" 0 0 ",
" 0 0 ",
" 0 0 ",
" 000 "},
{" 11 ",
" 11 ",
" 11 ",
" 11 ",
" 11 ",
" 11 ",
" 11 "},
{" 222 ",
" 2 2 ",
" 2 ",
" 2 ",
" 2 ",
" 2 ",
" 22222 "},
{" 333 ",
" 3 3 ",
" 3 ",
" 33 ",
" 3 ",
" 3 3 ",
" 333 "},
{" 4 ",
" 44 ",
" 4 4 ",
" 4 4 ",
" 44444 ",
" 4 ",
" 4 "},
{" 55555 ",
" 5 ",
" 5 ",
" 555 ",
" 5 ",
" 5 5 ",
" 555 "},
{" 666 ",
" 6 ",
" 6 ",
" 6666 ",
" 6 6 ",
" 6 6 ",
" 6666 "},
{" 77777",
" 7 ",
" 7 ",
" 7 ",
" 7 ",
" 7 ",
" 7 "},
{" 8 ",
" 8 8 ",
" 8 8 ",
" 8 ",
" 8 8 ",
" 8 8 ",
" 8 "},
{" 9999 ",
" 9 9 ",
" 9 9 ",
" 9999 ",
" 9 ",
" 9 ",
" 9 "},
}
func main() {
if len(os.Args) == 1 {
fmt.Printf("usage: %s [-b|--bar] <whole-number>\n",filepath.Base(os.Args[0]))
os.Exit(1)
}
state , Bar := barshow()
stringOfDigits := ""
if state == 4 {
stringOfDigits += os.Args[1]
} else {
stringOfDigits += os.Args[2]
}
fmt.Printf("%s",Bar)
fmt.Printf("\n")
for row := range bigDigits [0] {
line := ""
for column := range stringOfDigits {
digit := stringOfDigits[column] - '0'
if 0 <= digit && digit <= 9 {
line += bigDigits[digit][row] + ""
} else {
log.Fatal("invalid whole number")
}
}
fmt.Println(line)
}
fmt.Printf("\n")
fmt.Printf("%s",Bar)
fmt.Printf("\n")
}
func barshow() (int,string) {
bar := ""
bar_s := "*******************************************************************"
if os.Args[1] == "-b" || os.Args[1] == "--bar" {
return 3, bar_s
}
return 4, bar
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment