Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 1
    Is ignoring n really that trivial? Moving the a(0) case to a(1) worries me. As does writing a line like for(i in 3:n) {if(even(i)){a(i+1)=a(i/2+1) else a(i+1)=a(1+(i-1)/2)+a(1+(i+1)/2)} Commented Dec 4, 2020 at 21:19
  • I think you're fundamentally right but specifically wrong. "Just move the relevant bits one index up" is trivial, but figuring out what parts are relevant is not. A key part in solving our example is making the observation that the 0-indexed even branch is an odd branch in 1-indexing. Another pitfall is that we must notice that the left-hand side of our equations, a(i)=[whatever], must not change, whereas we must "change all a([some function of i]) to a([some function of i+1])" on the right. Overall, the path to if(even(i)){a(i)=a(i/2)+a((i+2)/2)} else a(i)=a((i+1)/2 seems non-trivial. Commented Dec 5, 2020 at 13:59
  • 3
    @J.Mini the relevant bits are precisely the argument to a() and absolutely nothing else. Commented Dec 5, 2020 at 17:41
  • @J.Mini: Just think about the myCorrectIndex value. Setting its value is easy (the old index + or - 1 depending on which way you're correcting). The usage of myCorrectIndex in the actual calculation remains unchanged between the two ways of handling indices. I think you're getting yourself turned around by trying to do it all in one go and failing to keep track of which part of the formula belongs to the original formula and which part is an index-correcting calculation. Commented Dec 11, 2020 at 0:20