Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ challenge V̅MCLXXIV: Dr. Kaprekar

Name: Anonymous 2018-08-31 12:52

Write the function KaprekarsConstant(num). num parameter being passed will be a 4-digit number with at least two distinct digits. Your program should perform the following routine on the number: Arrange the digits in descending order and, separately, in ascending order (adding leading zeroes to fit it to a 4-digit number), and subtract the smaller of the two resulting numbers from the bigger number. Repeat. Performing this routine will always cause you to reach a fixed number: 6174. Then performing the routine on 6174 will always give you 6174 (7641 - 1467 = 6174). Your program should return the number of times this routine must be performed until 6174 is reached.

。゜*:。:。☆゚・.+♩*:****。: *.。.゚   ・・❀o❀・゚。✧゚・ : 。*  ;:.* ゜+.。○。 ♩;゚゚ 。


For example: if num is 3524 your program should return 3 because of the following steps:
(1) 5432 - 2345 = 3087,
(2) 8730 - 0378 = 8352,
(3) 8532 - 2358 = 6174.

Shortest byte count wins. Good luck!

Name: Anonymous 2018-09-12 7:55

>>15
python doesn't have the pre/post-incrementation syntax:

Python 3.5.2 (default, Nov 23 2017, 16:37:01)
Type "copyright", "credits" or "license" for more information.

IPython 2.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: i=0;i++
File "<ipython-input-1-cac78eb7531c>", line 1
i=0;i++
^
SyntaxError: invalid syntax

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List