Eisenstein primes: Difference between revisions
Content deleted Content added
SqrtNegInf (talk | contribs) Added Perl (in the right place) |
Added Sidef |
||
Line 375: | Line 375: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="raku" line> |
||
my \ω = exp 2i × π/3; |
my \ω = exp 2i × π/3; |
||
Line 414: | Line 414: | ||
-0.5000 -7.7942i -7.0000 +3.4641i +0.5000 -7.7942i -6.5000 +4.3301i |
-0.5000 -7.7942i -7.0000 +3.4641i +0.5000 -7.7942i -6.5000 +4.3301i |
||
+6.5000 -4.3301i -0.5000 +7.7942i +7.0000 -3.4641i +0.5000 +7.7942i |
+6.5000 -4.3301i -0.5000 +7.7942i +7.0000 -3.4641i +0.5000 +7.7942i |
||
</pre> |
|||
=={{header|Sidef}}== |
|||
{{trans|Raku}} |
|||
<syntaxhighlight lang="ruby" line>class Eisenstein(a, b, w = (-1 + sqrt(3).i)/2) { |
|||
method norm { |
|||
a**2 - a*b + b**2 |
|||
} |
|||
method to_s { |
|||
sprintf('%+8.4f%+8.4fi', reals(a + b*w)) |
|||
} |
|||
} |
|||
var E = [] |
|||
for e in (-10..10 ~X -10..10 -> map_2d {|x,y| Eisenstein(x,y) }) { |
|||
var c = [e.a,e.b].map{.abs}.max |
|||
if ( |
|||
((0 ~~ [e.a, e.b]) || (e.a == e.b)) ? |
|||
(c.is_congruent(2,3) && c.is_prime) : e.norm.is_prime |
|||
) { |
|||
E << e |
|||
} |
|||
} |
|||
E.sort_by { .norm }.first(100).slices(4).each {|s| |
|||
say s.join(' ') |
|||
}</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
-1.5000 -0.8660i +0.0000 -1.7321i -1.5000 +0.8660i +1.5000 -0.8660i |
|||
+0.0000 +1.7321i +1.5000 +0.8660i -1.0000 -1.7321i -2.0000 +0.0000i |
|||
+1.0000 -1.7321i -1.0000 +1.7321i +2.0000 +0.0000i +1.0000 +1.7321i |
|||
-2.0000 -1.7321i -2.5000 -0.8660i -0.5000 -2.5981i -2.5000 +0.8660i |
|||
+0.5000 -2.5981i -2.0000 +1.7321i +2.0000 -1.7321i -0.5000 +2.5981i |
|||
+2.5000 -0.8660i +0.5000 +2.5981i +2.5000 +0.8660i +2.0000 +1.7321i |
|||
-2.5000 -2.5981i -3.5000 -0.8660i -1.0000 -3.4641i -3.5000 +0.8660i |
|||
+1.0000 -3.4641i -2.5000 +2.5981i +2.5000 -2.5981i -1.0000 +3.4641i |
|||
+3.5000 -0.8660i +1.0000 +3.4641i +3.5000 +0.8660i +2.5000 +2.5981i |
|||
-3.5000 -2.5981i -4.0000 -1.7321i -0.5000 -4.3301i -4.0000 +1.7321i |
|||
+0.5000 -4.3301i -3.5000 +2.5981i +3.5000 -2.5981i -0.5000 +4.3301i |
|||
+4.0000 -1.7321i +0.5000 +4.3301i +4.0000 +1.7321i +3.5000 +2.5981i |
|||
-2.5000 -4.3301i -5.0000 +0.0000i +2.5000 -4.3301i -2.5000 +4.3301i |
|||
+5.0000 +0.0000i +2.5000 +4.3301i -3.5000 -4.3301i -5.5000 -0.8660i |
|||
-2.0000 -5.1962i -5.5000 +0.8660i +2.0000 -5.1962i -3.5000 +4.3301i |
|||
+3.5000 -4.3301i -2.0000 +5.1962i +5.5000 -0.8660i +2.0000 +5.1962i |
|||
+5.5000 +0.8660i +3.5000 +4.3301i -5.0000 -3.4641i -5.5000 -2.5981i |
|||
-0.5000 -6.0622i -5.5000 +2.5981i +0.5000 -6.0622i -5.0000 +3.4641i |
|||
+5.0000 -3.4641i -0.5000 +6.0622i +5.5000 -2.5981i +0.5000 +6.0622i |
|||
+5.5000 +2.5981i +5.0000 +3.4641i -4.0000 -5.1962i -6.5000 -0.8660i |
|||
-2.5000 -6.0622i -6.5000 +0.8660i +2.5000 -6.0622i -4.0000 +5.1962i |
|||
+4.0000 -5.1962i -2.5000 +6.0622i +6.5000 -0.8660i +2.5000 +6.0622i |
|||
+6.5000 +0.8660i +4.0000 +5.1962i -6.5000 -4.3301i -7.0000 -3.4641i |
|||
-0.5000 -7.7942i -7.0000 +3.4641i +0.5000 -7.7942i -6.5000 +4.3301i |
|||
+6.5000 -4.3301i -0.5000 +7.7942i +7.0000 -3.4641i +0.5000 +7.7942i |
|||
</pre> |
</pre> |
||