Group Abstract Group Abstract

Message Boards Message Boards

Impression of the Kaprekar´s routine with 5, 6, 7 and 8 digit numbers

POSTED BY: Claudio Chaib
3 Replies

enter image description here - Congratulations! This post is now featured in our Staff Pick column as distinguished by a badge on your profile of a Featured Contributor! Thank you, keep it coming, and consider contributing your work to the The Notebook Archive!

POSTED BY: EDITORIAL BOARD
Posted 6 years ago

Hi Claudio,

Nice analysis. Maybe you can use FixedPointList to simplify the computations a little. e.g.

k[b_][n_] := 
 FromDigits@ReverseSort[IntegerDigits[n, b]] - FromDigits@Sort@IntegerDigits[n, b]

FixedPointList[k[10], 3177]
(* {3177, 6354, 3087, 8352, 6174, 6174} *)
POSTED BY: Rohit Namjoshi

Hi Rohit,

Thanks for the feedback, the way you suggested it is a little simpler and more optimized for the beginning of the code that I created (at least smaller) than using two Do[] commands, I believe that the final code could be a few lines less that way and also works with numbers with more than 4 digits, because I can also choose how many steps the list stops with this command, useful when the FixedPointList[] does not find a fixed point (the case of cycles). I may still need to make some modifications and adaptations to the code ... I will test some of the lines with this method that you suggested to compare the evaluation time with the method I used.

Thank you very much for the comment, I am always open to suggestions!

POSTED BY: Claudio Chaib
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard