this slowpoke moves

Generate Conway Numbers

procedure GenerateConwaySequence(const TS: TStrings; const n: Word = 12;
  const Init: Byte = 1);
var
  i, j: Integer;
  Line, Reading, Tmp: string;
begin
  with TS do
  begin
    Clear;
    BeginUpdate;
    Add(IntToStr(Init));
    for i := 0 to n -1 do
    begin
      Line := TS[i];
      Reading := '';
      Tmp := '';
      for j := 1 to Length(Line) do
      begin
        Tmp := Format('%s%s', [Tmp, Line[j]]);
        if (j = Length(Line)) or (Line[j + 1] <> Tmp[Length(Tmp)]) then
        begin
          Reading := Format('%s%d%s', [Reading, Length(Tmp), Tmp[1]]);
          Tmp := '';
        end;
      end;
      Add(Reading);
    end;
    EndUpdate;
  end;
end;

procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var Lin, Col: Integer;
begin
  with RichEdit1 do
  begin
    Lin := SendMessage(Handle, EM_LineFromChar, SelStart, 0);
    Col := Selstart - SendMessage(Handle, EM_LineIndex, Lin, 0) + 1;
  end;
  Edit1.Text := Format('%d:  %d', [Lin + 1, Col]);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SpinEdit2.MinValue := 0;
  SpinEdit2.MaxValue := High(Word);
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
begin
  GenerateConwaySequence(RichEdit1.Lines, SpinEdit2.Value, SpinEdit1.Value);
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate