List comprehensions: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Icon}} and {{header|unicon}}: Tweak irregular header markup) |
|||
Line 1,773: | Line 1,773: | ||
{{3,4,5},{5,12,13},{6,8,10},{8,15,17},{9,12,15},{12,16,20}} |
{{3,4,5},{5,12,13},{6,8,10},{8,15,17},{9,12,15},{12,16,20}} |
||
</pre> |
</pre> |
||
=={{header|Picat}}== |
|||
Picat has list comprehensions: |
|||
<lang Picat>pyth(N) = [[A,B,C] : A in 1..N, B in A..N, C in B..N, A**2 + B**2 == C**2].</lang> |
|||
as well as array comprehensions for faster access (using {} instead of []): |
|||
<lang Picat>pyth(N) = {{A,B,C} : A in 1..N, B in A..N, C in B..N, A**2 + B**2 == C**2}.</lang> |
|||
A related construct is findall/2 to get all solutions for the specific goal at the second parameter. Here this is shown with member/2 for generating the numbers to test (which for this task is fairly inefficient). |
|||
<lang>pyth(N) = findall([A,B,C], (member(A,1..N), member(B,1..N), member(C,1..N), A < B, A**2 + B**2 == C**2)).</lang> |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |