Step 9: What have we calculated?

So what have we calculated with our collatz function? It’s the number of steps it takes to reach 1 from a starting number n.

So now we can see what that list of random-looking numbers was that we saw earlier: it’s how many steps it takes for each number from 2 to 11 inclusive to reach 1 when we repeatedly halve the number if it’s even, or multiply 3 and add 1 if it’s odd.

In this chapter we saw some of the building blocks of Ursa: variables, assignment, conditionals, loops and functions. We wrote some code to count, and read some code that did something used counting numbers to test a mathematical conjecture.

In the next chapter, we’ll use a completely different example to revisit the same building blocks.

Unreal, artless