Duffinian numbers: Difference between revisions

Added Easylang
m (→‎{{header|FutureBasic}}: highlight test3)
Tag: Manual revert
(Added Easylang)
 
(5 intermediate revisions by 4 users not shown)
Line 821:
14 6399 6400 6401
15 8449 8450 8451</pre>
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func gcd a b .
while b <> 0
h = b
b = a mod b
a = h
.
return a
.
func sumdiv num .
d = 2
repeat
quot = num div d
until d > quot
if num mod d = 0
sum += d
if d <> quot
sum += quot
.
.
d += 1
.
return sum + 1
.
func isduff n .
if isprim n = 0 and gcd sumdiv n n = 1
return 1
.
return 0
.
proc duffs . .
print "First 50 Duffinian numbers:"
n = 4
repeat
if isduff n = 1
write n & " "
cnt += 1
.
until cnt = 50
n += 1
.
cnt = 0
n = 4
print "\n\nFirst 15 Duffinian triplets:"
repeat
if isduff n = 1 and isduff (n + 1) = 1 and isduff (n + 2) = 1
print n & " - " & n + 2
cnt += 1
.
until cnt = 15
n += 1
.
.
duffs
</syntaxhighlight>
 
=={{header|Factor}}==
Line 1,494 ⟶ 1,561:
860671-860673 910115-910117 913951-913953 963271-963273 968255-968257
991231-991233</pre>
 
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Predicate functions that checks wether an integer is a Duffinian number or not */
duffinianp(n):=if n#1 and not primep(n) and gcd(n,divsum(n))=1 then true$
 
/* Function that returns a list of the first len Duffinian numbers */
duffinian_count(len):=block(
[i:1,count:0,result:[]],
while count<len do (if duffinianp(i) then (result:endcons(i,result),count:count+1),i:i+1),
result)$
 
/* Function that returns a list of the first len Duffinian triples */
duffinian_triples_count(len):=block(
[i:1,count:0,result:[]],
while count<len do (if map(duffinianp,[i,i+1,i+2])=[true,true,true] then (result:endcons([i,i+1,i+2],result),count:count+1),i:i+1),
result)$
 
/* Test cases */
/* First 50 Duffinian numbers */
duffinian_count(50);
 
/* First 15 Duffinian triples */
duffinian_triples_count(15);
</syntaxhighlight>
{{out}}
<pre>
[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]
 
[[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>
 
=={{header|Modula-2}}==
Line 1,667 ⟶ 1,765:
</pre>
 
=={{header|PARI/GP}}==
{{trans|Julia}}
<syntaxhighlight lang="PARI/GP">
isDuffinian(n) = (!isprime(n)) && (gcd(n, sigma(n)) == 1);
 
testDuffinians()=
{
print("First 50 Duffinian numbers:");
count = 0; n = 2;
while(count < 50,
if (isDuffinian(n),
print1(n, " ");
count++;
);
n++;
);
 
print("\n\nFifteen Duffinian triplets:");
count = 0; n = 2;
while (count < 15,
if (isDuffinian(n) && isDuffinian(n + 1) && isDuffinian(n + 2),
print(n, " ", n + 1, " ", n + 2);
count++;
);
n++;
);
}
 
testDuffinians();
</syntaxhighlight>
{{out}}
<pre>
First 50 Duffinian numbers:
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
 
Fifteen Duffinian triplets:
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>
=={{header|Perl}}==
{{libheader|ntheory}}
Line 2,278 ⟶ 2,429:
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./seq" for Lst
import "./fmt" for Fmt
 
1,962

edits