oups
This commit is contained in:
parent
f2e07f9a03
commit
9a22d0c7e3
35
euler25.php
35
euler25.php
|
@ -1,25 +1,20 @@
|
||||||
<?php
|
<?php
|
||||||
/*
|
/*
|
||||||
* Gnieark's anwser to euler problem 26
|
* Gnieark's anwser to euler problem 25
|
||||||
* https://projecteuler.net/problem=26
|
* https://projecteuler.net/problem=25
|
||||||
*/
|
*/
|
||||||
$beastDenominateur=0;
|
//see https://fr.wikipedia.org/wiki/Suite_de_Fibonacci#Avec_la_formule_de_Binet
|
||||||
$longestCycle=0;
|
echo intval((log(10)*999 + (log(5)/2) ) / log(1.61803398875)) +1;
|
||||||
for ($denominateur=2; $denominateur < 1000; $denominateur ++){
|
/*
|
||||||
|
Very long solution that didn't test :
|
||||||
$reste=1;
|
$i=1;
|
||||||
$restes=array();
|
$j=2;
|
||||||
$count=0;
|
$count=2;
|
||||||
while (!in_array($reste,$restes)){
|
while(strlen($i)<1000){
|
||||||
$restes[]=$reste;
|
$new=gmp_add($i,$j);
|
||||||
$reste=$reste*10;
|
$i=$j;
|
||||||
$reste=fmod($reste,$denominateur);
|
$j=$new;
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
if($count > $longestCycle){
|
echo $count;
|
||||||
$longestCycle=$count;
|
*/
|
||||||
$beastDenominateur=$denominateur;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $beastDenominateur."\n";
|
|
25
euler26.php
Normal file
25
euler26.php
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Gnieark's anwser to euler problem 26
|
||||||
|
* https://projecteuler.net/problem=26
|
||||||
|
*/
|
||||||
|
$beastDenominateur=0;
|
||||||
|
$longestCycle=0;
|
||||||
|
for ($denominateur=2; $denominateur < 1000; $denominateur ++){
|
||||||
|
|
||||||
|
$reste=1;
|
||||||
|
$restes=array();
|
||||||
|
$count=0;
|
||||||
|
while (!in_array($reste,$restes)){
|
||||||
|
$restes[]=$reste;
|
||||||
|
$reste=$reste*10;
|
||||||
|
$reste=fmod($reste,$denominateur);
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
if($count > $longestCycle){
|
||||||
|
$longestCycle=$count;
|
||||||
|
$beastDenominateur=$denominateur;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $beastDenominateur."\n";
|
Loading…
Reference in New Issue
Block a user