My solution in Swift, factorial numbers are too big for Int but it's really bored to deal with NSDecimalNumber :
Int
NSDecimalNumber
extension Int { var factorial: UInt64 { (1...self).reduce(into: UInt64(1)) { $0 *= UInt64($1) } } func numberOfDivision(with number: Int) -> Int { guard number != 1 else { return 1 } var loop = 0 var value = self.factorial while value % UInt64(number) == 0 { value /= UInt64(number) loop += 1 } return loop } var primeNumbers: [Int] { (1..<self).filter { number in number > 1 && !(2..<number).contains { number % $0 == 0 } } } } func decomp(factorial: Int) -> String { factorial.primeNumbers.reduce(into: [String]()) { let numberOfDivision = factorial.numberOfDivision(with: $1) return $0.append("\($1)\(numberOfDivision == 1 ? "" : "^\(numberOfDivision)")") }.joined(separator: " * ") }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My solution in Swift, factorial numbers are too big for
Int
but it's really bored to deal withNSDecimalNumber
: