aboutsummaryrefslogtreecommitdiff
path: root/modules/numbers.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/numbers.go')
-rw-r--r--modules/numbers.go150
1 files changed, 150 insertions, 0 deletions
diff --git a/modules/numbers.go b/modules/numbers.go
new file mode 100644
index 0000000..2d19b9f
--- /dev/null
+++ b/modules/numbers.go
@@ -0,0 +1,150 @@
+package modules
+
+import (
+ "errors"
+)
+
+type Pattern [][]bool
+
+var DigitPatterns = map[int]Pattern{
+ 0: {
+ {true, true, true},
+ {true, false, true},
+ {true, false, true},
+ {true, false, true},
+ {true, true, true},
+ },
+ 1: {
+ {false, true, false},
+ {true, true, false},
+ {false, true, false},
+ {false, true, false},
+ {true, true, true},
+ },
+ 2: {
+ {true, true, true},
+ {false, false, true},
+ {true, true, true},
+ {true, false, false},
+ {true, true, true},
+ },
+ 3: {
+ {true, true, true},
+ {false, false, true},
+ {true, true, true},
+ {false, false, true},
+ {true, true, true},
+ },
+ 4: {
+ {true, false, true},
+ {true, false, true},
+ {true, true, true},
+ {false, false, true},
+ {false, false, true},
+ },
+ 5: {
+ {true, true, true},
+ {true, false, false},
+ {true, true, true},
+ {false, false, true},
+ {true, true, true},
+ },
+ 6: {
+ {true, true, true},
+ {true, false, false},
+ {true, true, true},
+ {true, false, true},
+ {true, true, true},
+ },
+ 7: {
+ {true, true, true},
+ {false, false, true},
+ {false, true, false},
+ {false, true, false},
+ {false, true, false},
+ },
+ 8: {
+ {true, true, true},
+ {true, false, true},
+ {true, true, true},
+ {true, false, true},
+ {true, true, true},
+ },
+ 9: {
+ {true, true, true},
+ {true, false, true},
+ {true, true, true},
+ {false, false, true},
+ {true, true, true},
+ },
+}
+
+var SymbolPatterns = map[string]Pattern{
+ "celsius": {
+ {true, false, false, false, false},
+ {false, false, true, true, false},
+ {false, true, false, false, false},
+ {false, true, false, false, false},
+ {false, false, true, true, false},
+ },
+ "fahrenheit": {
+ {true, false, true, true, false},
+ {false, false, true, false, false},
+ {false, false, true, true, false},
+ {false, false, true, false, false},
+ {false, false, true, false, false},
+ },
+ "percent": {
+ {false, false, false, false, false},
+ {false, true, false, false, true},
+ {false, false, false, true, false},
+ {false, false, true, false, false},
+ {false, true, false, false, true},
+ },
+}
+
+func InsertPattern(grid [][]bool, pattern Pattern, row, col int) {
+ for i, rowPattern := range pattern {
+ for j, val := range rowPattern {
+ if row+i < len(grid) && col+j < len(grid[0]) {
+ grid[row+i][col+j] = val
+ }
+ }
+ }
+}
+
+func CreateNumberGrid(value int, symbol string, row int) ([][]bool, error) {
+ if value < 0 || value >= 1000 {
+ return nil, errors.New("value must be between 0 and 999")
+ }
+ if _, ok := SymbolPatterns[symbol]; !ok {
+ return nil, errors.New("unsupported symbol")
+ }
+
+ grid := make([][]bool, 14)
+ for i := range grid {
+ grid[i] = make([]bool, 14)
+ }
+
+ var (
+ digits []int
+ symbolCol int
+ )
+
+ if value < 100 {
+ digits = []int{value / 10, value % 10}
+ symbolCol = 9
+ } else {
+ digits = []int{value / 100, (value % 100) / 10, value % 10}
+ symbolCol = 13
+ }
+
+ col := 1
+ for _, digit := range digits {
+ InsertPattern(grid, DigitPatterns[digit], row, col)
+ col += 4
+ }
+ InsertPattern(grid, SymbolPatterns[symbol], row, symbolCol)
+
+ return grid, nil
+}