Duffinian numbers: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Now uses Fmt.tprint and new Int.divisorSum method - 3 times faster than before.) |
(add RPL) |
||
Line 1,024: | Line 1,024: | ||
(6399, 6400, 6401) |
(6399, 6400, 6401) |
||
(8449, 8450, 8451) |
(8449, 8450, 8451) |
||
</pre> |
|||
=={{header|RPL}}== |
|||
<code>∑DIV</code>, which returns the sum of the divisors of a given number, is defined at [[Sum_of_divisors#RPL]]. |
|||
<code>GCD</code>, which returns the GCD of 2 given numbers, is defined at [[Greatest_common_divisor#RPL]]. |
|||
{{trans|Python}} |
|||
{{works with|Halcyon Calc|4.2.8}} |
|||
{| class="wikitable" |
|||
! RPL code |
|||
! Comment |
|||
|- |
|||
| |
|||
≪ |
|||
DUP '''∑DIV''' |
|||
'''IF''' DUP2 1 - == '''THEN''' DROP2 0 '''ELSE''' GCD 1 == '''END''' |
|||
≫ ‘'''DUFF?'''’ STO |
|||
≪ { } 2 |
|||
'''WHILE''' OVER SIZE 50 < '''REPEAT''' |
|||
'''IF''' DUP '''DUFF? THEN''' SWAP OVER + SWAP '''END''' |
|||
1 + |
|||
'''END''' DROP |
|||
≫ ‘'''TASK1'''’ STO |
|||
≪ { } 4 → duff n |
|||
≪ 0 0 0 |
|||
'''WHILE''' duff SIZE 15 ≤ '''REPEAT''' |
|||
ROT DROP n '''DUFF?''' |
|||
'''IF''' 3 DUPN + + 3 == '''THEN''' |
|||
n 2 - n 1 - n 3 →ARRY |
|||
duff SWAP + 'duff' STO '''END''' |
|||
n 1 + 'n' STO '''END''' |
|||
3 DROPN duff |
|||
≫ ≫ ‘'''TASK2’''' STO |
|||
| |
|||
'''DUFF?( n -- boolean ) |
|||
get σ |
|||
if composite then check gcd(n,σ) |
|||
‘'''TASK1'''’ ''( -- { duff1..duff50 } ) '' |
|||
loop from n=2 until 50 items in list |
|||
if n is Duffinian then append to list |
|||
n += 1 |
|||
clean stack |
|||
‘'''TASK2'''’ ''( -- { [duff_triplets] } ) '' |
|||
put 3 'false' boolean values in stack |
|||
loop from n=4 until 15 items in list |
|||
update stack with n Duffinian status |
|||
if first 3 stack levels are all 1 |
|||
create triplet |
|||
append it to list |
|||
n += 1 |
|||
clean stack, display list |
|||
|} |
|||
{{out}} |
|||
<pre> |
|||
2: { 4 8 9 16 21 25 27 32 35 36 39 49 50 55 57 63 64 65 75 77 81 85 93 98 100 111 115 119 121 125 128 129 133 143 144 155 161 169 171 175 183 185 187 189 201 203 205 209 215 217 } |
|||
1: { [ 63 64 65 ] [ 323 324 325 ] [ 511 512 513 ] [ 721 722 723 ] [ 899 900 901 ] [ 1443 1444 1445 ] [ 2303 2304 2305 ] [ 2449 2450 2451 ] [ 3599 3600 3601 ] [ 3871 3872 3873 ] [ 5183 5184 5185 ] [ 5617 5618 5619 ] [ 6049 6050 6051 ] [ 6399 6400 6401 ] [ 8449 8450 8451 ] } |
|||
</pre> |
</pre> |
||