human
Largest number with prime digits | check if character is prime.
replace with previous prime character.
if 2 erase s [ i ] and replace next with 7.
find first non prime char.
find first char greater than 2.
like 20.
like 7721.
replace remaining with 7.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to largest number with prime digits and the other steps required.
 def isPrime ( c ) :
	return ( c == '2' or c == '3' or c == '5' or c == '7' )
def decrease ( s , i ) :
	if ( s [ i ] <= '2' ) :
		s . pop ( i )
		s [ i ] = '7'
	elif ( s [ i ] == '3' ) :
		s [ i ] = '2'
	elif ( s [ i ] <= '5' ) :
		s [ i ] = '3'
	elif ( s [ i ] <= '7' ) :
		s [ i ] = '5'
	else :
		s [ i ] = '7'
def primeDigits ( s ) :
	s = [ i for i in s ]
	i = 0
	while i < len ( s ) :
		if ( isPrime ( s [ i ] ) == False ) :
			while ( s [ i ] <= '2' and i >= 0 ) :
				i -= 1
			if ( i < 0 ) :
				i = 0
				decrease ( s , i )
			else :
				decrease ( s , i )
			for j in range ( i + 1 , len ( s ) ) :
				s [ j ] = '7'
			break
		i += 1
	return " " . join ( s )
s = "45"
print ( primeDigits ( s ) )
s = "1000"
print ( primeDigits ( s ) )
s = "7721"
print ( primeDigits ( s ) )
s = "7221"
print ( primeDigits ( s ) )
s = "74545678912345689748593275897894708927680"
print ( primeDigits ( s ) )