Project Euler/2

From Esolang
Jump to navigation Jump to search

Back to User:ProjectEuler

Project Euler Problem 2 is a problem that works with Fibonacci numbers. The task is to work out the sum of all even Fibonacci numbers below four million.

This article is not detailed enough and needs to be expanded. Please help us by adding some more information.

Implementations

Aheui

This program may need reduction.

바싹바발발나빠뱐주뱔뗘땨뼈뺘뗘뺘변따뗘
삭망희ㅇ루벅포뼈차
싹샥뼈댜챠사빠쑥
ㅇㅇㅇㅇ쌰석쇼뎌

C

#include <stdio.h>
int h=0, j=1, j_=0;
int main(){
while(j<4000000){
j_+=j;
j+=j_;
j_=j-j_;
j-=j_;
if(j==(j/2)*2){
h+=j;
}
}
printf("%d",h);
return 0;
}

Rockstar

Please note that there are two blank lines before the last line

Henry is gone.
Jack is harkworking.
Jill is gone.
While Jack is lower than 4000000
Let Jill be with Jack.
Let Jack be with Jill.
Let Jill be Jack without Jill.
Let Jack be without Jill.
Let Papa be Jack over 2.
Turn it down.
Let Papa be of 2.
If Papa is Jack
Let Henry be with Jack.


Say Henry.

Shakespeare

exeunt at the beginning of a scene sounds absurd, but that's what usually happens in a program with three or more variables. [citation needed] The program can't run without them.

Jack and Jill's affairs.

Hamlet, who adds everything up.
Juliet, who delivers the big things.
Julia, who memorizes the smaller things.

Act I: a.
Scene I: Constant definition.
[ enter Hamlet and Juliet ]
Hamlet: You are a cat.
[ exeunt ]

Scene II: Start loop.
[ exeunt ]
[ enter Julia and Juliet ]
Julia: Are you better than the square of twice the cube of the sum of a big big big cat and a big cat? If so, let us proceed to Scene III.
Juliet: You are the sum of you and me.
Julia:  You are the sum of you and me.
Juliet: You are the difference between me and you.
Julia:  You are the difference between you and me.

[ exit Julia ]
[ enter Hamlet ]

Hamlet: Are you as good as the product of the quotient between you and a big cat and a big cat?
Juliet: If so, you are the sum of you and me.
Let us return to Scene II.

[ exeunt ]

Scene III: End of affairs.
[ exeunt ]
[ enter Hamlet and Juliet ]
Juliet: Open your heart.
[ exeunt ]

Wenyan

有數零。 名之曰「和」。
有數一。 名之曰「大」。
有數零。 名之曰「小」。

恆為是。若「大」大於四百萬者乃止也。
 加「大」以「小」。昔之「小」者。今其是矣。
 加「大」以「小」。昔之「大」者。今其是矣。
 減「大」以「小」。昔之「小」者。今其是矣。
 減「大」以「小」。昔之「大」者。今其是矣。
 
 除「大」以二。所餘幾何。若其等於零者。
 加「大」以「和」。昔之「和」者。今其是矣。
 云云。
云云。

吾有一數。曰「和」。書之。

Python

# Project Euler problem 2
# by Europe2048

def fibonacci(n):
    if n < 2:
        return 1
    else:
        return fibonacci(n-1) + fibonacci(n-2)

result = []
for i in range(1, 35):
    if fibonacci(i) % 2 == 0 and fibonacci(i) < 4000000:
        result.append(fibonacci(i))
print(sum(result))


See also

<< < 1 ... 2 3 4 5 6 ... 28 > >>

External resources

  • Fibonacci on Wolfram Mathworld
  • Problem 2 on Project Euler Official Website (not available)
  • Problem 2 on Project Euler Mirror