Josh Crompton

4: Io Day 2 Self-study: I hate contrived examples especially when they involve math

Like it says in the title. The first self-study problem is as follows:

A Fibonacci sequence starts with two 1s. Each subsequent number is the sum of the two numbers that came before: 1, 1, 2, 3, 5, 8, 13, 21, and so on. Write a program to find the nth Fibonacci number. fib(1) is 1, and fib(4) is 3. As a bonus, solve the problem with recursion and with loops.

Recursion is easy for these problems:

Object fib := method(n, if (n == 0, 0, if(n == 1, 1, fib(n-1) + fib(n-2))))

Not so loops. I gave up after a while. On the other hand, this has caused me come to appreciate the importance of a good emacs mode for writing code in weird new languages.