Skip to content

Instantly share code, notes, and snippets.

@iidaatcnt
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iidaatcnt/ff7066e0eb4521e3c85f to your computer and use it in GitHub Desktop.
Save iidaatcnt/ff7066e0eb4521e3c85f to your computer and use it in GitHub Desktop.
100個のフィボナッチ数のリストを計算せよ(但しできるところまで)
#!/usr/bin/env xcrun swift
func FibonacciGen(inout fibtbl:[Int]) {
var f0 = 0
var f1 = 1
var fib = 0
fibtbl[0] = 0
fibtbl[1] = 1
for var i = 2; i < 100; i++ {
fib = f0 &+ f1
if fib < 0 {
println("\(i+1): Over floow")
break
}
fibtbl[i] = fib
f0 = f1
f1 = fib
}
return
}
var fibtbl:[Int] = Array(count: 100, repeatedValue: 0)
FibonacciGen( &fibtbl )
for var i = 0; i < fibtbl.count; ++i {
println("\(i)\t\(fibtbl[i])")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment