"Fibonacci Sequence V"
Given the first few Fibonacci numbers:
How many odd digits (1, 3, 5, 7 or 9) are contained in the 1000th Fibonacci number?
Note: solve problem 25 first.
as the challenge suggests, modify chall 25 code to solve this, should be fairly trivial.
Awnser:
= 101
Source:
function solution(){
$prevno = 1; // no 1
$currno = 1; // no 2
for( $i = 3; $i <= 1000; $i++ ){
$placeholder = bcadd($prevno, $currno);
$prevno = $currno;
$currno = $placeholder;
}
$result = str_replace(array('0','2','4','6','8'), '' , $currno); //remove even no's
echo "= ".strlen($result).""; // length of string = number of odds
}