Created
June 10, 2012 12:35
-
-
Save saml/2905324 to your computer and use it in GitHub Desktop.
This file contains 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
{- ghc --make -O fib.hs | |
- ./fib <nth, such as 2607> <n-2 th fib> <n-1 th fib> | |
- example: | |
- ./fib 2583 180551925061996205582978676340396483148301922241771467739409810875233316279485917014169163475036188290260285027955156899207469403601685576648406557607174860852985399401107639843026289770321769850482975727659384712460509577795642089737397394352904471219631366377829901834818963919229137581230848941593109666718488092686220811682606140987563858018416173600757618522208289638064871472462821318933543944865008389403524910775693844630469532937155177666299240625507834460491424634356297396468525803122641719996486746805680623277512059420507512841 292139151484533826197706434547293236461825913269405499675521785336656487530015138036693796111711074512728386715633214956693186551529233175182223532132594800345230312768192244337818506046340578811459659022923683361201917577311144638325207394463935190122631204589004916971540204315961324259943543256444766123693082652262647728967183949454165466602627699125226156015855371375896441993109851160303419881850803838054854609318969099522177278506503910035700385955176114185594592239918745631384451882055830667122492485562765452900213080346938681122 | |
- then keep pressing enter to proceed to the next number | |
-} | |
import System.Environment (getArgs) | |
import Text.Printf (printf) | |
fib nth a b = do | |
let c = a + b | |
printf "F(%d) =\n\n" (nth :: Int) | |
print c | |
getLine | |
fib (nth+1) b c | |
main = do | |
argv <- getArgs | |
let nth = read $ argv !! 0 | |
let a = read $ argv !! 1 | |
let b = read $ argv !! 2 | |
fib nth a b |
This file contains 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
import sys | |
def fib(n, n_2, n_1): | |
while True: | |
result = n_2 + n_1 | |
print('''F(%d) = | |
%d''' % (n, result)) | |
raw_input() | |
n_1 = n_2 | |
n_2 = result | |
n = n + 1 | |
fib(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3])) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment