pub fn encode_row(n: u32, mut x: u64) -> Vec { let mut row = Vec::with_capacity(n as usize); let mut pieces: Vec = (0..n).collect(); for i in (1..=n.into()).rev() { let p = (x % i) as u32; let piece = pieces[p as usize]; row.push(piece + 1); pieces.swap_remove(p as usize); x /= i; } row } pub fn colliding(w1: &[u32], w2: &[u32]) -> bool { let n = w1.len() - 1; let (mut v1, mut v2) = (w1.iter().take(n), w2.iter().take(n)); let (mut i, mut j) = (*v1.next().unwrap(), *v2.next().unwrap()); loop { if i < j { i += if let Some(&k) = v1.next() { k } else { return false; }; } else if i > j { j += if let Some(&k) = v2.next() { k } else { return false; }; } else { return true; } } }