human
Give me a code to count rotations divisible by 8 and the other steps required given the following:
Count rotations divisible by 8 | function to count of all rotations divisible by 8.
For single digit number.
For two - digit numbers ( considering all pairs ).
first pair.
second pair.
considering all three - digit sequences.
Considering the number formed by the last digit and the first two digits.
Considering the number formed by the last two digits and the first digit.
required count of rotations.
Driver Code"
Solution in Python:
assistant
#Here is code to count rotations divisible by 8 and the other steps required.
 def countRotationsDivBy8 ( n ) :
	l = len ( n )
	count = 0
	if ( l == 1 ) :
		oneDigit = int ( n [ 0 ] )
		if ( oneDigit % 8 == 0 ) :
			return 1
		return 0
	if ( l == 2 ) :
		first = int ( n [ 0 ] ) * 10 + int ( n [ 1 ] )
		second = int ( n [ 1 ] ) * 10 + int ( n [ 0 ] )
		if ( first % 8 == 0 ) :
			count += 1
		if ( second % 8 == 0 ) :
			count += 1
		return count
	threeDigit = 0
	for i in range ( 0 , ( l - 2 ) ) :
		threeDigit = ( int ( n [ i ] ) * 100 + int ( n [ i + 1 ] ) * 10 + int ( n [ i + 2 ] ) )
		if ( threeDigit % 8 == 0 ) :
			count += 1
	threeDigit = ( int ( n [ l - 1 ] ) * 100 + int ( n [ 0 ] ) * 10 + int ( n [ 1 ] ) )
	if ( threeDigit % 8 == 0 ) :
		count += 1
	threeDigit = ( int ( n [ l - 2 ] ) * 100 + int ( n [ l - 1 ] ) * 10 + int ( n [ 0 ] ) )
	if ( threeDigit % 8 == 0 ) :
		count += 1
	return count
if __name__ == ' _ _ main _ _ ' :
	n = "43262488612"
	print ( " Rotations : " , countRotationsDivBy8 ( n ) )