List comprehensions: Difference between revisions

PascalABC.NET
m (→‎{{header|C}}: 3 syntaxhighlight -> 1 plus comment)
(PascalABC.NET)
 
(5 intermediate revisions by 3 users not shown)
Line 21:
{{trans|Python}}
 
<syntaxhighlight lang="11l"> print(cart_product(1..20, 1..20, 1..20).filter((x, y, z) -> x ^ 2 + y ^ 2 == z ^ 2 & y C x .. z))</syntaxhighlight>
 
{{out}}
Line 275:
end mReturn</syntaxhighlight>
{{Out}}
<syntaxhighlight lang="applescript"pre>{{3, 4, 5}, {5, 12, 13}, {6, 8, 10}, {7, 24, 25}, {8, 15, 17}, {9, 12, 15}, {12, 16, 20}, {15, 20, 25}}</syntaxhighlightpre>
 
=={{header|Arturo}}==
Line 604:
[x, y, z]
))
<code># pyth</code> can also be written more concisely as
<syntaxhighlight# lang="coffeescript">pyth = (n) -> flatten (flatten ([x, y, z] for z in [y..n] when x*x + y*y is z*z for y in [x..n]) for x in [1..n])</syntaxhighlight>
 
console.dir pyth 20</syntaxhighlight>
 
<code>pyth</code> can also be written more concisely as
 
<syntaxhighlight lang="coffeescript">pyth = (n) -> flatten (flatten ([x, y, z] for z in [y..n] when x*x + y*y is z*z for y in [x..n]) for x in [1..n])</syntaxhighlight>
 
=={{header|Common Lisp}}==
Line 1,735 ⟶ 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,641 ⟶ 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,709 ⟶ 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