Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
11
Task/Pascals-triangle/Ada/pascals-triangle-1.ada
Normal file
11
Task/Pascals-triangle/Ada/pascals-triangle-1.ada
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package Pascal is
|
||||
|
||||
type Row is array (Natural range <>) of Natural;
|
||||
|
||||
function Length(R: Row) return Positive;
|
||||
|
||||
function First_Row(Max_Length: Positive) return Row;
|
||||
|
||||
function Next_Row(R: Row) return Row;
|
||||
|
||||
end Pascal;
|
||||
26
Task/Pascals-triangle/Ada/pascals-triangle-2.ada
Normal file
26
Task/Pascals-triangle/Ada/pascals-triangle-2.ada
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package body Pascal is
|
||||
|
||||
function First_Row(Max_Length: Positive) return Row is
|
||||
R: Row(0 .. Max_Length) := (0 | 1 => 1, others => 0);
|
||||
begin
|
||||
return R;
|
||||
end First_Row;
|
||||
|
||||
function Next_Row(R: Row) return Row is
|
||||
S: Row(R'Range);
|
||||
begin
|
||||
S(0) := Length(R)+1;
|
||||
S(Length(S)) := 1;
|
||||
for J in reverse 2 .. Length(R) loop
|
||||
S(J) := R(J)+R(J-1);
|
||||
end loop;
|
||||
S(1) := 1;
|
||||
return S;
|
||||
end Next_Row;
|
||||
|
||||
function Length(R: Row) return Positive is
|
||||
begin
|
||||
return R(0);
|
||||
end Length;
|
||||
|
||||
end Pascal;
|
||||
18
Task/Pascals-triangle/Ada/pascals-triangle-3.ada
Normal file
18
Task/Pascals-triangle/Ada/pascals-triangle-3.ada
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Command_Line, Pascal; use Pascal;
|
||||
|
||||
procedure Triangle is
|
||||
|
||||
Number_Of_Rows: Positive := Integer'Value(Ada.Command_Line.Argument(1));
|
||||
Row: Pascal.Row := First_Row(Number_Of_Rows);
|
||||
|
||||
begin
|
||||
loop
|
||||
-- print one row
|
||||
for J in 1 .. Length(Row) loop
|
||||
Ada.Integer_Text_IO.Put(Row(J), 5);
|
||||
end loop;
|
||||
Ada.Text_IO.New_Line;
|
||||
exit when Length(Row) >= Number_Of_Rows;
|
||||
Row := Next_Row(Row);
|
||||
end loop;
|
||||
end Triangle;
|
||||
Loading…
Add table
Add a link
Reference in a new issue