In: Computer Science
Using the combination of HTML and PHP, implement a web page where the users can upload a text file, exclusively in .txt format, which contains a string of 1000 numbers, such as:
71636269561882670428252483600823257530420752963450
85861560789112949495459501737958331952853208805511
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
96983520312774506326239578318016984801869478851843
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
05886116467109405077541002256983155200055935729725
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
62229893423380308135336276614282806444486645238749
73167176531330624919225119674426574742355349194934
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
Your code should contain a PHP function that, accepting the string of 1000 numbers in input, is able to:
1) Find the 5 adjacent numbers that multiplied together give the largest product.
2) Given the product from above, computes the sum of the factorial of each term of such product
Example, if the product is 5046, computes 5! + 0! + 4! + 6!
NOTE:
//HTML file
<html> <body> <form action="prog.php"
method="post">
File name: <input type="text" fname="fname" /> <input
type="submit" /> </form> </body> </html>
// Prog.php file
<?php
$c = fopen("fname", "r") or die("Can not open File! Try
again");
echo fread($c,filesize("input.txt"));
fclose($c);
$inptlen= strlen($c[0]);
if( $inptlen > "999") // checking for the length is 1000 or
less that that
{
for($i= 0; $i<$inptlen ; $i++)
{
$asc = ord($c[$i]); // checks whether any character is present or
not based on ascii
if ($asc>="48" && $asc<= "57") //as the 0-9 ascii
lies from 48-57 , we are checking for that
{
$numb[$i]= (int)$c[$i];
}
else
{
echo "\nWrong !!! file format \n";
}
}
for ($j =0; $j<$inptlen-5;$j++)
{
$mul[$j] =
$numb[$j]*$numb[$j+1]*$numb[$j+2]*$numb[$j+3]*$numb[$j+4]; // the
multiplication of 5 consecutive values
}
$highest= (string)max($mul); // highest value from the
multiplications
$nochar=strlen($highest); // converting number in to digits using
string maping
for($k=0;$k<$nochar;$k++) // factorization of digits
{
$fact= 1;
for($g=(int)$highest[$k]; $g>=1; $g--)
{
if($g=="0")
{
$fact=1;
}
else
{
$fact = $fact * $g;
}
}
$factresult[$k]=$fact;
}
$s=0;
for($b=0;$b<$nochar;$b++)
{
$s=$s+$factresult[$b]; //sum of factorials
}
echo "Final Result is :";
echo $s;
}
else
{
echo "Wrong !!! file format \n";
}
?>
Test Function:
Please save the following content in three different text files:
1. please make a text file with the following value using note pad, please remove the word wrap option unchecked and remove the "enters" from the end of the files": The expected output will be of positive output.
8793626956188267042825248360082325753042075296345085861560789112949495459501737958331952853208805511657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688196983520312774506326239578318016984801869478851843125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311305886116467109405077541002256983155200055935729725164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760662229893423380308135336276614282806444486645238749731671765313306249192251196744265747423553491949343035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776
2. please make a text file with the following value using note pad, please remove the word wrap option unchecked and remove the "enters" from the end of the files": The expected output will be of negative output for the size of the no of values.
56188267042825248360082325753042075296345085861560789112949495459501737958331952853208805511657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688196983520312774506326239578318016984801869478851843125406987471585238630507156932909632952274430435576689664895044524452316173185640309871112172238311305886116467109405077541002256983155200055935729725164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760662229893423380308135336276614282806444486645238749731671765313306249192251196744265747423553491949343035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888
3. please make a text file with the following value using note pad, please remove the word wrap option unchecked and remove the "enters" from the end of the files": The expected output will be of negative output as there is a character present.
87936269561882670428252483600823257530420752963450858615607891129494954595017379583319528532088055116572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881969835203127745063262395783180169848018694788518431254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113058861164671094p507754100225698315520005593572972516427171479924442928230863465674813919123162824586178664583591a45665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403@509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760662229893423380308135336276614282806444486645238749731671765313306249192251196744265747423553491949343035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776