Self numbers: Difference between revisions
Content added Content deleted
(→sliding sieve: + tidy generator) |
m (→{{header|AppleScript}}: Simpler block interval calculation. Revamped comments.) |
||
Line 19: | Line 19: | ||
<lang applescript>(* |
<lang applescript>(* |
||
Base-10 self numbers by index (single or range). |
Base-10 self numbers by index (single or range). |
||
After the initial single-digit numbers, the sequence follows an observed pattern whereby self numbers |
After the initial single-digit numbers, the sequence follows an observed pattern whereby self numbers |
||
occur in groups whose consecutive members are 11 apart. The interval between these groups is 2. |
|||
They occur in blocks of ten: eight ten-number groups sandwiched between two shorter groups. |
|||
The intervals between blocks and the lengths of the shorter groups |
The intervals between blocks and the lengths of the shorter groups depend the most signficant |
||
digit to have changed in the number sequence since they were last set. |
|||
*) |
*) |
||
on selfNumbers(indexRange) |
on selfNumbers(indexRange) |
||
Line 50: | Line 50: | ||
-- Main loop. |
-- Main loop. |
||
set sentinel to thisSelf |
|||
set shortGroupLength to 10 |
set shortGroupLength to 10 |
||
repeat -- Per block. |
repeat -- Per block. |
||
-- First short group. |
-- First short group. Its length in the first block is 10, thereafter the same as that of the second |
||
-- |
-- short group of the preceding block. The numeric interval preceding it is related to this length. |
||
set thisSelf to thisSelf + 2 + (10 - shortGroupLength) * 13 |
|||
-- ticked over since the first (sentinel) number of the preding block. |
|||
set interval to 2 |
|||
set temp1 to sentinel div 1000 |
|||
set temp2 to thisSelf div 1000 |
|||
repeat until (temp1 = temp2) |
|||
set interval to interval + 13 |
|||
set temp1 to temp1 div 10 |
|||
set temp2 to temp2 div 10 |
|||
⚫ | |||
set thisSelf to thisSelf + interval |
|||
set sentinel to thisSelf |
|||
if (storer's doneAfter(thisSelf)) then return storer's output |
if (storer's doneAfter(thisSelf)) then return storer's output |
||
-- |
-- Consecutive numbers within groups are 11 apart. |
||
repeat (shortGroupLength - 1) times |
repeat (shortGroupLength - 1) times |
||
set thisSelf to thisSelf + 11 |
set thisSelf to thisSelf + 11 |
||
if (storer's doneAfter(thisSelf)) then return storer's output |
if (storer's doneAfter(thisSelf)) then return storer's output |
||
end repeat |
end repeat |
||
⚫ | |||
-- Eight ten-number groups, each preceded by an interval of 2. |
-- Eight ten-number groups, each preceded by an interval of 2. |
||
repeat 8 times |
repeat 8 times |
||
Line 82: | Line 71: | ||
end repeat |
end repeat |
||
end repeat |
end repeat |
||
-- Its length depends on the most significant digit to tick over |
-- Second short group. Its length depends on the most significant digit to tick over |
||
-- The interval |
-- at the thousands boundary within it. The interval preceding it is 2. |
||
set thisSelf to thisSelf + 2 |
set thisSelf to thisSelf + 2 |
||
if (storer's doneAfter(thisSelf)) then return storer's output |
if (storer's doneAfter(thisSelf)) then return storer's output |