Various incomplete solutions
This commit is contained in:
13
CodeChef/easy/HS08TEST/solve.php
Normal file
13
CodeChef/easy/HS08TEST/solve.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
while($s=explode(' ',trim(fgets(STDIN)))) {
|
||||
|
||||
if($s[1]%5) {
|
||||
echo $s[1];
|
||||
} else {
|
||||
$new = round($s[1]-$s[1]-0.5,2);
|
||||
if($new)
|
||||
echo $new;
|
||||
else
|
||||
echo $s[1];
|
||||
}
|
||||
}
|
7
CodeChef/easy/TEST/solve.php
Normal file
7
CodeChef/easy/TEST/solve.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
echo fgets(STDIN);
|
||||
while($s = fgets(STDIN)) {
|
||||
if(trim($s) == '42')
|
||||
die;
|
||||
echo $s;
|
||||
}
|
@ -6,7 +6,8 @@ desc: |
|
||||
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?
|
||||
|
||||
solution: Use factoring
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic Solution
|
||||
language: php
|
||||
solve.php:
|
||||
desc: Basic Solution
|
||||
language: php
|
@ -3,10 +3,8 @@ 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
|
||||
@ -20,11 +18,13 @@ desc: |
|
||||
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
|
||||
desc: Basic Solution - needs BCMath
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
20
ProjectEuler/029/desc.yml
Normal file
20
ProjectEuler/029/desc.yml
Normal file
@ -0,0 +1,20 @@
|
||||
title: How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
||||
url: http://projecteuler.net/problem=29
|
||||
|
||||
desc: |
|
||||
Consider all integer combinations of a^b for 2 <= a 5 and 2 <= b <= 5:
|
||||
2^2=4, 2^3=8, 2^4=16, 2^5=32
|
||||
3^2=9, 3^3=27, 3^4=81, 3^5=243
|
||||
4^2=16, 4^3=64, 4^4=256, 4^5=1024
|
||||
5^2=25, 5^3=125, 5^4=625, 5^5=3125
|
||||
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
|
||||
4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125
|
||||
How many distinct terms are in the sequence generated by a^b for 2 <= a <= 100 and 2 <= b <= 100?
|
||||
solution: Bruteforce
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic Solution - needs BCMath
|
||||
language: php
|
||||
solve.rb:
|
||||
desc: Basic solution
|
||||
language: ruby
|
12
ProjectEuler/029/solve.php
Normal file
12
ProjectEuler/029/solve.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
define('A_START',2);
|
||||
define('A_END',100);
|
||||
define('B_START',2);
|
||||
define('B_END',100);
|
||||
|
||||
for($a=A_START;$a<=A_END;$a++) {
|
||||
for($b=B_START;$b<=B_END;$b++) {
|
||||
$array[] = bcpow($a,$b);
|
||||
}
|
||||
}
|
||||
echo count(array_unique($array));
|
21
ProjectEuler/029/solve.rb
Normal file
21
ProjectEuler/029/solve.rb
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
MAX = 6*9**5
|
||||
value = 2;
|
||||
total = 0;
|
||||
for value in (2..MAX) do
|
||||
a = 0
|
||||
|
||||
end
|
||||
while($value<354294) {
|
||||
$a = 0;
|
||||
for($t=0;$t<strlen($value);$t++) {
|
||||
$a += pow(substr((string)$value,$t,1),5);
|
||||
}
|
||||
|
||||
|
||||
if($value == $a) { $total += $value;}
|
||||
|
||||
$value++;
|
||||
}
|
||||
echo $total;
|
||||
|
16
ProjectEuler/030/desc.yml
Normal file
16
ProjectEuler/030/desc.yml
Normal file
@ -0,0 +1,16 @@
|
||||
title: Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
|
||||
url: http://projecteuler.net/problem=30
|
||||
|
||||
desc: |
|
||||
Surprisingly there are only three numbers that can be written as the sum of fourth powers of their digits:
|
||||
1634 = 1^4 + 6^4 + 3^4 + 4^4
|
||||
8208 = 8^4 + 2^4 + 0^4 + 8^4
|
||||
9474 = 9^4 + 4^4 + 7^4 + 4^4
|
||||
As 1 = 1^4 is not a sum it is not included.
|
||||
The sum of these numbers is 1634 + 8208 + 9474 = 19316.
|
||||
Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.
|
||||
solution: We can safely assume that we don't have to search high values higher than 354294. Because 6*9^5 = 354294 is far from the value of 999999
|
||||
solutions:
|
||||
solve.php:
|
||||
desc: Basic Solution
|
||||
language: php
|
16
ProjectEuler/030/solve.php
Normal file
16
ProjectEuler/030/solve.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
define('POWER',5);
|
||||
define('START',2);
|
||||
define('END', 6*pow(9,POWER) );
|
||||
|
||||
$result = 0;
|
||||
for($value = START; $value < END; $value++ ) {
|
||||
$cmp = 0;
|
||||
for($c= 0, $len = strlen($string), $string = (string)$value; $c< $len; $c++)
|
||||
{
|
||||
$cmp += pow($string[$c],POWER);
|
||||
}
|
||||
|
||||
$result += ($value == $cmp) ? $value : 0;
|
||||
}
|
||||
echo $result;
|
10
ProjectEuler/031/desc.yml
Normal file
10
ProjectEuler/031/desc.yml
Normal file
@ -0,0 +1,10 @@
|
||||
title: Investigating combinations of English currency denominations.
|
||||
url: http://projecteuler.net/problem=31
|
||||
|
||||
desc: |
|
||||
In England the currency is made up of pound, £ and pence, p, and there are eight coins in general circulation:
|
||||
1p, 2p, 5p, 10p, 20p, 50p, ñ (100p) and £ (200p).
|
||||
It is possible to make £ in the following way:
|
||||
1£ + 150p + 220p + 15p + 12p + 31p
|
||||
How many different ways can £ be made using any number of coins?
|
||||
solution: Define the target value as 200 to simplify
|
4
ProjectEuler/031/solve.php
Normal file
4
ProjectEuler/031/solve.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
$start = 200;
|
||||
|
||||
for($c = 0; $c > $left; $c++);
|
10
ProjectEuler/032/desc.yml
Normal file
10
ProjectEuler/032/desc.yml
Normal file
@ -0,0 +1,10 @@
|
||||
title: Find the sum of all numbers that can be written as pandigital products.
|
||||
url: http://projecteuler.net/problem=32
|
||||
|
||||
desc: |
|
||||
We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.
|
||||
The product 7254 is unusual, as the identity, 39 x 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.
|
||||
Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.
|
||||
HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.
|
||||
solution: Bruteforce
|
||||
|
6
ProjectEuler/032/solve.php
Normal file
6
ProjectEuler/032/solve.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
function pandigital($number) {
|
||||
$array = count_chars($number,1);
|
||||
ksort($array);
|
||||
if($array == array(49=>1,50=>1,51=>1,52=>1,53=>1,54=>1,55=>1,56=>1,57=>1)) { return true;} else { return false; }
|
||||
}
|
13
ProjectEuler/034/desc.yml
Normal file
13
ProjectEuler/034/desc.yml
Normal file
@ -0,0 +1,13 @@
|
||||
title: Find the sum of all numbers which are equal to the sum of the factorial of their digits.
|
||||
url: http://projecteuler.net/problem=34
|
||||
|
||||
desc: |
|
||||
145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.
|
||||
Find the sum of all numbers which are equal to the sum of the factorial of their digits.
|
||||
Note: as 1! = 1 and 2! = 2 are not sums they are not included.
|
||||
solution: Bruteforce
|
||||
solutons:
|
||||
solve.php:
|
||||
desc: Basic solution
|
||||
language: php
|
||||
|
16
ProjectEuler/034/solve.php
Normal file
16
ProjectEuler/034/solve.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
$num = 3;
|
||||
$result =0;
|
||||
for($num = 3; $num < 99999; $num++) {
|
||||
$sum = 0;
|
||||
foreach(str_split($num) as $digit) {
|
||||
$sum += fact($digit);
|
||||
}
|
||||
if($sum == $num) { $result += $sum;}
|
||||
}
|
||||
echo $result;
|
||||
|
||||
function fact($int){
|
||||
static $facts = array(1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880);
|
||||
return $facts[$int];
|
||||
}
|
Reference in New Issue
Block a user