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
|
{ ====================================================================== }
procedure TForm1.operations(t: tab; max: integer);
var i, j1, j2: integer;
a : longint;
t1 : tab;
begin
for i := 1 to 4 do
for j1 := 1 to max - 1 do
for j2 := j1 + 1 to max do
begin
case i of
1: a := t[j1] + t[j2];
2: a := t[j1] - t[j2];
3: a := t[j1] * t[j2];
4: begin
a := t[j1] div t[j2];
if t[j2] * a <> t[j1] then a := 0;
end;
end;
if a > 0 then
begin
if a = t[0] then
begin
//gotoxy(1,8-max);write(t[j1],signe[i],t[j2],'=',a);
Form1.ListBox1.Items.Add(inttostr(t[j1]) + signe[i] + inttostr(t[j2]) + '=' + inttostr(a));
trouve := true ;
exit;
end
Else
Begin
If (Abs(a - t[0]) < Proche) Then
Begin
Proche := Abs(a - t[0]) ;
Voisin := a ;
End ;
End ;
move(t, t1, 28);
t1[j1] := a; t1[j2] := 0;
repeat
echange := false;
for ii := 1 to max - 1 do
if t1[ii] < t1[ii + 1] then
begin
aa := t1[ii]; t1[ii] := t1[ii + 1]; t1[ii + 1] := aa;
echange := true;
end;
until not echange;
operations(t1, max - 1);
if trouve then
begin
//gotoxy(1,8-max);write(t[j1],signe[i],t[j2],'=',a);
Form1.ListBox1.Items.Add(inttostr(t[j1]) + signe[i] + inttostr(t[j2]) + '=' + inttostr(a));
exit;
end
Else
Begin
If (Abs(a - t[0]) < Proche) Then
Begin
Proche := Abs(a - t[0]) ;
Voisin := a ;
End ;
End ;
end;
end;
end;
{ ========================================================================= }
Procedure TForm1.Button1Click(Sender: TObject);
Var
Texte : String ;
Maxi : Integer ;
i : Integer ;
Begin
Maxi := 6 ;
Randomize;
Nombres[0] := Random(1000) ;
For i := 1 to Maxi do begin
Nombres[i] := Random(99) + 1 ;
End;
Screen.Cursor := crHourGlass;
Trouve := false;
Proche := 100000000 ;
Voisin := 0 ;
ListBox1.Clear;
Form1.ListBox1.Items.Add('Nombre à trouver : '+ IntToStr(Nombres[0])) ;
Texte := 'Tirage : ' ;
For i := 1 to Maxi Do
Texte := Texte + IntToStr(Nombres[i]) + ' - ' ;
Form1.ListBox1.Items.Add(Texte) ;
Form1.ListBox1.Items.Add('') ;
Application.ProcessMessages;
Operations(Nombres, Maxi);
If Trouve Then
Form1.ListBox1.Items.Add('Le compte est bon --')
Else
Begin
Form1.ListBox1.Items.Add('Le compte n''est pas bon --');
Form1.ListBox1.Items.Add(' Valeur la plus proche : '+ IntToStr(Voisin));
End ;
Screen.Cursor := crDefault;
End; |
Partager