| 1 |
-- { dg-do compile } |
| 2 |
-- { dg-options "-gnat2022" } |
| 3 |
|
| 4 |
with Ada.Text_IO; use Ada.Text_IO; |
| 5 |
|
| 6 |
procedure Reduce5 is |
| 7 |
subtype Chunk_Number is Natural range 1 .. 8; |
| 8 |
Grid : array (1 .. 80, 1 .. 100) of Boolean := (others => (others => False)); |
| 9 |
Partial_Sum, Partial_Max : array (Chunk_Number) of Natural := (others => 0); |
| 10 |
Partial_Min : array (Chunk_Number) of Natural := (others => Natural'Last); |
| 11 |
|
| 12 |
begin |
| 13 |
for I in Grid'Range (1) loop |
| 14 |
Grid (I, 1) := (for all J in Grid'Range (2) => Grid (I, J) = True); |
| 15 |
end loop; |
| 16 |
|
| 17 |
for I in Grid'Range (1) loop |
| 18 |
declare |
| 19 |
True_Count : constant Natural := |
| 20 |
[for J in Grid'Range(2) => (if Grid (I, J) then 1 else 0)]'Reduce("+",0); |
| 21 |
begin |
| 22 |
Partial_Sum (I) := @ + True_Count; |
| 23 |
Partial_Min (I) := Natural'Min (@, True_Count); |
| 24 |
Partial_Max (I) := Natural'Max (@, True_Count); |
| 25 |
end; |
| 26 |
end loop; |
| 27 |
|
| 28 |
Put_Line ("Total=" & Natural'Image (Partial_Sum'Reduce ("+", 0)) & |
| 29 |
", Min=" & Natural'Image (Partial_Min'Reduce(Natural'Min, Natural'Last)) & |
| 30 |
", Max=" & Natural'Image (Partial_Max'Reduce(Natural'Max, 0))); |
| 31 |
|
| 32 |
Put_Line ("Total=" & Partial_Sum'Reduce ("+", 0)'Image & |
| 33 |
", Min=" & Partial_Min'Reduce(Natural'Min, Natural'Last)'Image & |
| 34 |
", Max=" & Partial_Max'Reduce(Natural'Max, 0)'Image); |
| 35 |
|
| 36 |
end; |