static OFFSETS: &'static[(i32,i32)] = &[ (-1,-1), (-1, 0), (-1, 1), ( 0,-1), ( 0, 1), ( 1,-1), ( 1, 0), ( 1, 1) ]; pub fn annotate(minefield: &[&str]) -> Vec { let height = minefield.len() as i32; (0..height).map(|i| { let width = minefield[i as usize].len() as i32; (0..width).map(|j| { if minefield[i as usize].as_bytes()[j as usize] == b' ' { let count = OFFSETS .iter() .map(|(oi,oj)| (i+oi,j+oj)) .filter(|&(i,j)| i >= 0 && i < height && j >= 0 && j < width) .filter(|&(i,j)| minefield[i as usize].as_bytes()[j as usize] == b'*') .count(); if count > 0 { char::from_digit(count as u32,10).unwrap() } else { ' ' } } else { '*' } }).collect() }).collect() }