Thema: Delphi magisches feld/quadrat

Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
43.177 Beiträge
 
Delphi 12 Athens
 
#6

Re: magisches feld/quadrat

  Alt 12. Jan 2004, 09:51
Zitat von MikeS:
das ist ja sehr interessant was ihr hier so schreibt, aber ich denke in so einem "magischen Quadrat" ist von allen diagonalen, horizontalen und vertikalen die Rede!

Dein Beispiel sieht jedoch so aus:

1 2 (3)
2 (3) 1
(3) 1 2

Das ist wohl nicht ganz das was du suchst!
Das ist auch eine Art Magisches Quadrat, auch wenn es die wohl billigste Variante ist und auch nicht so ganz magisch aussieht.
Delphi-Quellcode:
{StringGrid1: TStringGrid}

Const G = 5; {Größe der Quadrats}

Var X, Y, S: Integer;

Begin
  StringGrid1.ColCount := G + 1;
  StringGrid1.RowCount := G;
  StringGrid1.DefaultColWidth := 25;
  StringGrid1.DefaultRowHeight := 20;
  StringGrid1.FixedCols := 0;
  StringGrid1.FixedRows := 0;
  S := 0;
  For X := 0 to G - 1 do Begin
    For Y := 0 to G - 1 do
      StringGrid1.Cells[X, Y] := IntToStr((X + Y) mod G + 1);
    Inc(S, X + 1);
  End;
  StringGrid1.Cells[G, G - 1] := IntToStr(S);
End;
Garbage Collector ... Delphianer erzeugen keinen Müll, also brauchen sie auch keinen Müllsucher.
my Delphi wish list : BugReports/FeatureRequests
  Mit Zitat antworten Zitat