+ 29
[ ASSIGNMENT: ] Form The Minimum [ UPDATE: ] Form The minValue Without Leading Zero!
TASK : Given a list of digits, return the smallest number that could be formed from these digits, using the digits only once (ignore duplicates). NOTE : Only positive integers will be passed to the method (> 0 ), no negatives, Without duplications! Input, Output Examples :: 1. minValue({5, 7, 5, 9, 7}) --> return (579) (579) is the minimum number could be formed! 2. minValue({4, 1, 3, 1, 0, 0, 1}) --> return (1034) (1034) is the minimum number could be formed! HappyCodings!:-) Thanks to LukArToDo
15 Respostas
+ 32
My try 👇 [Ruby 1 Liner]
https://code.sololearn.com/cGvB5KqjRw20/?ref=app
+ 18
Bravo!! LukArToDo 😀👏👏😄
My Friend,
I think, now the task is Ok! 👌😉
Thank you very much for your Update and huge support which I have from You! 👍😊
+ 16
Danijel Ivanović
You're welcome my friend.
Thank you for the nice challenge 😉
+ 10
My version; space separated digits required as input. As a extra bonus, tossed in the maximum too.
https://code.sololearn.com/ckirPIbUbjhO
+ 8
This is a well commented version on Python:
https://code.sololearn.com/c8Yc4X3nm2aI/?ref=app
And this is a Python oneliner based on it:
https://code.sololearn.com/czR1aU1HqS73/?ref=app
UPD:
One more Python oneliner (2 lines in fact) based on @cyk solution. Complexity is much higher, but visually it is more pretty:
https://code.sololearn.com/cF580t646eMw/?ref=app
+ 6
This one is pretty tricky but I was waiting for it so I made it in Ruby but it will by harder for me in other languages but I'll still give it a try 😉
Added the maximum number as a bonus😉👍
Updated.
https://code.sololearn.com/cM59PwSL43uy/?ref=app
https://code.sololearn.com/WV8dvoexIv9F/?ref=app
+ 6
@Louis
1. sorted() already returns a list, so there is no need for further conversion.
2. No need to convert result to int before printing out. print() will convert it back to string.
So the shortest Python oneliner could be just:
print(''.join(sorted(set(list(input())))))
But it will not work properly with the second example in challenge description. See this code where this issue is solved:
https://code.sololearn.com/czR1aU1HqS73/?ref=app
BTW, if you have better ideas to make it shorter, you are welcome :-)
+ 5
#Python
# When asked - enter the number - as in:57597 output will be 579
print(int(''.join(list(sorted(set(list(input())))))))
+ 3
Danijel Ivanović updated my code to filter out any possible leading 0
0
hiii
0
ti
- 2
coc gems 10000000000