Avatar
Avatar
log5
@swift-5.4.3 // may cause "Cannot convert value of type 'Int' to expected argument type 'Builtin.FPIEEE64'" import Foundation let (N, M, K) = {() -> (Int, Int, Int) in let v = readLine()!.split(separator:" ").map{Int($0)!} return (v[0], v[1], v[2]) }() guard N - M >= K else { print(1.0) exit(0) } let b: [Double] = stride(from: N, through: N - K + 2, by: -1) .map({ i -> Double in Double(i)}) .map({ e -> Double in Double(e - 1 - M) / e }) let hazure = b.reduce(1.0) { (partialResult: inout Double, v: Double) -> Double in partialResult * v } let atari: Double = Double(M) / Double(N - K + 1) print(hazure * atari)
exit status: 1 with stderr:<stdin>:15:10: error: the compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions .map({ e -> Double in Double(e - 1 - M) / e }) ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <stdin>:16:28: error: cannot convert value of type '(inout Double, Double) -> Double' to expected argument type '(Double, Double) throws -> Double' let hazure = b.reduce(1.0) { (partialResult: inout Double, v: Double) -> Double in partialResult * v } ^