-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpascal.adb
69 lines (60 loc) · 1.34 KB
/
pascal.adb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
with Ada.Text_IO; use Ada.Text_IO;
procedure Pascal is
type Node;
type List is access Node;
type Node is record
Value: Integer;
Next: List;
end record;
function Get(L: List; I: Integer) return Integer is
begin
if I = 0 then return L.Value; end if;
return Get(L.next, I - 1);
end;
procedure Set(L: List; I, V: Integer) is
begin
if I = 0 then
L.Value := v;
else
Set(L.next, I - 1, V);
end if;
end;
function Create(N: Integer) return List is
L: List;
begin
if N = 0 then return null; end if;
L := new Node;
L.Value := 0;
L.Next := Create(N - 1);
return L;
end;
N: Integer := 42;
R: List := Create(N + 1);
procedure print_row(I: Integer) is
begin
for J in 0..I loop
if Get(R, J) /= 0 then
Put('*');
else
Put('.');
end if;
end loop;
New_Line;
end Print_Row;
procedure compute_row(I: Integer) is
begin
for J in reverse 1..I loop
Set(R, J, (Get(R, J) + Get(R, J-1)) rem 7);
end loop;
Set(R, 0, 1);
end Compute_Row;
begin
for i in 0 .. N-1 loop
Set(R, I, 0);
compute_row(i);
print_row(i);
end loop;
end Pascal;
-- Local Variables:
-- compile-command: "gnatmake pascal.adb && ./pascal"
-- End: