initial solution, with solution checking, and an attempt at a smarter
solution using expected frequency counts