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

  • SEARCH
  • Home
  • 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 4022734
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:30:45+00:00 2026-05-20T10:30:45+00:00

I am having a hard time following this function. I do not understand how

  • 0

I am having a hard time following this function. I do not understand how the variable start reverts back to 16 after it reaches a value of 26 which is greater than 24.

function findSequence(goal) {
  function find(start, history) {
    if (start == goal)
      return history;
    else if (start > goal)
      return null;
    else
      return find(start + 5, "(" + history + " + 5)") ||
             find(start * 3, "(" + history + " * 3)");
  }
  return find(1, "1");
}

print(findSequence(24));

OK, after looking at this for sometime, I have a few questions that might clarify a few things:

1) Is it a correct statement to say that each call to find keeps track of it’s own start value? For example, when find(1) is called, it’s has a start value of 1, when find(1 + 5) is called, find(1)’s start value is still one, but find(1 + 5) now has it’s own start value of 6.

2) I am having a hard time following the stacktrace even if I see it printed out. This is how I am viewing it:

find(1) calls find(1 + 5) //start = 1

find(6) calls find(6 + 5) // start = 6, Passes

find(11) calls find(11 + 5) // start = 11, Passes

find(16) calls find(16 + 5) // start = 16, Passes

find(21) calls find(21 + 5) // start = 21, Fails

Because find(21 + 5) returns null, it tries to call find(21 * 3) which also returns null.

This is the part I get stuck at, if both find(21 + 5) and find(21 * 3) return null, how does it know to call find(16 * 3) next. Why does it not do find(16 + 5) again?

Does it have something to do where find(21 + 5) and find(21 * 3) were called by find(16) and because those returned null into the calling function, it executed the second portion of the || statement which was find(16 * 3).

  • 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-05-20T10:30:46+00:00Added an answer on May 20, 2026 at 10:30 am

    It’s a different variable. start whenever a particular find(x) is called, its value of start doesn’t affect any other instance of start.

    when find(21) is called, it returns null, because find(26) and find(63) return null
    likewise,
    find(16) and find(11) return null

    when find(6) is called, it calls find(11), which returns null, so it calls find(24) next.
    in the context of this call, start == 6, so it continues with start + 5 and start * 3.

    find(6):
    start = 6, history = (1 + 5)
         find(6 + 5):
         start = 11, history = ((1 + 5) + 5)
             find(11 + 5):
             start = 16, history = (((1 + 5) + 5) + 5)
             ... continued etc...
    
             find(11 * 3):
             start = 33, history = (((1 + 5) + 5) * 3)
             <end>
         find(6 * 3):
         start = 24, history = ((1 + 5) * 3)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having hard time understanding the following C# code. This code was taken from
I've been having a hard time trying to understand PyPy's translation. It looks like
I'm still having a hard time not wanting to use Tables to do my
I'm having a hard time understanding what the difference is between incrementing a variable
I'm having a hard time figuring this one out. Seems like no matter what
I was given this code earlier but am having a hard time parsing the
I'm having a hard time understanding the following statements from Algorithms by S. Dasgupta,
I've been reading about Haskell and I'm having a hard time understanding how function
I'm new in JS, and having quite hard time reading the following JS code.
I'm having a hard time with the submit handler... Why does the following still

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.