Kaprekar numbers: Difference between revisions

Content deleted Content added
Toucan (talk | contribs)
m whitespace
Line 18:
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}}==
Line 301 ⟶ 300:
=={{header|Icon}} and {{header|Unicon}}==
 
<lang Icon>procedure is_kaprekar (n)
procedure is_kaprekar (n)
if n = 1 then {suspend n; return}
 
Line 322 ⟶ 320:
if is_kaprekar (i) then count +:= 1
write ("Number of Kaprekar numbers less than 1000000 is ", count)
end</lang>
</lang>
 
Output:
Line 468 ⟶ 465:
 
# one million is a small number, let's brute force it
is_kaprekar($_) and print "$_\n" for 1 .. 1_000_000;</lang>
</lang>
Output:<pre>1
9