Mathematics is incredibly useful, essential for our understanding of the
physical sciences and nature in general, and for the modeling of everything from
games of chance to economics. Mathematics can also be fun, giving rise to an
endless variety of puzzles. In this web page, I focus on some beautiful aspects
of mathematics; I've tried to present this material so as to make it accessible
to the widest possible audience.
find_composite
and
next_composite
to the primes.py
module. Both of these functions find composite integers of the form
p1^n1 * p2^n2 ..., where
p1, p2, ... are specified prime numbers and n1,
n2, ... are arbitrary non-negative integers, but the two functions
use very different algorithms. The first uses the simple, brute-force approach
of testing all integers. The second returns a generator; the algorithm uses a
priority queue to ensure that values are returned in the correct order. The
algorithm is highly time efficient, but the length of the queue does gradually
grow.