Created
July 7, 2013 02:36
-
-
Save johnholbrook/5942052 to your computer and use it in GitHub Desktop.
Applescript Fibonacci FInder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| set f1 to 1 | |
| set f2 to 2 | |
| set numToCalc to text returned of (display dialog "Which fibonacci number should I calculate?" default answer "") | |
| if numToCalc is less than or equal to 2 then | |
| display dialog "Error! Pick a whole number larger than 2!" | |
| error number -128 | |
| end if | |
| set repeatcount to numToCalc - 2 | |
| repeat repeatcount times | |
| set fn to f1 + f2 | |
| set f1 to f2 | |
| set f2 to fn | |
| end repeat | |
| display dialog ("The " & numToCalc & "th Fibonacci number is " & f2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment