Skip to content

Instantly share code, notes, and snippets.

@oscarryz
Created March 20, 2012 01:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarryz/2129414 to your computer and use it in GitHub Desktop.
Save oscarryz/2129414 to your computer and use it in GitHub Desktop.
Led converter in Go
package main
import (
"fmt"
"strings"
"strconv"
)
func main() {
fmt.Printf("%s\n", convertToLCD( 1234567890 ) )
}
// Convert a given number into an "LCD" esque representation:
// ie
// 42 = _
// |_| _|
// ||_
func convertToLCD( n int ) string {
i , result , numbers := 0 , "" , strings.Split( all_numbers, ".\n" )
for _, char := range strconv.Itoa( n ) {
current := numbers[ char - '0' ]
if i == 0 {
result = current
} else {
r1, r2, r3 := 3*i, 6*i+1, 9*i+2
result = result[0 : r1] + current[0:4] +
result[r1+1 : r2] + current[4:8] +
result[r2+1 : r3] + current[8:12]
}
i++
}
return result
}
const all_numbers =
` _
| |
|_|
.
|
|
.
_
_|
|_
.
_
_|
_|
.
|_|
|
.
_
|_
_|
.
_
|_
|_|
.
_
|
|
.
_
|_|
|_|
.
_
|_|
_|
`
@oscarryz
Copy link
Author

Output:

$ 6g led.go  ; 6l led.6  ; ./6.out 
    _  _     _  _  _  _  _  _ 
  | _| _||_||_ |_   ||_||_|| |
  ||_  _|  | _||_|  ||_| _||_|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment