You are viewing a single comment's thread. Return to all comments →
Swift
Quite harsh problem considering the constraints, some attention must be paid to the typing of the problem.
func superDigit(n: String, k: Int) -> Int { let digits = Array(n).compactMap{ UInt8(String($0)) } func computeSD(digits: [UInt8]) -> UInt8 { if digits.count == 1 { return digits.first! } let sum: UInt = digits.reduce(0) { UInt($0) + UInt($1) } return computeSD(digits: Array(String(sum)).compactMap{ UInt8(String($0)) }) } var superDigit: Int = Int(computeSD(digits: digits)) superDigit *= Int(k) return Int(computeSD(digits: Array(String(superDigit)).compactMap{ UInt8(String($0)) })) }
Seems like cookies are disabled on this browser, please enable them to open this website
Recursive Digit Sum
You are viewing a single comment's thread. Return to all comments →
Swift
Quite harsh problem considering the constraints, some attention must be paid to the typing of the problem.