Last active
September 3, 2020 15:26
-
-
Save Victoria-Hodder/5bdb1b2bde1218295dcd1ae9120ca028 to your computer and use it in GitHub Desktop.
ex2_Jose
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
""" | |
Write a function solution that, given integer N, returns the smallest non-negative | |
integer whose individual digits sum to N. | |
Examples: | |
1. Given N = 16, the function should return 79. There are many numbers whose | |
digits sum to 16 (for example: 79, 97, 808, 5551, 22822, etc.). | |
The smallest such number is 79. | |
2. Given N = 19, the function should return 199 (the sum of digits is 1 + 9 + 9 = 19). | |
3. Given N = 7, the function should return 7. | |
Assume that: N is an integer within the range [0..50]. | |
""" | |
def smallest_int(n): | |
list_to_string = list(str(n)) #converts n into a string, then splits the string into a list of strings | |
mapping = map(int,lst_converstion) # converts the list of strings back into integers | |
summing = sum(mapping) # adds the integers together | |
return summing | |
""" | |
This function is printing the sum of n by splitting the digits, then converting them to a list of ints, then summing them | |
I need to approach this the other way to find the minimum digit which, summed, would result in n | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I will meet with Meili tomorrow for German-Python exchange, perhaps we will get a chance to talk it through.