3 ms·
Sounds like something that would make an interesting blog post!
by sjosund 5y ago
Sounds like something that would make an interesting blog post!
- teaearlgraycold 5y agoThat's a good idea. Sometimes the domain is already graphical - and I take every opportunity to make the code match the visual layout, ex: https://github.com/danthedaniel/gameoflife-rs/blob/master/src/gol.rs#L106 https://github.com/danthedaniel/gameoflife-rs/blob/master/sr... /// Count living cells adjacent to a cell in the matrix. #[inline] #[rustfmt::skip] fn alive_neighbors(&self, x: i32, y: i32) -> u8 { [ self[(x - 1, y - 1)], self[(x + 0, y - 1)], self[(x + 1, y - 1)], self[(x - 1, y + 0)], /* selected cell */ self[(x + 1, y + 0)], self[(x - 1, y + 1)], self[(x + 0, y + 1)], self[(x + 1, y + 1)], ] .iter() .fold(0, |total, &neighbor| total + (neighbor != 0) as u8) }