| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 | use serde_derive::{Deserialize, Serialize};use serde_xml_rs::{from_reader, from_str, to_string};use std::fs::File;#[derive(Debug, Serialize, Deserialize, PartialEq)]struct Graph {    order: i32,    #[serde(rename = "type")]    game_type: String,    #[serde(rename = "specific-type")]    specific_type: String,}#[derive(Debug, Serialize, Deserialize, PartialEq)]struct Puzzle {    graph: Graph,    values: String,    solution: String,}#[derive(Debug, Serialize, Deserialize, PartialEq)]struct Game {    #[serde(rename = "had-help")]    help: i16,    #[serde(rename = "msecs-elapsed")]    elapsed: u32,    puzzle: Puzzle,}#[derive(Debug, Serialize, Deserialize, PartialEq)]struct Ksudoku {    game: Game,}const SIZE: u8 = 9;const MAX_SIZE: u8 = 81;#[derive(Debug)]struct Sudoku {    board: [u8; MAX_SIZE as usize],}const fn pos(x: u8, y: u8) -> u8 {    x + (y * SIZE as u8)}impl Sudoku {    fn new() -> Self {        let s = Sudoku {            board: [0; MAX_SIZE as usize],        };        s    }    fn clear(&mut self) {        for x in 0..MAX_SIZE {            self.board[x as usize] = 0;        }    }    fn load_xsudoku(&mut self, s: &str) {        self.clear();        let mut x: u8 = 0;        let mut y: u8 = 0;        for ch in s.chars() {            if ch >= 'b' {                self.board[pos(x, y) as usize] = ch as u8 - 'a' as u8;            };            y += 1;            if y >= SIZE {                y = 0;                x += 1;            }        }    }    fn display(&self) {        println!("╔═══╦═══╦═══╗");        for y in 0..SIZE {            print!("║");            for x in 0..SIZE {                let item = self.board[pos(x as u8, y as u8) as usize];                if item == 0 {                    print!(" ");                } else if (item >= 1) && (item <= 9) {                    print!("{}", item);                }                if x % 3 == 2 {                    print!("║");                }            }            println!("");            if y % 3 == 2 {                if (y + 1 == SIZE) {                    println!("╚═══╩═══╩═══╝");                } else {                    println!("╠═══╬═══╬═══╣");                }            }        }    }}/*const InRow: [u8; 81] = [1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3, 4, 5, 6, 7, 8, 9,1, 2, 3, 4, 5, 6, 7, 8, 9,]; */// rows, columns, and cells ?  (maybe?)// With the ability to know what RCC each item belongs?#[derive(Debug)]struct OnlyOne {    positions: [u8; SIZE as usize],}const CELLS: [OnlyOne; 3] = [    OnlyOne {        positions: [            pos(1, 1),            pos(1, 2),            pos(1, 3),            pos(1, 4),            pos(1, 5),            pos(1, 6),            pos(1, 7),            pos(1, 8),            pos(1, 9),        ],    },    OnlyOne {        positions: [            pos(2, 1),            pos(2, 2),            pos(2, 3),            pos(2, 4),            pos(2, 5),            pos(2, 6),            pos(2, 7),            pos(2, 8),            pos(2, 9),        ],    },    OnlyOne {        positions: [            pos(3, 1),            pos(3, 2),            pos(3, 3),            pos(3, 4),            pos(3, 5),            pos(3, 6),            pos(3, 7),            pos(3, 8),            pos(3, 9),        ],    },];const POS1: OnlyOne = OnlyOne {    positions: [0, 1, 2, 3, 4, 5, 6, 7, 8],};fn main() {    let filename = "../puzzle1";    let fh = File::open(filename).unwrap();    let puzzle: Ksudoku = from_reader(fh).unwrap();    println!("Puzzle: {:?}", puzzle);    println!("CELLS: {:?}", CELLS);    let mut s = Sudoku::new();    s.load_xsudoku(&puzzle.game.puzzle.values);    s.display();}
 |