Subtractive generator: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(RPL: add section) |
||
Line 1,845: | Line 1,845: | ||
563900213 |
563900213 |
||
</pre> |
</pre> |
||
=={{header|RPL}}== |
|||
Here, most data manipulation is performed directly in the stack. This requires less code, but slows down execution: when handling large amounts of data in RPL, it is better to store them in array variables and perform operations directly on them. |
|||
{{works with|Halcyon Calc|4.2.7}} |
|||
{| class="wikitable" |
|||
! RPL code |
|||
! Comment |
|||
|- |
|||
| |
|||
≪ 1 |
|||
2 54 '''START''' DUP2 - 1E9 MOD '''NEXT''' |
|||
55 →ARRY ''''SEEDS'''' STO |
|||
0 54 '''FOR''' j |
|||
''''SEEDS'''' j 1 + 34 * 55 MOD GET 1 + GET '''NEXT''' |
|||
55 →ARRY ''''SEEDS'''' STO |
|||
≫ ''''INITX'''' STO |
|||
≪ |
|||
'''SEEDS''' ARRY→ DROP |
|||
55 ROLL 25 PICK - 1E9 MOD |
|||
55 →ARRY ''''SEEDS'''' STO |
|||
≫ ''''XPAT2'''' STO |
|||
| |
|||
'''INITX''' ''( seed -- )'' |
|||
calculate in stack s(n)=mod(s(n-2)-s(n-1),10^9) for 2≤n≤54 |
|||
Store s(0)..s(54) as an array in SEEDS variable |
|||
for j=0 to 54 |
|||
r(j) = s(mod(34*(j+1),55)) & keep it in stack |
|||
Store r(0)..r(54) as an array in SEEDS variable |
|||
'''XPAT2''' ''( -- )'' |
|||
Put SEEDS in stack |
|||
r(n+1) = mod(r(n-55)-r(n-24),10^9) |
|||
Transfer stack to SEEDS |
|||
|} |
|||
{{in}} |
|||
<pre> |
|||
≪ 292929 INITX |
|||
55 222 START XPAT2 NEXT |
|||
220 222 FOR j SEEDS j GET NEXT |
|||
≫ EVAL |
|||
</pre> |
|||
{{out}} |
|||
<pre> |
|||
3: 467478574 |
|||
2: 512932792 |
|||
1: 539453717 |
|||
</pre> |
|||
Runs in 97 seconds on a basic HP-28S |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Line 1,888: | Line 1,939: | ||
<pre>[467478574, 512932792, 539453717]</pre> |
<pre>[467478574, 512932792, 539453717]</pre> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||