human
Check if binary string multiple of 3 using DFA | Function to check if the binary String is divisible by 3..
checking if the bit is nonzero.
checking if the nonzero bit is at even position.
Checking if the difference of non - zero oddbits and evenbits is divisible by 3..
Driver Program"
How can the above be solved in Python?
 ... Write me a code to check if binary string multiple of 3 using DFA and the other steps required?
assistant
#Here is code to check if binary string multiple of 3 using DFA and the other steps required.
 def CheckDivisibilty ( A ) :
	oddbits = 0 ;
	evenbits = 0 ;
	for counter in range ( len ( A ) ) :
		if ( A [ counter ] == '1' ) :
			if ( counter % 2 == 0 ) :
				evenbits += 1 ;
			else :
				oddbits += 1 ;
	if ( abs ( oddbits - evenbits ) % 3 == 0 ) :
		print ( " Yes " + " " ) ;
	else :
		print ( " No " + " " ) ;
if __name__ == ' _ _ main _ _ ' :
	A = "10101" ;
	CheckDivisibilty ( A ) ;