我正在制作快速计算阶乘的函数.像这样
func factorial(factorialNumber: UInt64) -> UInt64 {
if factorialNumber == 0 {
return 1
} else {
return factorialNumber * factorial(factorialNumber - 1)
}
}
let x = factorial(20)
Run Code Online (Sandbox Code Playgroud)
这个功能可以计算直到20.
我认为factorial(21)的值大于UINT64_MAX.
然后如何计算21!(21阶乘)快速?
此代码在 Playground 中运行良好
import Foundation
let stringDate : NSString = "1403437865"
let date = NSDate(timeIntervalSince1970:stringDate.doubleValue)
var outputFormat = NSDateFormatter()
outputFormat.locale = NSLocale(localeIdentifier:"ko_KR")
outputFormat.dateStyle = .MediumStyle
outputFormat.timeStyle = .MediumStyle
println("Result: \(outputFormat.stringFromDate(date))")
Run Code Online (Sandbox Code Playgroud)
但此代码在 Playground 中不起作用
import Cocoa
let stringDate : NSString = "1403437865"
let date = NSDate(timeIntervalSince1970:stringDate.doubleValue)
var outputFormat = NSDateFormatter()
outputFormat.locale = NSLocale(localeIdentifier:"ko_KR")
outputFormat.dateStyle = .MediumStyle
outputFormat.timeStyle = .MediumStyle
println("Result: \(outputFormat.stringFromDate(date))")
Run Code Online (Sandbox Code Playgroud)
只有不同的 1 行“进口可可”!
游乐场的bug?