human
Can you provide a code to check if any permutation of a large number is divisible by 8 and the other steps required given the following:
Check if any permutation of a large number is divisible by 8 | Function to check if any permutation of a large number is divisible by 8.
Less than three digit number can be checked directly ..
check for the reverse of a number.
Stores the Frequency of characters in the n ..
Iterates for all three digit numbers divisible by 8.
stores the frequency of all single digit in three - digit number.
check if the original number has the digit.
when all are checked its not possible.
Driver Code"
Solution in Python:
assistant
#Here is code to check if any permutation of a large number is divisible by 8 and the other steps required.
 def solve ( n , l ) :
	if l < 3 :
		if int ( n ) % 8 == 0 :
			return True
		n = n [ : : - 1 ]
		if int ( n ) % 8 == 0 :
			return True
		return False
	hash = 10 * [ 0 ]
	for i in range ( 0 , l ) :
		hash [ int ( n [ i ] ) - 0 ] += 1 ;
	for i in range ( 104 , 1000 , 8 ) :
		dup = i
		freq = 10 * [ 0 ]
		freq [ int ( dup % 10 ) ] += 1 ;
		dup = dup / 10
		freq [ int ( dup % 10 ) ] += 1 ;
		dup = dup / 10
		freq [ int ( dup % 10 ) ] += 1 ;
		dup = i
		if ( freq [ int ( dup % 10 ) ] > hash [ int ( dup % 10 ) ] ) :
			continue ;
		dup = dup / 10 ;
		if ( freq [ int ( dup % 10 ) ] > hash [ int ( dup % 10 ) ] ) :
			continue ;
		dup = dup / 10
		if ( freq [ int ( dup % 10 ) ] > hash [ int ( dup % 10 ) ] ) :
			continue ;
		return True
	return False
if __name__ == " _ _ main _ _ " :
	number = "31462708"
	l = len ( number )
	if solve ( number , l ) :
		print ( " Yes " )
	else :
		print ( " No " )