Initial import

This commit is contained in:
FuryFire 2012-03-01 11:35:34 +01:00
commit 2c7660786d
8 changed files with 114 additions and 0 deletions

20
ProjectEuler/001/desc.yml Normal file

@ -0,0 +1,20 @@
title: Add all the natural numbers below one thousand that are multiples of 3 or 5.
url: http://projecteuler.net/problem=1
desc: |
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
solution: |
Loop numbers from 1-1000 - Use mod to find the multiples
solutions:
solve.php:
desc: Basic solution
language: php
solve.rb:
desc: Basic solution in Ruby
language: ruby
solve.c:
desc: ANSI C solution (Tested with TCC)
language: c

15
ProjectEuler/001/solve.c Normal file

@ -0,0 +1,15 @@
#include <stdio.h>
int main( )
{
int sum = 0;
int i = 0;
for(i = 1; i < 1000; i++)
{
if(i % 3 == 0 || i % 5 == 0)
{
sum += i;
}
}
printf( "%i", sum );
}

@ -0,0 +1,10 @@
<?php
$sum = 0;
$i = 0;
for($i=1; $i<1000;$i++) {
if($i % 3 == 0 OR $i % 5 == 0) {
$sum += $i;
}
}
echo $sum;

@ -0,0 +1,7 @@
sum = 0
(1..1000).each do |i|
if(i % 3 == 0 or i % 5 == 0)
sum += i
end
end
puts sum

21
ProjectEuler/002/desc.yml Normal file

@ -0,0 +1,21 @@
title: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
url: http://projecteuler.net/problem=2
desc: |
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
solution: |
Step through the fibonacci sequence while you sum each even entry. Quit as you reach 4million
solutions:
solve.php:
desc: Basic solution
language: php
solve.rb:
desc: Basic solution in Ruby
language: ruby
solve.c:
desc: ANSI C solution (Tested with TCC)
language: c

18
ProjectEuler/002/solve.c Normal file

@ -0,0 +1,18 @@
#include <stdio.h>
int main( )
{
int sum = 2;
int fib[3] = { 1, 2, 3 };
while(fib[2] < 4000000)
{
fib[2] = fib[0] + fib[1];
if(fib[2] % 2 == 0)
sum += fib[2];
fib[0] = fib[1];
fib[1] = fib[2];
}
printf( "%i", sum );
}

@ -0,0 +1,12 @@
<?php
$fib = array(1,2,3);
$sum = 2;
while($fib[2] < 4000000) {
$fib[2] = $fib[0] + $fib[1];
if($fib[2] % 2 == 0) {
$sum += $fib[2];
}
$fib[0] = $fib[1];
$fib[1] = $fib[2];
}
echo $sum;

11
ProjectEuler/002/solve.rb Normal file

@ -0,0 +1,11 @@
fib = [1, 2, 3];
sum = 2;
while(fib[2] < 4000000)
fib[2] = fib[0] + fib[1];
if(fib[2] % 2 == 0)
sum += fib[2];
end
fib[0] = fib[1];
fib[1] = fib[2];
end
puts sum;