fn get_chunks(num_ranges: u32, length: u32) { let max_number = 10_i32.pow(length) as u32; let mut chunk_starts = Vec::new(); for i in 0..num_ranges { chunk_starts.push(max_number / num_ranges * i ) } let mut chunk_ends:Vec<u32> = Vec::new(); for i in &chunk_starts[1..] { chunk_ends.push(i - 1); } chunk_ends.push(max_number); let mut chunks = HashMap::new(); for i in 0..chunk_starts.len() { chunks.insert(chunk_starts[i], chunk_ends[i]); } println!("{:?}", chunks); }
get_chunks(5, 2);
{40: 59, 60: 79, 20: 39, 80: 100, 0: 19}
なるほどね