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.




with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Doubly_Linked_Lists;
 
procedure Pythagore_Set is
 
   type Triangles is array (1 .. 3) of Positive;
 
   package Triangle_Lists is new Ada.Containers.Doubly_Linked_Lists (
      Triangles);
   use Triangle_Lists;
 
   function Find_List (Upper_Bound : Positive) return List is
      L : List := Empty_List;
   begin
      for A in 1 .. Upper_Bound loop
         for B in A + 1 .. Upper_Bound loop
            for C in B + 1 .. Upper_Bound loop
               if ((A * A + B * B) = C * C) then
                  Append (L, (A, B, C));
               end if;
            end loop;
         end loop;
      end loop;
      return L;
   end Find_List;
 
   Triangle_List : List;
   C             : Cursor;
   T             : Triangles;
 
begin
   Triangle_List := Find_List (Upper_Bound => 20);
 
   C := First (Triangle_List);
   while Has_Element (C) loop
      T := Element (C);
      Put
        ("(" &
         Integer'Image (T (1)) &
         Integer'Image (T (2)) &
         Integer'Image (T (3)) &
         ") ");
      Next (C);
   end loop;
end Pythagore_Set;
 