Counting Up

A problem from Daniel J. Velleman and Stan Wagon’s excellent 2020 book Bicycle or Unicycle?: A Collection of Intriguing Mathematical Puzzles:

A square grid measures 999×999. Each square is either black or white. Each black square that’s not on the border of the grid has exactly five white squares among its eight immediate neighbors (those that adjoin it horizontally, vertically, or diagonally). Each white square that’s not on the border has exactly four black squares among its immediate neighbors. Of the 999 × 999 = 998001 squares in the grid, how many are black and how many white?

Click for Answer