Self numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: mirrored bugfix)
m (→‎{{header|AppleScript}}: Edited comments to show limit of accuracy. Changed the indexDiff calculation to reflect what it means (but same results). Added another demo.)
Line 25: Line 25:
This connection with significant digit change means every ten blocks form a higher-order block, every ten
This connection with significant digit change means every ten blocks form a higher-order block, every ten
of these a higher-order-still block, and so on.
of these a higher-order-still block, and so on.
The code below appears to be good up to the last self number before 10^12 — ie. 999,999,999,997, which is
returned as the 97,777,777,792nd such number. After this, instead of zero-length shorter runs, the actual
pattern apparently starts again with a single run of 10, like the one at the beginning.
*)
*)
on selfNumbers(indexRange)
on selfNumbers(indexRange)
Line 48: Line 52:
on fastForward()
on fastForward()
if (counter ≥ startIndex) then return
if (counter ≥ startIndex) then return
-- The highest-order blocks whose ends this script is thought to handle correctly contain 9,777,777,778 self numbers.
-- The highest-order blocks whose ends this script handles correctly contain 9,777,777,778 self numbers.
-- The difference between equivalently positioned numbers in these blocks is 100,000,000,001.
-- The difference between equivalently positioned numbers in these blocks is 100,000,000,001.
-- The figures for successively lower-order blocks are obtained by successively removing 7s and 0s!
-- The figures for successively lower-order blocks have successively fewer 7s and 0s!
set indexDiff to 9.777777778E+9
set indexDiff to 9.777777778E+9
set numericDiff to 1.00000000001E+11
set numericDiff to 1.00000000001E+11
Line 59: Line 63:
set currentSelf to (currentSelf + numericDiff)
set currentSelf to (currentSelf + numericDiff)
else
else
set indexDiff to indexDiff div 10 + 1
set indexDiff to (indexDiff + 2) div 10
set numericDiff to numericDiff div 10 + 1
set numericDiff to numericDiff div 10 + 1
end if
end if
Line 114: Line 118:
-- One hundred millionth:
-- One hundred millionth:
selfNumbers(100000000)
selfNumbers(100000000)
--> {1.022727208E+9}</lang>
--> {1.022727208E+9}

-- 97,777,777,792nd:
selfNumbers(9.7777777792E+10)
--> {9.99999999997E+11}</lang>


=={{header|C}}==
=={{header|C}}==