![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Оптимизация кода [D7, XP]
--------- © (2006-10-26 23:40:00)Люди помогите!!!!! Как мне это лучше сделать, чтоб машина не гнала бесу..тормозит по чёрному!!!!
вот код:
procedure TForm1.rasbr;
var
c_e: array [0..15] of Integer;
x, xx: Integer;
zxc: Boolean;
begin
for xx := 0 to 15 do
begin
zxc := False;
Randomize;
x := Random(15);
repeat
if xx=0 then
begin
c_e[xx] := x;
zxc := True;
end;
if xx=1 then
if c_e[0]<>x then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=2 then
if (c_e[0]<>x)and(c_e[1]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=3 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=4 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=5 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=6 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=7 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=8 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=9 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=10 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x)and(c_e[9]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=11 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x)and(c_e[9]<>x)and(c_e[10]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=12 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x)and(c_e[9]<>x)and(c_e[10]<>x)and(c_e[11]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=13 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x)and(c_e[9]<>x)and(c_e[10]<>x)and(c_e[11]<>x)
and(c_e[12]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=14 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x)and(c_e[9]<>x)and(c_e[10]<>x)and(c_e[11]<>x)
and(c_e[12]<>x)and(c_e[13]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
if xx=15 then
if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x)and(c_e[9]<>x)and(c_e[10]<>x)and(c_e[11]<>x)
and(c_e[12]<>x)and(c_e[13]<>x)and(c_e[14]<>x) then
begin
c_e[xx] := x;
zxc := True;
Beep;
end else
begin
Randomize;
x := Random(15);
zxc := False;
end;
until zxc = True;
end;
end;
DrPass (2006-10-27 00:10:00) [21]
> Ketmar © (27.10.06 00:04) [10]
У этого кода еще вторая функция есть - ускорить приход Антихриста
ProgRAMmer Dimonych (2006-10-27 00:08:00) [22]> [14]
Действительно... (С) Староконь
Ketmar (2006-10-27 00:07:00) [23]>[12] ProgRAMmer Dimonych(c) 27-Oct-2006, 00:06
>Я бы эту проверку в отдельную функцию вынес:
нафига?
Ketmar (2006-10-27 00:06:00) [24]ах, да. +1 за трудолюбивость. -16384 за сам код.
ProgRAMmer Dimonych (2006-10-27 00:06:00) [25]if (c_e[0]<>x)and(c_e[1]<>x)and(c_e[2]<>x)and(c_e[3]<>x)
and(c_e[4]<>x)and(c_e[5]<>x)and(c_e[6]<>x)and(c_e[7]<>x)
and(c_e[8]<>x)and(c_e[9]<>x)and(c_e[10]<>x)and(c_e[11]<>x)
and(c_e[12]<>x)and(c_e[13]<>x) then
Я бы эту проверку в отдельную функцию вынес:
function IsAllFalse(Count,x:Integer):Boolean;
var
i:Integer;
begin
Result:=True;
for i:=0 to Count-1 do
if c_e[i]=x then
Result:=False;
end;
Ketmar (2006-10-27 00:05:00) [26]тьфу. автор разрушил всю интригу... %-(((
Ketmar (2006-10-27 00:04:00) [27]а-а-а! я осилил код! кто догадался, для чего он? без анализа? интуитивно? нет, в цитатник, однозначно. только жаль, что всего 16 чисел надо. лучше бы 256. или 1024.
------------ (2006-10-27 00:03:00) [28]2го просто не дождёшся..мне нужно сгенерировать 16 чисел в разброс так, чтоб они не повторялись
Kolan (2006-10-27 00:00:00) [29]> Как мне это лучше сделать
Выделить все и удалить.
Anatoly Podgoretsky (2006-10-26 23:57:00) [30]Обязательно дождись второго.
------------ (2006-10-26 23:55:00) [31]1ое число есть а дальше он так думать начинает
Anatoly Podgoretsky (2006-10-26 23:53:00) [32]Не это черный сотона или ССЗБ или что еще хуже, даже называть не хочется.
DrPass (2006-10-26 23:52:00) [33]
> Мастером
= Мастеров. Руки дрожат и плохо слушаются
DrPass (2006-10-26 23:51:00) [34]На самом деле такой код мог родиться только в черном разуме адепта, прошедшего как минимум третий круг инициации. Я даже у себя за столом, в нескольких тысяч км от сервера "Мастером", ощущаю исходящее от него Зло
Anatoly Podgoretsky (2006-10-26 23:51:00) [35]Много буков, что бы разбираться, а какая часть тормозит, померь и скажи нам, тогда поможем.
Кстати ты слышал, что Паскаль (Дельфи) поддерживают оператор CASE?
Ketmar (2006-10-26 23:48:00) [36]лучше всего или провести ритуал посвящения машины Сатане (тогда машина не будет бесов бояться), или не вызывать бесов без достаточного опыта в саммонинге.