Ben her zaman "Yeterince iyi şu işleri", bir süre ile bağlı olan bir programlama meydan okuma çözümü sonra kendi kendime düşünüyorum.
Benim görüşüme göre, bu gerçekten doğru zihniyet olduğunu düşünmüyorum ve ben her zaman büyük performansı ile kod çalışıyor gerektiğini düşünüyorum.
Bu dedi ile Neyse, ben sadece bir ProjectEuler soru çalıştı. Özellikle 2. soru.
Bunu nasıl çözüm geliştirilmiş olabilir. Ben onun really ayrıntılı gibi hissediyorum. Sanki özyinelemede önceki sayıyı geçiyorum.
<?php
/* Each new term in the Fibonacci sequence is generated by adding the previous two
terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not exceed
four million.
*/
function fibonacci ( $number, $previous = 1 ) {
global $answer;
$fibonacci = $number + $previous;
if($fibonacci > 4000000) return;
if($fibonacci % 2 == 0) {
$answer = is_numeric($answer) ? $answer + $fibonacci : $fibonacci;
}
return fibonacci($fibonacci, $number);
}
fibonacci(1);
echo $answer;
?>
Note this isn't homework. I left school hundreds of years ago. I am just feeling bored and going through the Project Euler questions