Numbers and Math for Beginners
FizzBuzz, primes, Fibonacci, GCD and digit tricks: the number puzzles that build problem-solving confidence.
- FizzBuzz The classic: count from 1 to n, replacing multiples of 3 with Fizz, of 5 with Buzz, and of both with FizzBuzz.
- Factorial Compute n! = 1 × 2 × ... × n.
- Fibonacci Number Return the nth Fibonacci number, where each number is the sum of the two before it.
- Is It Prime? Check whether a number is prime by testing divisors up to its square root.
- Greatest Common Divisor Find the largest number that divides two numbers, with Euclid's algorithm.
- Sum of Digits Add up the digits of a non-negative integer.
- Power of Two Check whether a number is a power of two (1, 2, 4, 8, ...).
- Count Primes Below n Count the prime numbers less than n using the Sieve of Eratosthenes.
- Leap Year Decide whether a year is a leap year in the Gregorian calendar.
- Reverse an Integer Reverse the digits of an integer, keeping its sign.
- Armstrong Number Check whether a number equals the sum of its digits each raised to the number of digits.