Eleven problems for one loop at a time: ranges, steps, multiples, squares and powers, and the first divisor. Start with the first one and go in order.
- Count before you submit: does
i <= nori < ngive the right number of iterations? Test the smallest input by hand. - All even counts down: start from the largest even number not above
N, and step by −2. ForN = 1nothing is printed — and that is the right answer. - 123 doesn't need a string: the
i-th character isi % 3 + 1whenicounts from 0. - Squares and Powers of 2 stop at a value, not after a number of steps:
loop while the next square or power is still small enough.
i * ican pass 2 · 10⁹ near the end, so keep it inlong long. - The second smallest divisor is the lesson's largest divisor turned around: go up from 2 and stop at the first divisor.
- Multiplication by 2 to the limit counts the doublings with a
while. Its tests go up tox = 10⁹, more than the statement says, and the answer is still right.