8 kyu

Never visit a . . . !?

1,172 of 20,237aryan-firouzian

Description:

Subtract the sum

NOTE! This kata can be more difficult than regular 8-kyu katas (lets say 7 or 6 kyu)

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

  1. Sum all the digits of n.
  2. Subtract the sum from n, and it is your new n.
  3. 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.

There is no preloaded code to help you. This is not about coding skills; think before you code

1-kiwi
2-pear
3-kiwi
4-banana
5-melon
6-banana
7-melon
8-pineapple
9-apple
10-pineapple
11-cucumber
12-pineapple
13-cucumber
14-orange
15-grape
16-orange
17-grape
18-apple
19-grape
20-cherry
21-pear
22-cherry
23-pear
24-kiwi
25-banana
26-kiwi
27-apple
28-melon
29-banana
30-melon
31-pineapple
32-melon
33-pineapple
34-cucumber
35-orange
36-apple
37-orange
38-grape
39-orange
40-grape
41-cherry
42-pear
43-cherry
44-pear
45-apple
46-pear
47-kiwi
48-banana
49-kiwi
50-banana
51-melon
52-pineapple
53-melon
54-apple
55-cucumber
56-pineapple
57-cucumber
58-orange
59-cucumber
60-orange
61-grape
62-cherry
63-apple
64-cherry
65-pear
66-cherry
67-pear
68-kiwi
69-pear
70-kiwi
71-banana
72-apple
73-banana
74-melon
75-pineapple
76-melon
77-pineapple
78-cucumber
79-pineapple
80-cucumber
81-apple
82-grape
83-orange
84-grape
85-cherry
86-grape
87-cherry
88-pear
89-cherry
90-apple
91-kiwi
92-banana
93-kiwi
94-banana
95-melon
96-banana
97-melon
98-pineapple
99-apple
100-pineapple
Puzzles
Strings
Number Theory
Mathematics

Stats:

CreatedFeb 18, 2016
PublishedFeb 18, 2016
Warriors Trained51731
Total Skips1675
Total Code Submissions90957
Total Times Completed20237
C# Completions1172
Python Completions5815
JavaScript Completions6252
Java Completions2331
C++ Completions1384
Ruby Completions473
Groovy Completions66
Haskell Completions191
NASM Completions28
Lua Completions121
Kotlin Completions403
Julia Completions56
Go Completions514
Fortran Completions37
Factor Completions21
Erlang Completions60
Elixir Completions67
Dart Completions300
Crystal Completions37
CoffeeScript Completions41
Clojure Completions98
CFML Completions34
C Completions366
TypeScript Completions295
Swift Completions588
SQL Completions745
Shell Completions174
Scala Completions169
Rust Completions307
PureScript Completions30
Reason Completions26
Racket Completions38
R Completions103
Prolog Completions31
PHP Completions518
Objective-C Completions36
Nim Completions37
F# Completions65
Elm Completions34
COBOL Completions17
BF Completions24
D Completions21
Total Stars749
% of votes with a positive feedback rating61% of 3337
Total "Very Satisfied" Votes1755
Total "Somewhat Satisfied" Votes537
Total "Not Satisfied" Votes1045
Ad
Contributors
  • aryan-firouzian Avatar
  • jhoffner Avatar
  • smile67 Avatar
  • romerojp Avatar
  • Chrono79 Avatar
  • imjasonmiller Avatar
  • elisha464 Avatar
  • Voile Avatar
  • hobovsky Avatar
  • cliffstamp Avatar
  • user8436785 Avatar
  • ejini战神 Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad