human
Number of substrings divisible by 6 in a string of integers | Return the number of substring divisible by 6 and starting at index i in s [ ] and previous sum of digits modulo 3 is m ..
End of the string ..
If already calculated , return the stored value ..
Converting into integer ..
Increment result by 1 , if current digit is divisible by 2 and sum of digits is divisible by 3. And recur for next index with new modulo ..
Returns substrings divisible by 6..
For storing the value of all states ..
If string contain 0 , increment count by 1..
Else calculate using recursive function . Pass previous sum modulo 3 as 0..
Driver Code"
Solution in Python:
 Write me a code to number of substrings divisible by 6 in a string of integers and the other steps required?
assistant
#Here is code to number of substrings divisible by 6 in a string of integers and the other steps required.
 def f ( i , m , s , memoize ) :
	if ( i == len ( s ) ) :
		return 0
	if ( memoize [ i ] [ m ] != - 1 ) :
		return memoize [ i ] [ m ]
	x = ord ( s [ i ] ) - ord ( '0' )
	ans = ( ( ( x + m ) % 3 == 0 and x % 2 == 0 ) + f ( i + 1 , ( m + x ) % 3 , s , memoize ) )
	memoize [ i ] [ m ] = ans
	return memoize [ i ] [ m ]
def countDivBy6 ( s ) :
	n = len ( s )
	memoize = [ [ - 1 ] * 3 for i in range ( n + 1 ) ]
	ans = 0
	for i in range ( len ( s ) ) :
		if ( s [ i ] == '0' ) :
			ans += 1
		else :
			ans += f ( i , 0 , s , memoize )
	return ans
if __name__ == ' _ _ main _ _ ' :
	s = "4806"
	print ( countDivBy6 ( s ) )