Jump to content

List comprehensions: Difference between revisions

m
alphabetize
No edit summary
m (alphabetize)
Line 4:
 
Write a list comprehension that builds the list of all pythagorean triples with elements between 1 and n. If the language has multiple ways for expressing such a construct (for example, direct list comprehensions and generators), write one example for each.
 
=={{header|Erlang}}==
 
pythag(N) ->
[ {A,B,C} ||
A <- lists:seq(1,N),
B <- lists:seq(1,N),
C <- lists:seq(1,N),
A+B+C =< N,
A*A+B*B == C*C
].
 
=={{header|Haskell}}==
Line 25 ⟶ 36:
 
TODO: Alternative with generators
 
=={{header|Erlang}}==
 
pythag(N) ->
[ {A,B,C} ||
A <- lists:seq(1,N),
B <- lists:seq(1,N),
C <- lists:seq(1,N),
A+B+C =< N,
A*A+B*B == C*C
].
Cookies help us deliver our services. By using our services, you agree to our use of cookies.