import math
rows = 20
cols = 20
r_center = (rows - 1) / 2.0
c_center = (cols - 1) / 2.0
radius = r_center - 1
epsilon = 0.5
output = []
for r in range(rows):
row_str = ""
for c in range(cols):
dist = math.sqrt((r - r_center)**2 + (c - c_center)**2)
if abs(dist - radius) < epsilon:
row_str += "1"
else:
row_str += "0"
output.append(row_str)
print("\n".join(output))\(\pi\) Contains a Circle Inside?
The following section reveals the central mystery of Carl Sagan’s novel Contact (1985) and the 1997 film based on it. If you plan to read or watch it first, skip ahead to the Computational Math Is Useful section below.
Public domain, via Wikimedia Commons (NASA/JPL-Caltech)
In late Dr. Carl Sagan’s science fiction novel Contact (Sagan 1985), a radio telescope picks up a signal from the star Vega, 26 light years away. The signal has layers.
The first layer is prime numbers: 2, 3, 5, 7, 11, 13… broadcast as deliberate pulses. Primes are the aliens’ way of saying we are here and we are not an accident — because only an intelligent mind would single out exactly those numbers. Any civilization that builds a radio telescope already recognizes them as special. You will meet primes in 1 Prime Numbers: The Atoms of Arithmetic.
The second layer is stranger: a retransmission of humanity’s own 1936 Olympic broadcast from Berlin — the first television signal ever powerful enough to escape Earth’s atmosphere — bounced back from 26 light years away. The message: we have been listening.
The third layer, decoded with a mathematical primer hidden in the signal’s phase modulation, is a set of blueprints: 30,000 pages of instructions for building a machine. A five-seat machine. The nations of Earth argue, build it, and send five people inside.
Ellie Arroway — astronomer, SETI researcher, protagonist — is one of them. What happens inside the machine is the heart of the novel. At the end of the journey, she meets an entity that takes the form of her late father. And it tells her something:
There are messages hidden inside transcendental numbers. Look deep enough into \(\pi\), and you will find one.
Ellie runs the computation. At the \(100{,}000{,}000{,}000{,}000{,}000{,}000\)th digit of \(\pi\), in base 11 — a number system that uses eleven symbols instead of ten — a \((2 \times 3 \times 5 \times 7 \times 11 \times 13 \times 17 \times 19 \times 23 \times 29 \times 31 =)\) \(200{,}560{,}490{,}130\) digits-long pattern emerges.
This is how the book describes what she sees:
The anomaly showed up most starkly in Base 11 arithmetic, where it could be written out entirely as zeros and ones. […] The program reassembled the digits into a square raster, an equal number across and down. The first line was an uninterrupted file of zeros, left to right. The second line showed a single numeral one, exactly in the middle, with zeros to the borders, left and right. After a few more lines, an unmistakable arc had formed, composed of ones. The simple geometrical figure had been quickly constructed, line by line, self-reflexive, rich with promise. The last line of the figure emerged, all zeros except for a single centered one.
The circle was already there, baked into \(\pi\) itself, as if placed by whoever wrote the laws of the universe. If this were to ever happen in your career, the tools needed to find it: an understanding of prime numbers, the digits of \(\pi\), and the ability to read base 11. All of it computational mathematics. All of it things you will learn in this book.
How to compute \(\pi\) to such depths is covered in Computing π: Machin’s Formula and The BBP Formula: Extracting Any Digit of π. You will learn how number bases work and how to read base 11 in Positional Notation and Base Conversion.
Computational Math Is Useful
Mathematics is a lens. Through computation, it reveals structure invisible to the naked eye: patterns inside the digits of \(\pi\), order concealed in the primes, secrets encoded in ordinary integers. Students who use mathematics — who run the experiments, generate the sequences, and look for the patterns themselves — understand it in a way no textbook delivers. You do not memorize a secret. You discover it. That changes everything.
Public domain, via Wikimedia Commons
G. H. Hardy was one of the greatest mathematicians of the twentieth century — and he was proud, genuinely proud, that his work had no practical use. In A Mathematician’s Apology (Hardy 1940), written in 1940, he declared:
“No discovery of mine has made, or is likely to make, directly or indirectly, for good or ill, the least difference to the amenity of the world.”
Hardy specialized in number theory: the study of integers, primes, and their hidden relationships. He called pure mathematics a form of art, valuable the way poetry or chess is valuable — for its beauty, not its utility. The “great bulk of higher mathematics,” he wrote, is useless in any practical sense, and he celebrated that fact.
He wrote those words in 1940. That same year, Alan Turing was using number theory and modular arithmetic to break the Nazi Enigma cipher at Bletchley Park. The Enigma machine encrypted every German military communication during World War II. Turing’s team cracked it using precisely the kind of abstract mathematical reasoning Hardy celebrated as useless. Historians estimate that breaking Enigma shortened the war by two years and saved millions of lives. You will see where this long tradition of cryptography leads in 3 Cryptography and Steganography: The Art of Hidden Messages.
The story did not stop there. In 1978, three mathematicians — Rivest, Shamir, and Adleman — published an encryption scheme built on a single observation from number theory: multiplying two enormous prime numbers together is easy, but working backwards to recover those primes from the product is practically impossible (Rivest et al. 1978). That method is RSA encryption. It protects nearly every private transaction on the internet today — your passwords, your credit card numbers, your money transfers. You will build it yourself in RSA: The Lock That Anyone Can Close.
Number theory: the art Hardy called useless. Nation-saving in 1940. Internet-saving from 1978 onward. And possibly alien-connecting at the \(10^{20}\)th digit of \(\pi\).
All of this useful mathematics has one thing in common: it is computational. Don’t worry that your high school does not teach computational math yet. You will learn it in this book.
A Computational Note on the Circle Inside \(\pi\)’s Digits
Let’s examine the circle inside \(\pi\) described in Contact. No, I did not compute \(\pi\) to the \(10^{20}\)th digit. What follows is my simulation based on what Sagan wrote — “a circle drawn in zeros and ones” with “an equal number across and down.”
Although I arbitrarily chose 20, you can change rows and cols value to any other numbers to find out what happens. Fair warning about what you will see: the output looks stretched, not square, because a text character is taller than it is wide. And the novel’s detail of a lone 1 on the very first and last lines cannot happen with any sizable circle because the top and bottom arcs of a circle are famously flat, i.e., the derivative is zero. You get that lone 1 only when the circle is very small. Try it yourself running the code below.
# uses: output
#| echo: false
print("\n".join(output))00000000000000000000
00000001111110000000
00000110000001100000
00001000000000010000
00010000000000001000
00100000000000000100
00100000000000000100
01000000000000000010
01000000000000000010
01000000000000000010
01000000000000000010
01000000000000000010
01000000000000000010
00100000000000000100
00100000000000000100
00010000000000001000
00001000000000010000
00000110000001100000
00000001111110000000
00000000000000000000
Could we really see the output above inside the good old \(\pi\)?
We do not know yet. This is supposed to happens at the \(10^{20}\)th digit of \(\pi\) in base 11. Currently, farthest the humanity has reached is \(314{,}000{,}000{,}000{,}000\) digits, which is in the order of \(10^{14}\) in base 10 (O’Brien and Beeler 2025). Six more orders of magnitude to go. Want to give it a try using algorithms explained in Computing π: Machin’s Formula and The BBP Formula: Extracting Any Digit of π?
Maybe you will be the the first to get there.
