News for hackers. Stuff that matters.
Re:How I See Numbers by teaearlgraycold on Thursday March 03, 2022 @03:46PM (#30546733)
That'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/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)
    }

There are no comments on this comment yet.