Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results for euler 2 tagged with
Search options not deleted

Use this tag when the code is a solution to a programming challenge. Always include a sufficient description of the problem to be solved - while a link to the challenge is welcome, the review request needs to be complete when the challenge site is unavailable.

11 votes
5 answers
2k views

Project Euler #2 in Java

Project Euler #2: 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, ... … 000; public static void main(String[] args) { long time = System.nanoTime(); double max = MAX_NUM * SQRT_5; long sum = 0; for (int i = 3, result = (int) Math.round(2
TheCoffeeCup's user avatar
  • 9,446
9 votes
4 answers
938 views

Project Euler #2 in Python

Here is my Python code for Project Euler #2: 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, ... …
bbali's user avatar
  • 303
4 votes
0 answers
119 views

Project Euler #2 in Go

I just learned Go (yesterday in fact) and today I made this solution to Project Euler #2. The problem is to sum the even Fibonacci numbers. … matrix calculation is raising a matrix to the power of 4, which I did using this Go matrix library which I believe uses BLAS under the hood. /* p2.go * by hacatu * * This program solves Project Euler
hacatu's user avatar
  • 462
5 votes
2 answers
204 views

Project Euler Attack #2

This is my implementation of Project Euler #2 in C#. It takes 0 milliseconds to run, and I believe it is correct - I have seen nothing to indicate otherwise! … static void GetFibos(ref List<int> nums, int maxVal) { nums.Add(1); int lastNum = 2; while (lastNum <= maxVal) { nums.Add(lastNum); lastNum = nums[nums.Count - 2] + nums …
user avatar
4 votes
3 answers
217 views

Project Euler #2 in F#

Project Euler Problem 2 asks for the sum of all even Fibonacci numbers below 4 million. My first attempt at this problem using functional programming with F#. … open System let rec fib n = match n with | 0 | 1 | 2 -> n | _ -> fib (n - 1) + fib (n - 2) let rec nOfFibTermsUpUntil x y = if fib (y + 1) < x then nOfFibTermsUpUntil …
Overly Excessive's user avatar
4 votes
3 answers
811 views

Project Euler 2 - Fibonacci sequence

I lately spend a lot of time at Project Euler programming challenges. … By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... …
user avatar
3 votes
1 answer
234 views

Generators in Javascript; Project Euler #2

I'm trying to learn javascript using project euler and I decided to try to force myself to learn about generators in javascript using problem number 2 which asks us to: Find the sum of the even-valued … terms in the fibonacci (f(n)) sequence such that f(n) < 4M , beginning with n=1 is 1, n=2 is 2, n=3 is 3 and so on My code below presently works but I'm hoping to get some input as I began learning javascript …
mburke05's user avatar
  • 641
3 votes
3 answers
682 views

Project Euler problem 2

This is a question about Project Euler number 2, a relatively easy one. The question is: 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, ... …
kafka's user avatar
  • 426
21 votes
4 answers
3k views

Project Euler #2 (Even Fibonacci numbers) in Swift

I figured working through Project Euler problems in Swift would be a good way to learn any tips or tricks. For example, tuples are something I'm not used to using, but they proved useful here. … By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... …
nhgrif's user avatar
  • 25.3k
6 votes
2 answers
218 views

Project Euler #2 with a fibSequence and result

I was hoping you could give me a feedback on the solution I have come up with for the second challenge of Project Euler, and maybe explain me why many of the other solutions I have come across were wrapped … By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... …
user avatar
7 votes
2 answers
2k views

Project Euler #2 Efficiency

By starting with 1 and 2, the first 10 terms will be: 1,2,3,5,8,13,21,34,55,89,... … fib2 = new BigInteger("1"); BigInteger sum = new BigInteger("0"); BigInteger fib = new BigInteger("0"); while (input.compareTo(fib)>0) { if (fib.doubleValue() % 2
Arun Prakash's user avatar
  • 1,483
2 votes
3 answers
859 views

Maintaining the Single Responsibility Principle with Project Euler #2

This is my solution to Project Euler problem 2: By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms. … (self,limit_value): sequence = 2 sum = 0 while True: result = self.F(sequence) if result > limit_value …
Sarawut Positwinyu's user avatar
1 vote
1 answer
304 views

Euler Project Problem 2 JavaScript

Just solved Euler Project Problem 2 using JavaScript and I would like to know how I could improve my code. I do think it looks good, but you never know. … By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... …
fabinfabinfabin's user avatar
9 votes
3 answers
2k views

Project Euler #2 (Fibonacci Sequence)

By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89. …
Legato's user avatar
  • 9,839
2 votes
1 answer
222 views

Project Euler #2: sum of even Fibonacci numbers, using generators

I am currently working on Project Euler problem #2 which requires you to print the sum of all even fibonacci numbers below 4 million. … second_last_n = last_n last_n = current_n yield current_n def filter_even(nums): # yields all numbers in nums (a generator) which are even for n in nums: if (n % 2
Dominik Schmidt's user avatar

1
2 3 4 5
22
15 30 50 per page