Pythonmatics

Solving mathematical problems with Python

Category: Uncategorized

  • Goldbach’s conjecture

    I bought the book Uncle Petros and Goldbach’s Conjecture by Apostolos Doxiadis in my twenties and immediately shared it with my father. The book tells with great charm the story of an elderly and isolated mathematical genius who tries to solve the puzzle that has eluded so many: Goldbach’s conjecture. It seems so simple: “every…

  • Python-agorean

    One of the most famous mathematical statements is the Pythagorean theorem, which asserts that for a right triangle with sides an and b and hypotenuse c, the relationship a2 + b2 = c2 holds. If the lengths of the sides are natural numbers, then the triple of values (a, b, c) is called a Pythagorean…

  • Islands of order

    As a young person, I was deeply influenced by the book Chaos: Making a New Science by James Gleick that my father purchased. The book presents the principles behind chaos theory in an accessible way and includes stunning images of various types of fractals. I vividly recall being fascinated by the images of the Mandelbrot…

  • Triangle surprise

    My father used to program in the Logo language back in the 1980s. Although Logo also supported text-based commands, it was widely known for its use of turtle graphics. For those who are less familiar with this term, turtle graphics are based on a cursor (also known as a ‘turtle’) that the code can turn…

  • Not exactly in the middle

    This riddle was given to my son during an online math course: There are 42 tiles in a line. How many tiles can be marked so that no marked tile is located exactly between two other marked tiles? Honestly, I’m not sure how to tackle this puzzle without the assistance of a computer. When it…

  • One hundred lamplighters

    My father presented this surprising math puzzle to me when I was a kid. It begins with the city’s main street, which has 100 light poles numbered from 1 to 100, and 100 lamplighters, also numbered from 1 to 100. Initially, all the lights are turned off. Lamplighter #1 goes over the poles one after…

  • Monte Carlo Pie

    The Monte Carlo algorithm uses randomness to provide an estimated result for a mathematical problem instead of computing the exact result, which might be complicated. For example, the probability of getting the sum 6 when two dice are thrown is 5/36 (approximately 0.1389). This code estimates this probability by simulating 1,000,000 throws and calculating the…

  • Perfect numbers

    A perfect number is a number that equals the sum of its divisors, excluding the number itself. The first number that comes to mind is 6, as its divisors are 1, 2, and 3, and 1 + 2 + 3 = 6. The next perfect number is 28 (1 + 2 + 4 + 7…

  • The Sieve of Eratosthenes

    A prime number is a number that can only be divided by 1 and itself without remainders. My father taught me that 1 is a “special number” which is neither a prime number nor a composite number. A classic computer programming task is to find all the prime numbers from 2 (the first prime) to…

  • Where it all began

    My father was an autodidact. Among his countless other interests, including woodturning, photography, and shooting sports, he had a great passion for math. As a young kid, he introduced me to the beauty of mathematics and could talk for hours about Mersenne primes, the Koch snowflake, the Sieve of Eratosthenes, or the Sierpiński triangle. Another…