1package pdfexport23import (4 "encoding/json"5 "fmt"6 "strings"7)89type sudokuSave struct {10 Provided []sudokuCell `json:"provided"`11}1213type sudokuCell struct {14 X int `json:"x"`15 Y int `json:"y"`16 V int `json:"v"`17}1819func ParseSudokuPrintData(saveData []byte) (*SudokuData, error) {20 if len(strings.TrimSpace(string(saveData))) == 0 {21 return nil, nil22 }2324 var save sudokuSave25 if err := json.Unmarshal(saveData, &save); err != nil {26 return nil, fmt.Errorf("decode sudoku save: %w", err)27 }2829 var givens [9][9]int30 for _, cell := range save.Provided {31 if !isSudokuCellInBounds(cell.X, cell.Y) {32 continue33 }34 if cell.V < 1 || cell.V > 9 {35 continue36 }37 givens[cell.Y][cell.X] = cell.V38 }3940 return &SudokuData{Givens: givens}, nil41}4243func ParseSudokuRGBPrintData(saveData []byte) (*SudokuData, error) {44 if len(strings.TrimSpace(string(saveData))) == 0 {45 return nil, nil46 }4748 var save sudokuSave49 if err := json.Unmarshal(saveData, &save); err != nil {50 return nil, fmt.Errorf("decode sudoku rgb save: %w", err)51 }5253 var givens [9][9]int54 for _, cell := range save.Provided {55 if !isSudokuCellInBounds(cell.X, cell.Y) {56 continue57 }58 if cell.V < 1 || cell.V > 3 {59 continue60 }61 givens[cell.Y][cell.X] = cell.V62 }6364 return &SudokuData{Givens: givens}, nil65}6667func isSudokuCellInBounds(x, y int) bool {68 return x >= 0 && x < 9 && y >= 0 && y < 969}