Skip To Main Content
Tonight’s Math Homework: Set Theory and Sudoku

March 4, 2021 — Sudoku puzzles are ubiquitous: They’re in every newspaper alongside the comics; in airport convenience stores; and online, where they range in difficulty from “easy” to “evil.” But are they math homework?

Yes, says NMH faculty member David Warren. He teaches a course called Discrete Math with Python, which blends mathematics and computer science. Students learn about sets, algorithms, sequences, and combinations, and use the Python programming language to apply their theoretical learning. When they tackled set theory recently, they practiced by designing and implementing an algorithm that could solve Sudoku puzzles. One student, Tyler Kristjansen ’21, took it a step further, making an algorithm that created the puzzles as well. “I joked that we could go into business by printing cheap Sudoku books to sell in airports,” Warren said. 

Sudoku puzzles are like crosswords, but with numbers instead of words. Every puzzle has 81 spaces, or cells — nine squares with nine cells in each square, three rows of three, with a handful of the cells already filled in with a number between 1 and 9. Using logic and trial and error, the person solving the puzzle — or in the case of Warren’s class, the algorithm — fills in the rest of the blank spaces with only the numbers 1 through 9, without repeating a number in each row, each column, and each 3x3 square. “With set theory — creating sets of different numbers — we can deduce,” Warren says, which numbers need to go in which blank spaces. “For any given blank cell, the potential digits we can place — also known as ‘candidates’ — are the digits that haven’t been used in the column, row, or square that the cell is within.”

The class used the programming language Python to create mathematical functions that proposed candidates to fill in each blank space. First they tackled each row, then each column, then each square. “Once we created the tool, or the algorithm, we just ran it a lot,” Warren said. The process, he added, “was like a blend of smart brute force and smart random choice.”

If you’re not a math person, set theory may sound confusing. Warren says it’s actually not. “Anything that is an unordered group of things without any repetitions is a set,” he says. “A box of Crayola crayons is a set. The students in our math class are a set. These are both discrete groups of unique things that can be added and subtracted. Every day, people work with sets. They just don’t realize it.”