We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #2: Even Fibonacci numbers
  4. Discussions

Project Euler #2: Even Fibonacci numbers

Problem
Submissions
Leaderboard
Discussions

Sort 535 Discussions, By:

recency

Please Login in order to post a comment

  • miryalaraghu369
    1 day ago+ 0 comments

    python solution passed all testcases

    fib = [] fib.append(1) fib.append(2) for i in range(2,n): val = fib[i-1]+fib[i-2] if val>n: break fib.append(val) print(sum(x for x in fib if x%2==0))

    0|
    Permalink
  • malabade_chetan
    4 days ago+ 0 comments
    static long fibb(long n){
            if(n<=1)
                return 0;
            long sum=2;
            long n1=1;
            long n2=2;
            long n3=0;
            
            while(n3<n){
                n3=n1+n2;
                if(n3>n) break;
                if(n3%2==0) sum+=n3;
                n1=n2;
                n2=n3;
            }
            return sum;        
        }
    
    0|
    Permalink
  • Ramesh_vankdoth
    5 days ago+ 1 comment

    This is my solution in python but it failed test case 3, it happens for a bigger a number of input because of time out.

    if name == 'main': t = int(input().strip()) for t_itr in range(t): n = int(input().strip()) fib1 = 0 fib2 = 1 count = 0 inp = 10000 num = set() num2 = set() while count < inp: if fib1 < n and fib1 % 2 == 0: num.add(fib1) fib3 = fib2+fib1 fib1, fib2 = fib2, fib3 count += 1 print(sum(num))

    0|
    Permalink
  • runckcod
    6 days ago+ 0 comments

    this. Say you do:

    The browser is smart enough not to load that CSS file at all (unless you’re printing, natch).

    You can also do this:

    Butttttt, the browser will actually load both of those files regardless if the media matches or not. So no obvious immediate benefit, but that’s where Vadim’s research comes in. While all the files with non-matching media (queries) still load, the browser is smart enough to make the non-matching stylesheets load with a lower priority. At least in Chrome and Firefox — Safari has some bug that makes the priority levels not provide the perf benefits.

    Pretty cool I think. Doing this kind of work by hand feels onerous though, I’d love to see build processes deal with it automatically.

    Ya know I was scared for Mozilla & Firefox for a while. Those big layoffs in 2020 included many browser engine engineers and it seemed like it would be hard to continue to be a viable browser engine alternative without a strong team there. But I was essentially wrong. Since then they’ve shipped plenty of important web platform features at a decent pace, including the ever-important Container Queries and new color formats. Putting MDN on GitHub happened after the layoffs too and that seems like a massive thing to get shipped.

    Last year WIRED asked Is Firefox OK? There wasn’t really an answer there, but some good information. We know Google provides the bulk of their income, but they showed really strong growth with their own products and services, saying 14% of all revenue was that back in 2021. They’ve clearly been trying new stuff to increase that, so things look on the right track to me.

    I like to see little stories like this: Mozilla fixed an 18-year old CSS bug in the Firefox browser. So they aren’t just playing catch up, they are getting details right along the way too. Better late than never. This one was a weird bug with ::first-letter, the real ticket for doing drop caps:

    examples of the first-letter CSS property in very old versions of the Firefox browser. They said it was kind of a bandaid for now but still cool. Speaking of drop caps though… ::first-letter was always fraught for this purpose. Much better would be to support initial-letter. C’mon Firefox, you can do it!

    0|
    Permalink
  • mega180698
    2 weeks ago+ 0 comments

    Golang Solution

    func fibonacci(n uint64) uint64 {
        var a, b, sum uint64 = 1, 2, 2
        for a + b < n {
            next := a + b
            if next % 2 == 0 {
                sum += next
            }
            a = b
            b = next
        }
        
        return sum
    }
    
    0|
    Permalink
Load more conversations

Need Help?


View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy