Project Euler meets Powershell - reworking factorial to avoid PowerShell 1000 recursions limit

Turns out it was the recursion the factorial function - I’ve reworked it to use a for loop

function factorial {
	[cmdletbinding()]
	param($x)
	if ($x -lt 1) {
		return "Has to be on a positive integer"
	}
    Write-Verbose "Input is $x"
    $fact = 1
	for ($i = $x; $i -igt 0; $i -= 1){
        #Write-verbose "i: $i"
		$fact = [System.Numerics.BigInteger]::Multiply($i , $fact)
	}
    Write-Verbose "i equals $i"
    $fact
}

it’s still running for factorial 486847…