Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
June 17, 2020 01:27 pm GMT

Daily Challenge 260 - Subtract the Sum

Complete the function which get an input number n such that n >= 10 and n < 10000, then:

Sum all the digits of n.
Subtract the sum from n, and it is your new n.
If the new n is in the list below return the associated fruit, otherwise return back to task 1.

Example
n = 325
sum = 3+2+5 = 10
n = 325-10 = 315 (not in the list)
sum = 3+1+5 = 9
n = 315-9 = 306 (not in the list)
sum = 3+0+6 = 9
n =306-9 = 297 (not in the list)
...
. ...until you find the first n in the list below.

Here are all possible values of n:

1-kiwi2-pear3-kiwi4-banana5-melon6-banana7-melon8-pineapple9-apple10-pineapple11-cucumber12-pineapple13-cucumber14-orange15-grape16-orange17-grape18-apple19-grape20-cherry21-pear22-cherry23-pear24-kiwi25-banana26-kiwi27-apple28-melon29-banana30-melon31-pineapple32-melon33-pineapple34-cucumber35-orange36-apple37-orange38-grape39-orange40-grape41-cherry42-pear43-cherry44-pear45-apple46-pear47-kiwi48-banana49-kiwi50-banana51-melon52-pineapple53-melon54-apple55-cucumber56-pineapple57-cucumber58-orange59-cucumber60-orange61-grape62-cherry63-apple64-cherry65-pear66-cherry67-pear68-kiwi69-pear70-kiwi71-banana72-apple73-banana74-melon75-pineapple76-melon77-pineapple78-cucumber79-pineapple80-cucumber81-apple82-grape83-orange84-grape85-cherry86-grape87-cherry88-pear89-cherry90-apple91-kiwi92-banana93-kiwi94-banana95-melon96-banana97-melon98-pineapple99-apple100-pineapple

Tests:
SubtractSum(10)
SubtractSum(1204)

Good luck!

This challenge comes from aryan-firouzian on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email [email protected] with your suggestions!


Original Link: https://dev.to/thepracticaldev/daily-challenge-260-subtract-the-sum-31gd

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To