Recursive solution to finding patterns

Posted by user2997162 on Stack Overflow See other posts from Stack Overflow or by user2997162
Published on 2014-06-13T03:02:02Z Indexed on 2014/06/13 3:25 UTC
Read the original article Hit count: 93

Filed under:
|
|

I was solving a problem on recursion which is to count the total number of consecutive 8's in a number. For example:

input: 8801 output: 2
input: 801 output: 0
input: 888 output: 3
input: 88088018 output:4

I am unable to figure out the logic of passing the information to the next recursive call about whether the previous digit was an 8.

I do not want the code but I need help with the logic. For an iterative solution, I could have used a flag variable, but in recursion how do I do the work which flag variable does in an iterative solution. Also, it is not a part of any assignment. This just came to my mind because I am trying to practice coding using recursion.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about recursion