Coding challenge

Pick any number you like—$5$, $-100$, $0.5$, or $1000000$. Write a loop that takes the cosine of your number, then the cosine of that result, and repeats this $100$ times (remembering that Lua's math.cos uses radians).

What number do you always end up with, regardless of your starting value? Can you explain why?

(Hint: You are finding the unique real root of $\cos(x) = x$, known as the Dottie number: $0.739085...$)

Type your code here:


Lua reference

See your results here: