Created
January 2, 2024 14:08
-
-
Save izumigoto/adbddbd5b9b32d2193aa6e6f16f94243 to your computer and use it in GitHub Desktop.
A code to find the largest number by only changing a digit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = [69, 699, 69, 96666, 699] | |
def find_largest_number(numbers): | |
max_number = float('-inf') | |
for num in numbers: | |
num_str = str(num) | |
for i in range(len(num_str)): | |
temp_num = int(num_str[:i] + '9' + num_str[i+1:]) | |
max_number = max(max_number, temp_num) | |
return max_number | |
largest_number = find_largest_number(numbers) | |
print("Largest Number:", largest_number) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment