human
Can you provide a code to count of N digit Numbers whose sum of every K consecutive digits is equal and the other steps required given the following:
Count of N digit Numbers whose sum of every K consecutive digits is equal | Function to count the number of N - digit numbers such that sum of every k consecutive digits are equal.
Range of numbers.
Extract digits of the number.
Store the sum of first K digits.
Check for every k - consecutive digits.
If sum is not equal then break the loop.
Increment the count if it satisfy the given condition.
Given N and K.
Function call"
How can the above be solved in Python?
assistant
#Here is code to count of N digit Numbers whose sum of every K consecutive digits is equal and the other steps required.
 def countDigitSum ( N , K ) :
	l = pow ( 10 , N - 1 )
	r = pow ( 10 , N ) - 1
	count = 0
	for i in range ( l , r + 1 ) :
		num = i
		digits = [ 0 ] * N
		for j in range ( N - 1 , - 1 , - 1 ) :
			digits [ j ] = num % 10
			num //= 10
		sum = 0
		flag = 0
		for j in range ( 0 , K ) :
			sum += digits [ j ]
		for j in range ( 1 , N - K + 1 ) :
			curr_sum = 0
			for m in range ( j , j + K ) :
				curr_sum += digits [ m ]
			if ( sum != curr_sum ) :
				flag = 1
				break
		if ( flag == 0 ) :
			count += 1
	return count
N = 2
K = 1
print ( countDigitSum ( N , K ) )