Sudoku: Difference between revisions
Content deleted Content added
m →{{header|Rust}}: do rustfmt |
→{{header|Rust}}: Made the example more idiomatic |
||
Line 9,780:
=={{header|Rust}}==
{{trans|Ada}}
<lang rust>type
fn
▲fn check_validity(val: u8, x: usize, y: usize, sudoku_ar: &mut SudokuArType) -> bool {
return false;▼
}▼
}
▲ let start_x: usize = (x / 3) * 3;
▲ if sudoku_ar[i * 9 + j] == val {
return false;▼
}
let
if place_number(pos + 1, sudoku_ar) {
sudoku_ar[pos] = n;▼
▲ ret = place_number(pos + 1, sudoku_ar);
}
}
}
let line_sep = "------+-------+------";▼
▲fn pretty_print(sudoku_ar: SudokuArType) {
▲ let line_sep = "------+------+------";
println!("{}", line_sep);
for (i, e) in
print!("{} ",
if (i + 1) % 3 == 0 &&
print!("| ");
}
Line 9,849 ⟶ 9,822:
}
fn solve(sudoku_ar: &mut Sudoku) -> bool {
▲fn solve(sudoku_ar: &mut SudokuArType) -> bool {
place_number(0, sudoku_ar)
}
fn main() {
let mut sudoku_ar:
8, 5, 0, 0, 0, 2, 4, 0, 0,
7, 2, 0, 0, 0, 0, 0, 0, 9,
Line 9,867 ⟶ 9,838:
0, 0, 0, 0, 3, 6, 0, 4, 0
];
println!("Unsolvable");
}
}</lang>
Line 9,877 ⟶ 9,847:
{{out}}
<pre>
------+-------+------
8 5 9 | 6 1 2 | 4 3 7
7 2 3 | 8 5 4 | 1 6 9
1 6 4 | 3 7 9 | 5 2 8
------+-------+------
9 8 6 | 1 4 7 | 3 5 2
3 7 5 | 2 6 8 | 9 1 4
2 4 1 | 5 9 3 | 7 8 6
------+-------+------
4 3 2 | 9 8 1 | 6 7 5
6 1 7 | 4 2 5 | 8 9 3
5 9 8 | 7 3 6 | 2 4 1
------+-------+------
</pre>
|