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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
| procedure TForm1.Button11Click(Sender: TObject);
var primitives: array[0..47,0..8] of byte = ((0,0,0,0,0,1,1,0,1),(0,0,1,0,0,0,1,0,0),(0,1,0,0,1,1,1,1,1),(0,1,1,0,1,0,1,1,0),(1,0,0,1,0,1,0,0,1),(1,0,1,1,0,0,0,0,0),(1,1,0,1,1,1,0,1,1),(1,1,1,1,1,0,0,1,0),(0,0,0,0,1,0,1,1,0),(0,1,0,0,0,0,1,0,0),(0,0,1,0,1,1,1,1,1),(0,1,1,0,0,1,1,0,1),(1,0,0,1,1,0,0,1,0),(1,1,0,1,0,0,0,0,0),(1,0,1,1,1,1,0,1,1),(1,1,1,1,0,1,0,0,1),(0,0,0,0,0,1,0,1,1),(0,0,1,0,0,0,0,1,0),(1,0,0,1,0,1,1,1,1),(1,0,1,1,0,0,1,1,0),(0,1,0,0,1,1,0,0,1),(0,1,1,0,1,0,0,0,0),(1,1,0,1,1,1,1,0,1),(1,1,1,1,1,0,1,0,0),(0,0,0,0,1,0,0,1,1),(0,1,0,0,0,0,0,0,1),(1,0,0,1,1,0,1,1,1),(1,1,0,1,0,0,1,0,1),(0,0,1,0,1,1,0,1,0),(0,1,1,0,0,1,0,0,0),(1,0,1,1,1,1,1,1,0),(1,1,1,1,0,1,1,0,0),(0,0,0,1,0,0,1,1,0),(1,0,0,0,0,0,0,1,0),(0,0,1,1,0,1,1,1,1),(1,0,1,0,0,1,0,1,1),(0,1,0,1,1,0,1,0,0),(1,1,0,0,1,0,0,0,0),(0,1,1,1,1,1,1,0,1),(1,1,1,0,1,1,0,0,1),(0,0,0,1,0,0,1,0,1),(1,0,0,0,0,0,0,0,1),(0,1,0,1,1,0,1,1,1),(1,1,0,0,1,0,0,1,1),(0,0,1,1,0,1,1,0,0),(1,0,1,0,0,1,0,0,0),(0,1,1,1,1,1,1,1,0),(1,1,1,0,1,1,0,1,0));
table:array[0..255] of longint;
d0,d1,d2,x,y,i,j:longint;
data:array[0..7] of longint;
points:array[0..511] of byte;
s,sd:string;
l,t,lt,ht,gfs:longint;
psc,w0,w1:longint;
f,f1: file of byte;
a,max: byte;
flag: Boolean;
savg,z,prof:real;
cavg,test:longint;
OutPaper: TStringList;
cb:boolean;
begin
cavg:=0;
j:=0;
while (j<256) do
begin
x:=j;
i:=0;
while (i<8) do
begin
data[i]:=x and 1;
x:=x shr 1;
i:=i+1;
end;
i:=0;
while (i<512) do
begin
points[i]:=0;
i:=i+1;
end;
d0:=0;
while (d0<48) do
begin
d1:=0;
while (d1<48) do
begin
d2:=0;
while (d2<48) do
begin
x:=0;
i:=0;
while (i<9) do
begin
x:=x*2+data[primitives[d0,i]*4+primitives[d1,i]*2+primitives[d2,i]*1];
i:=i+1;
end;
points[x]:=1;
d2:=d2+1;
end;
d1:=d1+1;
end;
d0:=d0+1;
end;
x:=0;
i:=0;
while (i<512) do
begin
x:=x+points[i];
i:=i+1;
end;
table[j]:=x;
cavg:=cavg+x;
j:=j+1;
end;
OutPaper := TStringList.Create;
GetTreeDirs(Edit1.Text,OutPaper);
prof:=0;
gfs:=0;
while (gfs<OutPaper.Count) do
begin
sd:=OutPaper.Strings[gfs];
i:=0;
while (i<512) do
begin
x:=x+points[i];
i:=i+1;
end;
while (i<1000000) do
begin
primes[i]:=0;
i:=i+1;
end;
max:=0;
test:=0;
if (StrPos(PChar(sd),'.')<>nil) then
begin
AssignFile(f,sd);
test:=1;
end;
if ((IOResult = 0) and (test=1)) then
begin
Reset(f);
cavg:=0;
l:=0;
while (not Eof(f)) do
begin
Read(f,a);
primes[l]:=a;
l:=l+1;
end;
CloseFile(f);
savg:=0;
cavg:=0;
sd:='';
ht:=l;
l:=ht;
j:=0;
while (j<ht) do
begin
x:=primes[j mod ht];
i:=0;
while (i<8) do
begin
bs[j*8+i]:=x and 1;
x:=x shr 1;
i:=i+1;
end;
j:=j+1;
end;
z:=0;
i:=0;
while (i<(ht*8)) do
begin
x:=0;
j:=i;
while (j<i+8) do
begin
x:=x*2+bs[((j) mod (ht*8))];
j:=j+1;
end;
w0:=x+0;
w1:=x+1;
if (table[w0]<table[w1]) then
begin
y:=0;
end else
begin
y:=1;
end;
if (bs[((i+8) mod (ht*8))]=y) then
begin
z:=z+1;
end;
i:=i+1;
end;
end;
savg:=(z/(ht*8));
prof:=prof+abs((z/(ht*8))-0.5);
Memo2.Lines.Add(FloatToStr(savg));
gfs:=gfs+1;
end;
Memo2.Lines.Add('entrpoy: '+FloatToStr(prof/gfs));
end; |