All puzzles › Math
Math Practice Problems
27 puzzles (8 easy, 15 medium, 4 hard), 6 free, in Python, JavaScript and C++.
Primes, sequences, GCD and number tricks as puzzles.
The puzzles, easiest first
- Two Clocks, One Time (Easy, free): One clock chimes every m1 minutes and last chimed r1 minutes after the hour.
- Digit Sum (Easy): Given a number, return the sum of its digits.
- Digital Root (Easy): Given a number, add up its digits.
- Factorial (Easy): Given n, return n factorial: 1 x 2 x 3 x ...
- Greatest Common Divisor (Easy): Given two numbers a and b, return their greatest common divisor, the biggest number that divides both.
- Least Common Multiple (Easy): Given two numbers, return their least common multiple, the smallest number both divide evenly.
- Perfect Number (Easy): Given n, return true if it's a perfect number, meaning it equals the sum of its divisors other than itself.
- Sum 1 to N (Easy): Given n, return the sum of every whole number from 1 to n.
- A Shared Secret, Agreed in Public (Medium, free): With Diffie-Hellman, two strangers can agree on a secret number while an eavesdropper hears every word.
- Dividing When There Is No Division (Medium, free): In arithmetic modulo m, dividing by a means multiplying by its inverse: the number x with a times x leaving remainder 1.
- Lock With One Key, Open With Another (Medium, free): RSA has a public key anyone can encrypt with and a private key that only its owner can compute.
- Count Divisors (Medium): Given n, return how many positive whole numbers divide it evenly.
- Factorial Trailing Zeros (Medium): Given n, return how many zeros are at the end of n factorial, without computing it.
- Is It Prime? (Medium): Given n, return true if it's prime, meaning it's bigger than 1 and only divisible by 1 and itself.
- Modular Exponentiation (Medium): Given base, exp, and mod, return base to the power exp, mod m, without the number blowing up.
- Newton's Square Root (Medium): Given n, return its square root, rounded to 3 decimals, using Newton's method.
- Nth Fibonacci (Medium): Given n, return the nth Fibonacci number, where fib(0) is 0, fib(1) is 1, and every number after is the sum of the two before it.
- Pascal's Triangle (Medium): Given numRows, return the first numRows rows of Pascal's triangle.
- Pascal's Triangle Row (Medium): Given n, return row n of Pascal's triangle, starting from row 0, which is [1].
- Power (a^b) (Medium): Given a and b, return a to the power b.
- Power of Two? (Medium): Given n, return true if it's a power of two, like 1, 2, 4, or 8.
- Reverse Integer (Medium): Given a whole number, return it with its digits reversed and its sign kept.
- Sieve of Eratosthenes (Medium): Given n, return every prime up to and including n.
- A Prime Test That Scales (Hard, free): Trial division is hopeless for the huge primes cryptography needs.
- Any Few Pieces Open the Vault (Hard, free): A secret can be split so that any k people together can recover it and any fewer learn nothing.
- Collatz Steps (Hard): Given n, return how many steps it takes to reach 1.
- Count Primes (Hard): Given n, return how many prime numbers are less than n.
Practice another pattern
Or browse by subject
Browse all 676 puzzles