You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.0 KiB

//012
//021
//102
//120
//201
//210
type Str = Vec<u8>;
fn pr(s: &Str) {
for c in s.iter() { print!("{}", c); }
println!("");
}
fn sp(s: &Str, fx: usize, k: usize) -> Str {
let mut res = Vec::new();
for i in 0..fx {
res.push(s[i]);
}
res.push(s[k]);
for i in fx..s.len() {
if i != k { res.push(s[i]); }
}
res
}
fn lp(s: &Str, fx: usize, keep_first: bool, mut count: usize) -> usize {
let kf = 0; //if keep_first { 0usize } else { 1usize };
for k in (fx + kf)..s.len() {
let ss = sp(&s, fx, k);
//count += 1;
if ss != *s || keep_first {
count += 1;
if count == 1_000_000 {
//print!("{}\t", count);
pr(&ss);
}
}
count = lp(&ss, fx + 1, false, count);
}
count
}
fn main() {
let mut s = Vec::new();
s.push(0);
s.push(1);
s.push(2);
s.push(3);
s.push(4);
s.push(5);
s.push(6);
s.push(7);
s.push(8);
s.push(9);
lp(&s, 0, true, 0);
}