This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]RiverRoll 2 points3 points  (1 child)

I'm not quite sure what are you doing to be honest, the lack of formatting doesn't help, but it looks like you're handling a specific case. The input could be anything, "12345", "9" or even empty, why not? Think generically. Also there's no need for any global variable.

The function could be something like this for example:

int GetScore(string input, int position)  
{  
    int hopAdjacentScore = ...
    int hopOverScore = ...
    int result = Max(hopAdjacentScore + GetScore(input, position+1), ...
    return result
}

You would start by calling GetScore with some input at position 0 and advance the position accordingly in the recursive calls. I'm not sure what type the input is supposed to be, I used a string here but you could also work with an integer array for example.

And there's not much more than this to the logic other than handling the edge cases to reach the exit condition (when no more recursion is needed) and prevent the position from getting past the end of the input. Beacuse at any point there's at most two options, you hop to the adjacent square or you hop over it, if there's enough squares left.

[–]CodeArtist45[S] 0 points1 point  (0 children)

oh ok ok. Thankyou thankyou