I'm working on an Io problem that involves the Fibonacci sequence. I'm trying to create a method that tests if a number is a Fibonacci number or not. I can't figure out why my IsAFib method isn't working, does anyone know why and what I can do to fix it? I'm really new to Io, and pretty new to programming too, so if you could be descriptive with your reasons for changing things, I would really appreciate it! I want to know what it needs to be different, not just what it should be written as.
OperatorTable addOperator("xor", 11)
true xor := method(bool, if(bool, false, true))
false xor := method(bool, if(bool, true, false))
doFile("isASquare.io");
Then the isASquare.io file:
isASquare := method(n,
for(i, 1, n,
if(i * i == n, return true)
if(i * i > n, return false)
)
)
isAFib := method(n,
if(isASquare(2 ** 5 * n) xor isASquare(2 ** n * 5 - 4), return true, return false)
)