Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Kaprekar-numbers/Maple/kaprekar-numbers.maple
Normal file
26
Task/Kaprekar-numbers/Maple/kaprekar-numbers.maple
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
isKaprekar := proc(n::posint)
|
||||
local holder, square, num_of_digits, k, left, right;
|
||||
holder := true;
|
||||
if n = 1 then
|
||||
holder := true;
|
||||
else
|
||||
holder := false;
|
||||
square := n^2;
|
||||
num_of_digits := length(n^2);
|
||||
for k to num_of_digits do left := floor(square/10^k);
|
||||
right := irem(square, 10^k);
|
||||
if left + right = n and right <> 0 then
|
||||
holder := true;
|
||||
break;
|
||||
end if;
|
||||
end do;
|
||||
end if;
|
||||
return holder;
|
||||
end proc;
|
||||
|
||||
showKaprekar := n -> select(isKaprekar, select(x -> irem(x, 9) = 1 or irem(x, 9) = 0, [seq(1 .. n - 1)]));
|
||||
|
||||
countKaprekar := n -> nops(showKaprekar(n));
|
||||
|
||||
showKaprekar(10000);
|
||||
countKaprekar(1000000);
|
||||
Loading…
Add table
Add a link
Reference in a new issue