fn main() { let data: [u8;4] = [2, 5, 7, 8]; let dlen: usize = data.len(); // 4 let cnt_data_comb: u8 = 2_u8.pow(4) - 1; // 2^4 -1 = 15 // [A] // I can get the quantities in the groups like this: let mut c; for i in 0..dlen { println!(); c = cnt(dlen as u8, i as u8 + 1); for j in 0..c { println!("{}. ", j+1); } } // code ... } fn cnt(dlen: u8, cnt_n: u8) -> usize { let cnt_1: u8 = (1..=dlen).product(); // 24 let cnt_2: u8 = (1..=cnt_n).product(); // 2 let cnt_3: u8 = (1..=(dlen - cnt_n)).product(); // 2 (cnt_1 / (cnt_2 * cnt_3)) as usize // 6 } [A] (click for more details) The data are linked by their index to other data that will subsequently need to be mapped. So, need to obtain a vector of indices, something like this:
and a universal rule that will get the correct result - similar to [A] - for other array lengths. For example, for the data = [2, 3, 5, 7, 8] there will be five groups with the following counts: 5, 10, 10, 5, 1 = 31.
Need to get the sums as in [A], because for a given sum value, the array elements (accessed by index) will subsequently be linked to other data.
1 post - 1 participant