Data update
This commit is contained in:
parent
796d366b97
commit
35bcdeebf8
504 changed files with 7045 additions and 610 deletions
20
Task/Rare-numbers/EasyLang/rare-numbers.easy
Normal file
20
Task/Rare-numbers/EasyLang/rare-numbers.easy
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
fastfunc next n .
|
||||
while 1 = 1
|
||||
n += 1
|
||||
h = n
|
||||
nrev = 0
|
||||
while h > 0
|
||||
nrev = nrev * 10 + h mod 10
|
||||
h = h div 10
|
||||
.
|
||||
if sqrt (n + nrev) mod 1 = 0
|
||||
if n - nrev >= 1 and sqrt (n - nrev) mod 1 = 0
|
||||
return n
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
for cnt to 5
|
||||
n = next n
|
||||
print n
|
||||
.
|
||||
46
Task/Rare-numbers/Lua/rare-numbers.lua
Normal file
46
Task/Rare-numbers/Lua/rare-numbers.lua
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
do -- find the first five rare numbers
|
||||
|
||||
local function revn ( na )
|
||||
local n, r = na, 0
|
||||
while n > 0 do
|
||||
r = r * 10 r = r + ( n % 10 )
|
||||
n = math.floor( n / 10 )
|
||||
end
|
||||
return r
|
||||
end -- revn
|
||||
|
||||
local nd, count, lim, n = 2, 0, 90, 20
|
||||
local oddNd = nd % 2 == 1
|
||||
while true do
|
||||
n = n + 1
|
||||
local r = revn( n )
|
||||
if r < n then
|
||||
local s, d = n + r, n - r
|
||||
local tryThis = false
|
||||
if oddNd
|
||||
then tryThis = d % 1089 == 0
|
||||
else tryThis = s % 121 == 0
|
||||
end
|
||||
if tryThis then
|
||||
local rootS = math.sqrt( s )
|
||||
if rootS == math.floor(rootS )
|
||||
then
|
||||
local rootD = math.sqrt( d )
|
||||
if rootD == math.floor( rootD )
|
||||
then
|
||||
count = count + 1
|
||||
io.write( count, ": ", n, "\n" )
|
||||
if count >= 5 then os.exit() end
|
||||
end
|
||||
end
|
||||
end
|
||||
if n == lim
|
||||
then
|
||||
lim = lim * 10
|
||||
nd = nd + 1
|
||||
oddNd = not oddNd
|
||||
n = math.floor( lim / 9 ) * 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue