ScratchData LogoScratchData
Back to nathanprocks's profile

Fast Fibonacci number test

NAnathanprocks•Created June 26, 2014
Fast Fibonacci number test
9
6
322 views
View on Scratch

Instructions

This custom block tests if a number is a Fibonacci number. Generating Fibonacci numbers in the project is slow because it tests every number. This method allows you to generate Fibonacci numbers starting from any number. If you want a fast Fibonacci number generator that allows you to start from any number, you can use this method to generate the first two numbers and add them together, etc.

Description

I was inspired to make this by a question on Quora and because I was bored. Basically, a number is a Fibonacci number if (5n^2+4) or (5n^2-4) is a perfect square. To check if the result is a perfect square, I get the square root of the result % 1. If result of that is 0, then it is a perfect square!

Project Details

Project ID24080970
CreatedJune 26, 2014
Last ModifiedJuly 24, 2015
SharedJune 26, 2014
Visibilityvisible
CommentsAllowed