diff --git a/ProjectEuler/024/desc.yml b/ProjectEuler/024/desc.yml index 1205c24..652521a 100644 --- a/ProjectEuler/024/desc.yml +++ b/ProjectEuler/024/desc.yml @@ -5,7 +5,8 @@ desc: | A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are: 012 021 102 120 201 210 What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9? -todo: Improve algorithm - -solution: Bruteforce -solutions: \ No newline at end of file +solutions: + solve.php: + desc: Basic Solution + language: php \ No newline at end of file diff --git a/ProjectEuler/024/solve.php b/ProjectEuler/024/solve.php index 848a63d..9060fae 100644 --- a/ProjectEuler/024/solve.php +++ b/ProjectEuler/024/solve.php @@ -1,25 +1,26 @@ 1); +for ($i = 2; $i <= 9; $i++) { + $permus[$i] = $permus[$i - 1] * $i; } -echo "DONE!"; -print_r($result); -echo " - ".$cstep ."\n"; -echo "Result: 2783915460"; +$permus = array_reverse($permus); +$values = array(); + +foreach ($permus as $n) { + $values[] = floor($target / $n); + $target = $target%$n; +} + +$result = ""; +foreach ($values as $val) { + $result .= $digits[$val]; + unset($digits[$val]); + sort($digits); +} +$result .= $digits[0]; +echo $result; diff --git a/ProjectEuler/025/desc.yml b/ProjectEuler/025/desc.yml new file mode 100644 index 0000000..11d41d9 --- /dev/null +++ b/ProjectEuler/025/desc.yml @@ -0,0 +1,30 @@ +title: What is the first term in the Fibonacci sequence to contain 1000 digits? +url: http://projecteuler.net/problem=25 + +desc: | + The Fibonacci sequence is defined by the recurrence relation: + + Fn = Fn1 + Fn2, where F1 = 1 and F2 = 1. + Hence the first 12 terms will be: + + F1 = 1 + F2 = 1 + F3 = 2 + F4 = 3 + F5 = 5 + F6 = 8 + F7 = 13 + F8 = 21 + F9 = 34 + F10 = 55 + F11 = 89 + F12 = 144 + The 12th term, F12, is the first term to contain three digits. + + What is the first term in the Fibonacci sequence to contain 1000 digits? +solution: Bruteforce + +solutions: + solve.php: + desc: Basic Solution + language: php \ No newline at end of file diff --git a/ProjectEuler/025/solve.php b/ProjectEuler/025/solve.php new file mode 100644 index 0000000..6719dc0 --- /dev/null +++ b/ProjectEuler/025/solve.php @@ -0,0 +1,13 @@ +