aboutsummaryrefslogtreecommitdiff
path: root/challenge-201/deadmarshal/ada/ch2.adb
blob: 1ce6235e8ba74b487d6b2268f89ccda6ed3ccf2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
with Ada.Text_IO; use Ada.Text_IO;

procedure Ch2 is
  Count:Integer := 0;
  type TArr is array(0..4) of integer;
  Arr:TArr;

  procedure Find_Combinations(Arr:in out TArr;Index,Num,Reduced_Num:Integer) is
    Prev:Integer;
  begin
    if Reduced_Num < 0 then return; end if;
    if Reduced_Num = 0 then Count := Count + 1; return; end if;
    if Index = 0 then Prev := 1; else Prev := Arr(Index-1); end if;
    for I in Prev..Num loop
      Arr(Index) := I;
      Find_Combinations(Arr,Index+1,Num,Reduced_Num-I);
    end loop;
  end Find_Combinations;
begin
  Find_Combinations(Arr,0,5,5);
  Put_Line(Integer'Image(Count));
end Ch2;