Skip to content

Instantly share code, notes, and snippets.

@Victoria-Hodder
Last active September 3, 2020 15:26
Show Gist options
  • Save Victoria-Hodder/5bdb1b2bde1218295dcd1ae9120ca028 to your computer and use it in GitHub Desktop.
Save Victoria-Hodder/5bdb1b2bde1218295dcd1ae9120ca028 to your computer and use it in GitHub Desktop.
ex2_Jose
"""
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
"""
@kpanic
Copy link

kpanic commented Sep 2, 2020

mmm, I am thinking that the code is close enough. but not covering the requirement of the exercise.
Please have a thought about it given the snippet that I provided.
I might have some time to think about it this evening, pardon Victoria

@Victoria-Hodder
Copy link
Author

Thank you, I'll have a run with it now :)

@Victoria-Hodder
Copy link
Author

I will meet with Meili tomorrow for German-Python exchange, perhaps we will get a chance to talk it through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment