A generator, duck typing, and a branchless conditional walk into a bar.
The only way to learn mathematics is to do mathematics.