So thankfully I got myself out of infinite loop hell with this problem. The real kicker behind this one is to get the current number to add itself over and over again using an until loop. The thing that almost sunk me is that I had written until curr == n // return true instead of curr >= n so when the number skipped over it became an infinite loop. Small fix, but so relieved when I fixed it.
def is_fibonacci?(n)
curr = 0
succ = 1
until curr >= n
curr, succ = succ, curr + succ
end
if curr == n
return true
else
return false
end
end
No comments:
Post a Comment