Swift: New 21 Game (+ Test Cases)
swift\nclass Solution {\n    func new21Game(_ n: Int, _ k: Int, _ maxPts: Int) -> Double {\n        guard k != 0 && n < (k + maxPts) else { return 1.0 }\n      
```swift\nclass Solution {\n    func new21Game(_ n: Int, _ k: Int, _ maxPts: Int) -> Double {\n        guard k != 0 && n < (k + maxPts) else { return 1.0 }\n        var dp = [Double](repeating: 0, count: n+1)\n        dp[0] = 1.0\n        var result = 0.0, val = 1.0\n        for i in 1...n {\n            dp[i] = val / Double(maxPts)\n            i < k ? (val += dp[i]) : (result += dp[i])\n            if i - maxPts >= 0 { val -= dp[i - maxPts] }\n        }\n        return result\n    }\n}\n```\n\n```swift\nimport XCTest\n\n// Executed 3 tests, with 0 failures (0 unexpected) in 0.006 (0.007) seconds\n// In the examples for the task the values seem to have been rounded up\n\nclass Tests: XCTestCase {\n    private let s = Solution()\n    func test1() {\n        XCTAssertEqual(s.new21Game(10, 1, 10), 0.9999999999999999) // 1.00000\n    }\n    func test2() {\n        XCTAssertEqual(s.new21Game(6, 1, 10), 0.60000)\n    }\n    func test3() {\n        XCTAssertEqual(s.new21Game(21, 17, 10), 0.7327777870686082) // 0.73278\n    }\n}\n\nTests.defaultTestSuite.run()\n```
['Swift']