Here's a function in Swift that determines if a number x
is the factorial of another number:
main.swift181 chars12 lines
The function uses a while
loop to continuously multiply consecutive natural numbers until the factorial is greater than or equal to the input x
. Then, the function returns true
if the resulting factorial is equal to x
, otherwise it returns false
.
gistlibby LogSnag