Skip to content

Instantly share code, notes, and snippets.

@iamshanto
Created May 18, 2013 13:35
Show Gist options
  • Save iamshanto/5604404 to your computer and use it in GitHub Desktop.
Save iamshanto/5604404 to your computer and use it in GitHub Desktop.
<?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