Mateja
(Mateja)
May 3, 2020, 7:39am
#1
Hi Koders, today I have another daily challenge for you.
You shall ask for a list of inputs (numbers), and the program should return the number with the greatest sum of digits.
Example inputs and outputs:
magicNumber(525,245,184,114) => 184
magicNumber(111111111111,999) => 999
magicNumber(234,243) => 243
As always,
Have fun!
EDIT: Forgot to mention, if there are multiple numbers with the same sum of digits return the greatest one.
EDIT 2: Ask for inputs like this:
3 Likes
just in case u r waiting, let me say, i am trying, may be not the best but lets see
1 Like
when i input no. like this it shows me error but if i set the numbers in a variable list and call that list as a input, it works
1 Like
Mateja
(Mateja)
May 3, 2020, 12:46pm
#6
Hm, weird, but I will accept that as an answer.
2 Likes
Mateja:
EDIT:
this is the toughest part
1 Like
I am giving my bad solution but it currently do not fulfil your duplicate number requirement, if numbers are duplicate it will give the first number in the list
I am currently working on your second part too, Will resume once electricity is back( )
there is just a small problem in that part
Edit
Oh man! , I am so dumb, i suddenly got an idea of using dictionary, , will be much more simple, just waiting for electricity, great ideas struck suddenly
3 Likes
Hereโs my solution, tested with all three sets of provided inputs:
Solution
Proof of functionality:
7 Likes
Mateja
(Mateja)
May 3, 2020, 5:45pm
#11
Wow! Good job indeed! Could you post your solution under the details tag?
2 Likes
Yoshi
(KidKoder)
May 3, 2020, 5:48pm
#12
Aargh! @Kanishka_Developer was earlier! He won.
Testing of functionality:
Solution
And this are my blocks. I know, not the best way, but a way. Btw, I also did not use the Extension @Deepanshu_Arya used
2 Likes
Mateja
(Mateja)
May 3, 2020, 5:51pm
#13
Oh wow, the variable names:
2 Likes
Yoshi
(KidKoder)
May 3, 2020, 5:53pm
#14
Laziness rules the world
Ok, ok. This is the last one.
2 Likes
I love most of your variables but please avoid using variables with the same name barring the punctuation (in your case item and ITEM).
Also, maybe do this when possible?
2 Likes
Yoshi
(KidKoder)
May 3, 2020, 5:54pm
#16
Kanishka_Developer:
item and ITEM
Yes, this was a part where I saw you posting your solution, and me:
And I had no idea anymore.
2 Likes
Congrats @Kanishka_Developer
I need to practice myself more
@Yoshi , I had a version without extention too. anyways keep it up
3 Likes
system
(system)
Closed
June 3, 2020, 2:46am
#18
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.