Nieuw lid |
|
Hee,
Ik heb dit script gemaakt voor Project Euler Problem 22.
Maar het antwoord is fout. Ziet iemand de fout?
<?php
$bestand = 'names.txt';
$fopen = fopen($bestand, 'r');
$fread = fread($fopen, filesize($bestand));
$substr = substr($fread, 1, count($fread)-2);
$explode = explode('","', $substr);
sort($explode);
$array = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26);
for($a=0; $a<count($explode); $a++)
{
for($b=0; $b<strlen($explode{$a}); $b++)
$c+= $array[$explode{$a}{$b}];
$d = $c*($a+1);
$e+= $d;
}
print $e;
fclose($fopen);
?>
<?php $bestand = 'names.txt'; $fopen = fopen($bestand, 'r'); $explode = explode('","', $substr); $array = array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 4, 'E' => 5, 'F' => 6, 'G' => 7, 'H' => 8, 'I' => 9, 'J' => 10, 'K' => 11, 'L' => 12, 'M' => 13, 'N' => 14, 'O' => 15, 'P' => 16, 'Q' => 17, 'R' => 18, 'S' => 19, 'T' => 20, 'U' => 21, 'V' => 22, 'W' => 23, 'X' => 24, 'Y' => 25, 'Z' => 26); for($a=0; $a<count($explode); $a++) { for($b=0; $b<strlen($explode{$a}); $b++) $c+= $array[$explode{$a}{$b}]; $d = $c*($a+1); $e+= $d; } ?>
-edit-
Trouwens als iemand iets wil verbeteren mag dat ook altijd
|