37 lines
2.1 KiB
Text
37 lines
2.1 KiB
Text
A positive integer is a [[wp:Kaprekar number|Kaprekar number]] if:
|
|
* It is 1
|
|
* The decimal representation of its square may be split once into two parts consisting of positive integers which sum to the original number.
|
|
<br>Note that a split resulting in a part consisting purely of 0s is not valid,
|
|
as 0 is not considered positive.
|
|
|
|
;Example Kaprekar numbers:
|
|
* <math>2223</math> is a Kaprekar number, as <math>2223 * 2223 = 4941729</math>, <math>4941729</math> may be split to <math>494</math> and <math>1729</math>, and <math>494 + 1729 = 2223</math>.
|
|
* The series of Kaprekar numbers is known as [[oeis:A006886|A006886]], and begins as <math>1, 9, 45, 55, ...</math>.
|
|
|
|
;Example process:
|
|
10000 (100<sup>2</sup>) splitting from left to right:
|
|
* The first split is [1, 0000], and is invalid; the 0000 element consists entirely of 0s, and 0 is not considered positive.
|
|
* Slight optimization opportunity: When splitting from left to right, once the right part consists entirely of 0s, no further testing is needed; all further splits would also be invalid.
|
|
|
|
;Task description:
|
|
Generate and show all Kaprekar numbers less than 10,000.
|
|
|
|
;Extra credit:
|
|
Optionally, count (and report the count of) how many Kaprekar numbers are less than 1,000,000.
|
|
|
|
;Extra extra credit:
|
|
The concept of Kaprekar numbers is not limited to base 10 (i.e. decimal numbers);
|
|
if you can, show that Kaprekar numbers exist in other bases too.
|
|
|
|
For this purpose, do the following:
|
|
* Find all Kaprekar numbers for base 17 between 1 and 1,000,000 (one million);
|
|
* Display each of them in base 10 representation;
|
|
* Optionally, using base 17 representation (use letters 'a' to 'g' for digits 10(10) to 16(10)), display each of the numbers, its square, and where to split the square.
|
|
|
|
<br>For example, 225(10) is "d4" in base 17, its square "a52g", and a5(17) + 2g(17) = d4(17), so the display would be something like:<pre>225 d4 a52g a5 + 2g</pre>
|
|
|
|
;Reference:
|
|
* [http://www.cs.uwaterloo.ca/journals/JIS/VOL3/iann2a.html The Kaprekar Numbers] by Douglas E. Iannucci (2000). [http://pictor.math.uqam.ca/~plouffe/OEIS/jis/The%20Kaprekar%20Numbers.pdf PDF version]
|
|
;related task
|
|
[[Casting out nines]]
|
|
<br>
|