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.
A positive integer is a [[wp:Kaprekar number|Kaprekar number]] if it is 1, or if the string representation of its square can be split once into parts consisting of positive integers that when summed add up to the original number.


A positive integer is a [[wp:Kaprekar number|Kaprekar number]] if it is 1, or if the string representation of its square may be split once into parts consisting of positive integers that sum to the original number.
For example 2223 is a Kaprekar number as 2223*2223 == 4941729 and 494 + 1729 == 2223


;Example Kaprecar numbers:
The series of Kaprekar numbers begins: [[oeis:A006886|1, 9, 45, 55, ...]].
* 2223 is a Kaprekar number, as 2223*2223 = 4941729, 4941729 may be split to 494 and 1729, and 494 + 1729 = 2223
* The series of Kaprekar numbers begins: [[oeis:A006886|1, 9, 45, 55, ...]].


;Example process:
The task is to generate and show all the Kaprekar numbers less than 10,000
10000 (100<sup>2</sup>) splitting from left to right:
* 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 - as zero is not considered positive.
In comparing splits of the square, a split of all zeroes is not counted; zero is not considered positive.


Example: 10000 (100<sup>2</sup>) splitting from left to right:
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}}==