小编dia*_*ike的帖子

如何计算21!(21阶乘)快速?

我正在制作快速计算阶乘的函数.像这样

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阶乘)快速?

math swift

9
推荐指数
2
解决办法
8057
查看次数

Xcode 的 Playground 中的“import Cocoa”和“import Foundation”有什么不同

此代码在 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?

xcode swift

7
推荐指数
1
解决办法
7143
查看次数

标签 统计

swift ×2

math ×1

xcode ×1