Giuga numbers: Difference between revisions

Content added Content deleted
imported>Maxima enthusiast
No edit summary
(→‎{{header|Euler}}: Sybntax highlight with Mediawiki markup)
Line 551: Line 551:
=={{header|Euler}}==
=={{header|Euler}}==
Uses the C style for loop procedure from the [[Sieve of Eratosthenes]] task
Uses the C style for loop procedure from the [[Sieve of Eratosthenes]] task
'''begin'''
<syntaxhighlight lang="euler">
'''new''' for; '''new''' n; '''new''' gCount;
begin
for &lt;- ` '''formal''' init; '''formal''' test; '''formal''' incr; '''formal''' body;
new for; new n; new gCount;
for <- ` formal init; formal test; formal incr; formal body;
'''begin'''
begin
'''label''' again;
label again;
init;
again: '''if''' test '''then''' '''begin''' body; incr; '''goto''' again '''end''' '''else''' 0
init;
again: if test then begin body; incr; goto again end else 0
'''end'''
end
&apos;
'
;
;
gCount &lt;- 0;
for( ` n &lt;- 2 &apos;, ` gCount &lt; 4 &apos;, ` n &lt;- n + 4 &apos;
gCount <- 0;
for( ` n <- 2 ', ` gCount < 4 ', ` n <- n + 4 '
, ` '''begin'''
'''new''' v; '''new''' f; '''new''' isGiuga; '''new''' fCount;
, ` begin
new v; new f; new isGiuga; new fCount;
v &lt;- n % 2;
v <- n % 2;
isGiuga &lt;- '''true''';
isGiuga <- true;
fCount &lt;- 1;
for( ` f &lt;- 3 &apos;, ` f &lt;= v '''and''' isGiuga &apos;, ` f &lt;- f + 2 &apos;
fCount <- 1;
for( ` f <- 3 ', ` f <= v and isGiuga ', ` f <- f + 2 '
, ` '''if''' v '''mod''' f = 0 '''then''' '''begin'''
, ` if v mod f = 0 then begin
fCount &lt;- fCount + 1;
fCount <- fCount + 1;
isGiuga &lt;- [ [ n % f ] - 1 ] '''mod''' f = 0;
isGiuga <- [ [ n % f ] - 1 ] mod f = 0;
v &lt;- v % f
v <- v % f
'''end''' '''else''' 0
end else 0
&apos;
'
);
);
'''if''' isGiuga '''then''' '''begin'''
if isGiuga then begin
'''if''' fCount &gt; 1 '''then''' '''begin'''
if fCount > 1 then begin
gCount &lt;- gCount + 1;
gCount <- gCount + 1;
'''out''' n
out n
'''end''' '''else''' 0
end else 0
'''end''' '''else''' 0
end else 0
'''end'''
end
&apos;
'
)
'''end''' $
)
end $
</syntaxhighlight>


=={{header|Go}}==
=={{header|Go}}==