Created
August 4, 2020 07:58
-
-
Save AcrylicShrimp/140bd2fd6b3a500063c3d3aa27b95733 to your computer and use it in GitHub Desktop.
horizon-kias-re-kr-15230
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::cmp::max; | |
use std::collections::VecDeque; | |
macro_rules! loop_perm { | |
($src_queue:ident, $src_queue_len:literal, $target_stack:ident => $code:block) => { | |
for _ in 0..$src_queue_len { | |
$target_stack.push($src_queue.pop_back().unwrap()); | |
$code | |
$src_queue.push_front($target_stack.pop().unwrap()); | |
} | |
}; | |
} | |
macro_rules! find_max { | |
($target_stack:ident, $i0:literal, $i1:literal) => { | |
max($target_stack[$i0], $target_stack[$i1]) | |
}; | |
($target_stack:ident, $i0:literal, $i1:literal, $i2:literal) => { | |
max( | |
max($target_stack[$i0], $target_stack[$i1]), | |
$target_stack[$i2], | |
) | |
}; | |
($target_stack:ident, $i0:literal, $i1:literal, $i2:literal, $i3:literal) => { | |
max( | |
max( | |
max($target_stack[$i0], $target_stack[$i1]), | |
$target_stack[$i2], | |
), | |
$target_stack[$i3], | |
) | |
}; | |
} | |
macro_rules! count_appearance { | |
($appearance_vec:ident, $local_max_value:ident, $value:ident) => { | |
if !$appearance_vec[$value] { | |
$appearance_vec[$value] = true; | |
$local_max_value += 1; | |
} | |
}; | |
} | |
fn main() { | |
let mut src_queue = VecDeque::from(vec![5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); | |
let mut target_stack = Vec::with_capacity(12); | |
let mut max_value = 0; | |
let mut max_value_target_stack = Vec::new(); | |
loop_perm!(src_queue, 12, target_stack => { | |
loop_perm!(src_queue, 11, target_stack => { | |
loop_perm!(src_queue, 10, target_stack => { | |
loop_perm!(src_queue, 9, target_stack => { | |
loop_perm!(src_queue, 8, target_stack => { | |
loop_perm!(src_queue, 7, target_stack => { | |
loop_perm!(src_queue, 6, target_stack => { | |
loop_perm!(src_queue, 5, target_stack => { | |
loop_perm!(src_queue, 4, target_stack => { | |
loop_perm!(src_queue, 3, target_stack => { | |
loop_perm!(src_queue, 2, target_stack => { | |
loop_perm!(src_queue, 1, target_stack => { | |
let max00 = find_max!(target_stack, 0, 1); | |
let max01 = find_max!(target_stack, 2, 3, 4, 5); | |
let max02 = find_max!(target_stack, 6, 7, 8, 9); | |
let max03 = find_max!(target_stack, 10, 11); | |
let max10 = find_max!(target_stack, 2, 6); | |
let max11 = find_max!(target_stack, 0, 3, 7, 10); | |
let max12 = find_max!(target_stack, 1, 4, 8, 11); | |
let max13 = find_max!(target_stack, 5, 9); | |
let max20 = find_max!(target_stack, 0, 2); | |
let max21 = find_max!(target_stack, 1, 3, 6); | |
let max22 = find_max!(target_stack, 4, 7); | |
let max23 = find_max!(target_stack, 5, 8, 10); | |
let max24 = find_max!(target_stack, 9, 11); | |
let max30 = find_max!(target_stack, 1, 5); | |
let max31 = find_max!(target_stack, 0, 4, 9); | |
let max32 = find_max!(target_stack, 3, 8); | |
let max33 = find_max!(target_stack, 2, 7, 11); | |
let max34 = find_max!(target_stack, 6, 10); | |
let mut appearance_vec = vec![false; 17]; | |
let mut local_max_value = 4; | |
count_appearance!(appearance_vec, local_max_value, max00); | |
count_appearance!(appearance_vec, local_max_value, max01); | |
count_appearance!(appearance_vec, local_max_value, max02); | |
count_appearance!(appearance_vec, local_max_value, max03); | |
count_appearance!(appearance_vec, local_max_value, max10); | |
count_appearance!(appearance_vec, local_max_value, max11); | |
count_appearance!(appearance_vec, local_max_value, max12); | |
count_appearance!(appearance_vec, local_max_value, max13); | |
count_appearance!(appearance_vec, local_max_value, max20); | |
count_appearance!(appearance_vec, local_max_value, max21); | |
count_appearance!(appearance_vec, local_max_value, max22); | |
count_appearance!(appearance_vec, local_max_value, max23); | |
count_appearance!(appearance_vec, local_max_value, max24); | |
count_appearance!(appearance_vec, local_max_value, max30); | |
count_appearance!(appearance_vec, local_max_value, max31); | |
count_appearance!(appearance_vec, local_max_value, max32); | |
count_appearance!(appearance_vec, local_max_value, max33); | |
count_appearance!(appearance_vec, local_max_value, max34); | |
if max_value < local_max_value { | |
max_value = local_max_value; | |
max_value_target_stack = target_stack.clone(); | |
} | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
println!("max: {}", max_value); | |
println!("max stack: {:#?}", max_value_target_stack); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment