Restructuring

This commit is contained in:
2024-07-01 13:49:44 +00:00
parent f11b705ef0
commit 8d60e1b905
194 changed files with 1296 additions and 112 deletions

View File

@ -0,0 +1,27 @@
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
solve.js:
desc: NodeJS solution
language: javascript
solve.lua:
desc: Basic solution
language: lua

View 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 );
}

View File

@ -0,0 +1,11 @@
sum = 2;
fib = new Array( 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];
}
console.log(sum );

View File

@ -0,0 +1,11 @@
sum = 2
fib = {1, 2, 3}
while fib[2] < 4000000 do
fib[3] = fib[1] + fib[2]
if(fib[3] % 2 == 0) then
sum = sum + fib[3]
end
fib[1] = fib[2]
fib[2] = fib[3]
end
print (sum )

View File

@ -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;

View 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;