Created
March 20, 2012 01:09
-
-
Save oscarryz/2129414 to your computer and use it in GitHub Desktop.
Led converter in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = | |
` _ | |
| | | |
|_| | |
. | |
| | |
| | |
. | |
_ | |
_| | |
|_ | |
. | |
_ | |
_| | |
_| | |
. | |
|_| | |
| | |
. | |
_ | |
|_ | |
_| | |
. | |
_ | |
|_ | |
|_| | |
. | |
_ | |
| | |
| | |
. | |
_ | |
|_| | |
|_| | |
. | |
_ | |
|_| | |
_| | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: