pragma Extensions_Allowed (On);
--  APL text (T32c): membership (`∊`), index of (dyadic `⍳`), replicate by counts, and
--  grades (`⍋` `⍒`, stable) and sorting by them, proved
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
   subtype Small is Integer range -100 .. 100;
   type Vector is array (Positive range <>) of Integer;
   type Smalls is array (Positive range <>) of Small;
   type Flags is array (Positive range <>) of Boolean;
   X : constant Smalls := (3, 1, 4, 1, 5);
   Y : constant Smalls := (1, 9, 5);
   procedure Show (V : Vector) is
   begin
      for E of V loop
         Put (Integer'Image (E));
      end loop;
      New_Line;
   end Show;
   procedure Show (F : Flags) is
   begin
      for E of F loop
         Put (if E then " 1" else " 0");
      end loop;
      New_Line;
   end Show;
   Found : constant Flags := APL ("Y ∊ X");
   Places : constant Vector := APL ("X ⍳ Y");
   Common : constant Vector := APL ("(X ∊ Y) / X");
   subtype Count is Integer range 0 .. 3;
   type Counts is array (Positive range <>) of Count;
   C : constant Counts := (2, 0, 1, 3, 1);
   Repeated : constant Vector := APL ("C / X");
   Doubled : constant Vector := APL ("2 0 1 0 1 / X");
   Up : constant Vector := APL ("⍋ X");
   Down : constant Vector := APL ("⍒ X");
   Sorted : constant Vector := APL ("X[⍋ X]");
begin
   Show (Found);
   Show (Places);
   Show (Common);
   Show (Repeated);
   Show (Doubled);
   Show (Up);
   Show (Down);
   Show (Sorted);
end Main;
