Created
May 18, 2013 13:35
-
-
Save iamshanto/5604404 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function bcfact($n){ | |
$factorial=$n; | |
while (--$n > 1) { | |
$factorial = bcmul($factorial,$n); | |
} | |
return $factorial; | |
} | |
function getFileContent() | |
{ | |
$file = 'input.txt'; | |
return array_filter(explode(PHP_EOL, file_get_contents($file))); | |
} | |
function run() | |
{ | |
$numbers = getFileContent(); | |
foreach ($numbers as $number) { | |
$output[] = $number . ' -> ' . substr(trim(bcfact($number),0), -1); | |
} | |
file_put_contents('output.txt', implode(PHP_EOL, $output)); | |
} | |
$eStart = microtime(true); | |
run(); | |
$eEnd = microtime(true); | |
echo 'Execution time: ' . ($eEnd - $eStart) * 1000 . ' ms' . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment