Module 6 · Loops and Jump Statements
Thinking in Loops: Sums, Digits, Primes
Free with an accountReading
Bob wrote a prime checker in four minutes. He tried it on 97, it said "97 is prime", and he called it done. 97 is a very cooperative number.
Checking what this lesson needs for you…
What is inside Thinking in Loops: Sums, Digits, Primes
- The accumulator: one box that grows every pass
- The digit loop: % takes a digit, / removes it
- Reversing and counting digits
- Is it prime? Trial division, and where to stop
- Euclid's gcd: the remainder does the work
- Fibonacci: two variables, and where long long runs out
- Zara's rule: test 0, 1 and 2 first