Kaprekar numbers: Difference between revisions
Content added Content deleted
(Added third version, as suggested.) |
(Cleaned up the description some, but much more is needed.) |
||
Line 1: | Line 1: | ||
{{task}} |
{{task}} |
||
In this task, generate andshow all Kaprekar numbers less than 10,000. For extra credit, count (and report the count of) how many Kaprekar numbers are less than 1,000,000. |
|||
⚫ | |||
⚫ | |||
⚫ | |||
;Example Kaprecar numbers: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
;Example process: |
|||
The task is to generate and show all the Kaprekar numbers less than 10,000 |
|||
⚫ | |||
* The first split is [1, 0000], which is not OK because "a split of all zeroes is not counted; zero is not considered positive". |
|||
* Slight optimization opportunity: When splitting from left to right, once the right part consists of all zeroes, no further testing is needed; all further splits would also be invalid. |
|||
As a stretch goal count and show how many Kaprekar numbers there are that are less than one million. |
|||
;Reference: |
;Reference: |
||
Line 14: | Line 18: | ||
;Note |
;Note |
||
In comparing splits of the square, a split of all zeroes is not counted |
In comparing splits of the square, a split of all zeroes is not counted; zero is not considered positive. |
||
⚫ | |||
The first split is [1, 0000], which is not OK because "a split of all zeroes is not counted - as zero is not considered positive". Slight optimization opportunity: When splitting from left to right, once the right part becomes all zeroes, you don't need to test this number anymore because its splits will always be invalid. |
|||
=={{header|C}}== |
=={{header|C}}== |