List comprehensions: Difference between revisions

PascalABC.NET
(PascalABC.NET)
 
(2 intermediate revisions by 2 users not shown)
Line 1,733:
{{works with|PARI/GP|2.4.2}}
<syntaxhighlight lang="parigp">f(n)=select(vector(n^3,i,vector(3,j,i\n^(j-1)%n)),v->norml2(v)==2*v[3]^2)</syntaxhighlight>
 
=={{header|PascalABC.NET}}==
<syntaxhighlight lang="delphi">
##
(1..20).CartesianPower(3).Where(\(x,y,z) -> (x*x + y*y = z*z) and (x < y)).PrintLines
</syntaxhighlight>
{{out}}
<pre>
[3,4,5]
[5,12,13]
[6,8,10]
[8,15,17]
[9,12,15]
[12,16,20]
</pre>
 
=={{header|Perl}}==
Line 2,639 ⟶ 2,654:
Pythagorean triples:
[[3, 4, 5], [5, 12, 13], [6, 8, 10], [9, 12, 15]]
</pre>
 
=={{header|Uiua}}==
<syntaxhighlight lang="uiua">
☇1⊞≡⊂⊞⊂..+1⇡20 # Cartesian product, flattened.
▽⊸≡(=1/↧/≥◫2) # Keep triplets which are in ascending order.
▽⊸≡(=⊃(/+⊏0_1|⊡2)×.) # Keep pythagorean triplets.
</syntaxhighlight>
{{out}}
<pre>
╭─
╷ 3 4 5
5 12 13
6 8 10
8 15 17
9 12 15
12 16 20
</pre>
 
Line 2,707 ⟶ 2,740:
=={{header|Wren}}==
Using a generator.
<syntaxhighlight lang="ecmascriptwren">var pythTriples = Fiber.new { |n|
(1..n-2).each { |x|
(x+1..n-1).each { |y|
229

edits