Restructuring
This commit is contained in:
16
solutions/ProjectEuler/104/desc.yml
Normal file
16
solutions/ProjectEuler/104/desc.yml
Normal file
@ -0,0 +1,16 @@
|
||||
title: Finding Fibonacci numbers for which the first and last nine digits are pandigital.
|
||||
url: http://projecteuler.net/problem=104
|
||||
|
||||
desc: |
|
||||
The Fibonacci sequence is defined by the recurrence relation:
|
||||
Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1.
|
||||
It turns out that F541, which contains 113 digits, is the first Fibonacci number for which the last nine digits are 1-9 pandigital (contain all the digits 1 to 9, but not necessarily in order). And F2749, which contains 575 digits, is the first Fibonacci number for which the first nine digits are 1-9 pandigital.
|
||||
Given that Fk is the first Fibonacci number for which the first nine digits AND the last nine digits are 1-9 pandigital, find k.
|
||||
|
||||
solution: |
|
||||
Bruteforce
|
||||
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Bruteforce - Sooooo slow
|
||||
language: php
|
20
solutions/ProjectEuler/104/solve.php
Normal file
20
solutions/ProjectEuler/104/solve.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
function pandigital($num) {
|
||||
for ($i = 1; $i <= 9; $i++) {
|
||||
if(strpos($n,(string)$i) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
$var = 1;
|
||||
$k = 1;
|
||||
while(true) {
|
||||
$k++;
|
||||
$new = bcadd($var,$prev);
|
||||
$prev = $var;
|
||||
$var = $new;
|
||||
|
||||
if(pandigital(substr($var,-9)) AND pandigital(substr($var,0,9))) { echo $k; die; }
|
||||
}
|
Reference in New Issue
Block a user