about | help | code help+videos | done | prefs |
Take any four digit number (with at least 2 digits different), and do the following: Rearrange the string of digits to form the largest and smallest 4-digit numbers possible. Take these two numbers and subtract the smaller number from the larger. Use the number you obtain and repeat the above process. Suppose we choose the number 3141. 4311-1134=3177. 7731-1377=6354. 6543-3456=3087. 8730-0378=8352. 8532-2358=6174. 7641-1467=6174... The process eventually hits 6174 and then stays there! Return a list of the numbers ending in the cycle 6174 for a 4 digit number n. kaprekarsConstant(3141) → [3141, 3177, 6354, 3087, 8352, 6174] kaprekarsConstant(1234) → [1234, 3087, 8352, 6174] kaprekarsConstant(3524) → [3524, 3087, 8352, 6174] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Difficulty: 200 Post-solution available
Copyright Nick Parlante 2017 - privacy