1 Commits

Author SHA1 Message Date
8df88d2c42 build: musl static binary + native + strip 2022-08-04 20:33:16 +02:00
2 changed files with 49 additions and 57 deletions

3
.cargo/config.toml Normal file
View File

@ -0,0 +1,3 @@
[build]
target = "x86_64-unknown-linux-musl"
rustflags = "-C target-cpu=native -C strip=symbols"

View File

@ -1,7 +1,5 @@
use std::time::Instant;
const MAX_BLOCK_SIZE: usize = 10;
struct SField {
field: Vec<usize>,
fixed: Vec<usize>,
@ -15,50 +13,46 @@ struct SField {
impl SField {
pub fn new(block_size: usize) -> SField {
if block_size > MAX_BLOCK_SIZE {
panic!("block size cannot be larger than {}", MAX_BLOCK_SIZE);
}
let size = block_size * block_size;
// EMPTY FIELD
// let field = vec![0; size * size];
// BLOCK_SIZE 4
#[rustfmt::skip]
let field = vec![
0,15,0,0,0,0,11,4,0,5,0,0,0,0,12,8,
12,0,0,9,0,1,0,5,0,0,8,15,0,0,0,13,
0,0,3,0,0,10,13,0,0,11,4,0,15,0,6,0,
13,10,0,11,0,0,0,14,0,3,2,0,0,9,0,0,
0,0,15,10,8,0,0,0,0,0,14,0,0,6,2,0,
0,0,14,0,0,0,6,0,0,0,0,0,1,0,0,0,
0,11,0,8,3,0,15,1,6,0,0,0,0,0,0,7,
0,6,0,7,0,0,0,0,8,13,0,0,10,0,0,0,
0,14,0,2,0,0,0,0,3,0,5,0,11,15,9,0,
0,0,0,12,11,0,2,0,0,0,0,0,0,0,0,0,
0,8,0,0,6,14,1,0,13,15,0,0,0,0,0,10,
10,0,0,3,9,0,7,0,0,1,0,0,13,12,8,0,
7,0,0,0,0,0,14,0,0,0,0,0,0,0,0,9,
0,3,0,14,0,0,9,6,0,0,0,0,0,4,0,0,
0,4,6,0,0,7,0,0,0,0,0,0,0,0,0,0,
5,2,0,0,0,4,10,15,1,0,3,0,0,0,7,0,
];
// MANY SOLUTIONS
// #[rustfmt::skip]
// let field = vec![
// 0,0,0,0,0,0,0,0,9,
// 0,0,0,0,8,9,0,2,0,
// 0,0,0,0,2,0,4,0,0,
// 0,0,4,0,6,0,0,0,8,
// 0,0,0,5,0,0,0,0,0,
// 0,6,5,0,0,2,0,7,4,
// 0,3,0,0,0,5,0,4,0,
// 0,0,1,8,0,0,0,0,0,
// 0,0,8,2,0,0,0,6,0,
// 0,15,0,0,0,0,11,4,0,5,0,0,0,0,12,8,
// 12,0,0,9,0,1,0,5,0,0,8,15,0,0,0,13,
// 0,0,3,0,0,10,13,0,0,11,4,0,15,0,6,0,
// 13,10,0,11,0,0,0,14,0,3,2,0,0,9,0,0,
// 0,0,15,10,8,0,0,0,0,0,14,0,0,6,2,0,
// 0,0,14,0,0,0,6,0,0,0,0,0,1,0,0,0,
// 0,11,0,8,3,0,15,1,6,0,0,0,0,0,0,7,
// 0,6,0,7,0,0,0,0,8,13,0,0,10,0,0,0,
// 0,14,0,2,0,0,0,0,3,0,5,0,11,15,9,0,
// 0,0,0,12,11,0,2,0,0,0,0,0,0,0,0,0,
// 0,8,0,0,6,14,1,0,13,15,0,0,0,0,0,10,
// 10,0,0,3,9,0,7,0,0,1,0,0,13,12,8,0,
// 7,0,0,0,0,0,14,0,0,0,0,0,0,0,0,9,
// 0,3,0,14,0,0,9,6,0,0,0,0,0,4,0,0,
// 0,4,6,0,0,7,0,0,0,0,0,0,0,0,0,0,
// 5,2,0,0,0,4,10,15,1,0,3,0,0,0,7,0,
// ];
// MANY SOLUTIONS
#[rustfmt::skip]
let field = vec![
0,0,0,0,0,0,0,0,9,
0,0,0,0,8,9,0,2,0,
0,0,0,0,2,0,4,0,0,
0,0,4,0,6,0,0,0,8,
0,0,0,5,0,0,0,0,0,
0,6,5,0,0,2,0,7,4,
0,3,0,0,0,5,0,4,0,
0,0,1,8,0,0,0,0,0,
0,0,8,2,0,0,0,6,0,
];
// HARD
// #[rustfmt::skip]
// let field = vec![
@ -130,21 +124,16 @@ impl SField {
let mut found_solution = false;
let mut num_solutions = 0;
let mut loop_count = 0;
let mut last_loop_count = 0;
let mut now = Instant::now();
//let mut loop_count = 0;
loop {
//std::thread::sleep_ms(30);
//self.print_clear();
//self.print();
loop_count += 1;
if now.elapsed().as_millis() >= 1000 {
now = Instant::now();
self.print_clear();
self.print();
println!("{} loops/s", loop_count - last_loop_count);
last_loop_count = loop_count;
}
//loop_count += 1;
//if loop_count % 1000000 == 0 {
//self.print_clear();
//self.print();
//}
if self.is_end() {
found_solution = true;
num_solutions += 1;
@ -345,21 +334,21 @@ impl SField {
}
#[inline(always)]
fn get_row(&self, row: &mut [usize]) {
fn get_row(&self, row: &mut [usize; 9]) {
for (idx, row_elem) in row.iter_mut().enumerate() {
*row_elem = self.get_field_at_pos((self.pos / self.size) * self.size + idx);
}
}
#[inline(always)]
fn get_col(&self, col: &mut [usize]) {
fn get_col(&self, col: &mut [usize; 9]) {
for (idx, col_elem) in col.iter_mut().enumerate() {
*col_elem = self.get_field_at_pos(idx * self.size + self.pos % self.size);
}
}
#[inline(always)]
fn get_block(&self, block: &mut [usize]) {
fn get_block(&self, block: &mut [usize; 9]) {
let block_start_row = self.pos / self.size / self.block_size * self.block_size;
let block_start_col = self.pos % self.size / self.block_size * self.block_size;
@ -373,22 +362,22 @@ impl SField {
#[inline(always)]
fn block_ok(&self, nr: usize) -> bool {
let mut block = [0; MAX_BLOCK_SIZE * MAX_BLOCK_SIZE];
self.get_block(&mut block[0..self.size]);
let mut block = [0; 9];
self.get_block(&mut block);
!block.contains(&nr)
}
#[inline(always)]
fn row_ok(&self, nr: usize) -> bool {
let mut row = [0; MAX_BLOCK_SIZE * MAX_BLOCK_SIZE];
self.get_row(&mut row[0..self.size]);
let mut row = [0; 9];
self.get_row(&mut row);
!row.contains(&nr)
}
#[inline(always)]
fn col_ok(&self, nr: usize) -> bool {
let mut col = [0; MAX_BLOCK_SIZE * MAX_BLOCK_SIZE];
self.get_col(&mut col[0..self.size]);
let mut col = [0; 9];
self.get_col(&mut col);
!col.contains(&nr)
}
@ -423,7 +412,7 @@ impl SField {
}
fn run() -> Result<(), String> {
let mut field = SField::new(4);
let mut field = SField::new(3);
field.build_possible_values_db();