A list comprehension is a special syntax in some programming languages to describe lists. It is similar to the way mathematicians describe sets, with a set comprehension, hence the name.

Some attributes of a list comprehension are:

 They should be distinct from (nested) for loops and the use of map and filter functions within the syntax of the language.
 They should return either a list or an iterator (something that returns successive members of a collection, in order).
 The syntax has parts corresponding to that of set-builder notation. 


Task

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.




using System;
using System.Console;
using System.Collections.Generic;
 
module Program
{
 
    PythTriples(n : int) : list[int * int * int]
    {
        $[ (x, y, z) | x in [1..n], y in [x..n], z in [y..n], ((x**2) + (y**2)) == (z**2) ]
    }
 
    GetPythTriples(n : int) : IEnumerable[int * int * int]
    {
        foreach (x in [1..n])
        {
            foreach (y in [x..n])
            {
                foreach (z in [y..n])
                {
                    when (((x**2) + (y**2)) == (z**2))
                    {
                        yield (x, y, z)
                    }
                }
            }
        }
    }
 
    Main() : void
    {
        WriteLine("Pythagorean triples up to x = 20: {0}", PythTriples(20));
 
        foreach (triple in GetPythTriples(20))
        {
            Write(triple)
        }
    }
}