Skip to content

Instantly share code, notes, and snippets.

@johnholbrook
Created July 7, 2013 02:36
Show Gist options
  • Select an option

  • Save johnholbrook/5942052 to your computer and use it in GitHub Desktop.

Select an option

Save johnholbrook/5942052 to your computer and use it in GitHub Desktop.
Applescript Fibonacci FInder
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