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

  1. Two Clocks, One Time (Easy, free): One clock chimes every m1 minutes and last chimed r1 minutes after the hour.
  2. Digit Sum (Easy): Given a number, return the sum of its digits.
  3. Digital Root (Easy): Given a number, add up its digits.
  4. Factorial (Easy): Given n, return n factorial: 1 x 2 x 3 x ...
  5. Greatest Common Divisor (Easy): Given two numbers a and b, return their greatest common divisor, the biggest number that divides both.
  6. Least Common Multiple (Easy): Given two numbers, return their least common multiple, the smallest number both divide evenly.
  7. Perfect Number (Easy): Given n, return true if it's a perfect number, meaning it equals the sum of its divisors other than itself.
  8. Sum 1 to N (Easy): Given n, return the sum of every whole number from 1 to n.
  9. 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.
  10. 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.
  11. 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.
  12. Count Divisors (Medium): Given n, return how many positive whole numbers divide it evenly.
  13. Factorial Trailing Zeros (Medium): Given n, return how many zeros are at the end of n factorial, without computing it.
  14. 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.
  15. Modular Exponentiation (Medium): Given base, exp, and mod, return base to the power exp, mod m, without the number blowing up.
  16. Newton's Square Root (Medium): Given n, return its square root, rounded to 3 decimals, using Newton's method.
  17. 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.
  18. Pascal's Triangle (Medium): Given numRows, return the first numRows rows of Pascal's triangle.
  19. Pascal's Triangle Row (Medium): Given n, return row n of Pascal's triangle, starting from row 0, which is [1].
  20. Power (a^b) (Medium): Given a and b, return a to the power b.
  21. Power of Two? (Medium): Given n, return true if it's a power of two, like 1, 2, 4, or 8.
  22. Reverse Integer (Medium): Given a whole number, return it with its digits reversed and its sign kept.
  23. Sieve of Eratosthenes (Medium): Given n, return every prime up to and including n.
  24. A Prime Test That Scales (Hard, free): Trial division is hopeless for the huge primes cryptography needs.
  25. 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.
  26. Collatz Steps (Hard): Given n, return how many steps it takes to reach 1.
  27. 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