Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:43:24+00:00 2026-06-06T02:43:24+00:00

I am trying to solve the project euler 2nd question. Why is the below

  • 0

I am trying to solve the project euler 2nd question. Why is the below code resulting into stack overflow ? I am using recur so it should not be storing all the recursive calls on the stack.

(defn sum
  [[a b]]
  [b (+ a b)])

(defn fib-r
  ([n] (fib-r n 0 [0 1]))
  ([n s [a b]]
     (if (= n 0)
       s
       (let [[c d] (sum [a b])
             e (if (even? c) c 0)
             f (+ s e)]
         (recur (dec n) f [c d])))))

(fib-r 4000000)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:43:26+00:00Added an answer on June 6, 2026 at 2:43 am

    your getting an integer overflow (rather than a stack overflow)
    If you use BigInts (BigInt literals end with N) then Clojure will
    happily compute the correct result:

    (defn fib-r                                                                                          
      ([n] (fib-r n 0N [0N 1N]))                                                                     
      ([n s [a b]]                                                                                     
         (if (= n 0N)                                                                            
           s                                                                            
           (let [[c d] (sum [a b])                                               
                 e (if (even? c) c 0N)                               
                 f (+ s e)]                             
             (recur (dec n) f [c d])))))
    #'autotestbed.core/fib-r                                                                                               
    autotestbed.core> (fib-r 40000)
    1158997879999727672946417013062336891791160667328280503727448.... big number
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In trying to solve a particular Project Euler question, I ran into difficulties with
I'm trying to solve Problem #5 in Project Euler. The code works for the
I was trying to solve Project Euler problem 10 using python, but my program
I am trying to solve Q10 from Project Euler. I am using JavaScript and
For a little context, i'm trying to solve Project Euler problem 31 using excellent
I was trying to solve this Project Euler Question . I implemented the sieve
I am trying to solve this Project Euler question : A perfect number is
Im trying to solve Euler's Project 9 using PHP. Im pretty sure my logic
I am trying to solve a question in Project Euler, which is creating a
I am trying to solve Project Euler problem in Clojure using recursion. The following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.