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 = | |
` _ | |
| | | |
|_| | |
. | |
| | |
| | |
. | |
_ | |
_| | |
|_ | |
. | |
_ | |
_| | |
_| | |
. | |
|_| | |
| | |
. | |
_ | |
|_ | |
_| | |
. | |
_ | |
|_ | |
|_| | |
. | |
_ | |
| | |
| | |
. | |
_ | |
|_| | |
|_| | |
. | |
_ | |
|_| | |
_| | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Output: