Autor Beitrag
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: So 08.05.05 15:58 
@F34r0fTh3D4rk: Deine Lösung ist aber falsch (auch wenn sie ein 'IF' weniger hat)!
Denn ich kann ja nicht erst den Turm von A nach B, dann von B nach C und zum Schluss die Scheibe oben drauf packen!
Schau Dir mal die ausgegebene Lösung (bei N=2) an.
Meine Lösung
1->2
1->3
2->3

Deine Lösung
1->2
2->3
1->3 <-- Regelverstoss weil eine größere über einer kleineren Scheibe liegt.
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 08.05.05 17:58 
ich weiß, hatte mich auch vertan, weil ich zuerst keine befehlszeile fürs speichern drin hatte die dazwischen musste, ist aber inzwischen längst behoben :D

wäre auch dumm ((1 nach 2) und (2 nach 3)) ist das gleiche wie (1 nach 3) ^^


Zuletzt bearbeitet von F34r0fTh3D4rk am So 08.05.05 19:33, insgesamt 1-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 08.05.05 18:07 
So meine Version ist fertig.
Einloggen, um Attachments anzusehen!
_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 08.05.05 19:22 
ich habs jetzt angefangen mit nem stringgrid Grafisch zu machen, aber bei mir tut sich garnischt:
ausblenden volle Höhe Delphi-Quelltext
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:
unit UMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure Init(N: integer);
var
  i: integer;
begin
  Form1.StringGrid1.RowCount := N;
  for i := 0 to N - 1 do
    Form1.StringGrid1.Cells[0, i] := inttostr(i + 1);
end;

procedure MoveDisc(aFromField, aToField: integer);
var
  i, j: integer;
begin
  for i := Form1.StringGrid1.RowCount - 1 downto 0 do //das erste leere feld von unten suchen (das zielfeld)
    if Form1.StringGrid1.Cells[atofield, i] = '' then
      begin
        for j := 0 to Form1.StringGrid1.RowCount - 1 do //das oberste belegte feld suchen (das feld, welches zu verschieben ist)
          if Form1.StringGrid1.Cells[afromfield, j] <> '' then
            begin
               Form1.StringGrid1.Cells[atofield, i] := Form1.StringGrid1.Cells[afromfield, j];
               Form1.StringGrid1.Cells[afromfield, j] := '';
               break;
            end;
        break;
      end;
end;

procedure Hanoi(N : Integer; aFromField, aToField, aUsingField : Integer);
begin
  if N > 1 then
    Hanoi(N - 1, aFromField, aUsingField, aToField);
  MoveDisc(aFromField, aToField);
  Application.ProcessMessages;
  if N > 1 then
    Hanoi(N - 1, aUsingField, aToField, aFromField);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Init(strtoint(edit1.text));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  Hanoi(strtoint(edit1.text), 132)
end;

end.

:(
kannst ja vielleicht mal deinen code zeigen GTA


Zuletzt bearbeitet von F34r0fTh3D4rk am So 08.05.05 20:01, insgesamt 1-mal bearbeitet
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 08.05.05 19:32 
Neue Version von meiner Simulation.
Ihr könnt jetzt einstellen, wie viele Scheiben ihr wollt (3 - 15).

ausblenden volle Höhe Delphi-Quelltext
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:
procedure MoveTower (N: Integer; aFromField, aToField, aUsingField: Integer);
begin
  If N > 1 Then
    MoveTower (N - 1, aFromField, aUsingField, aToField);

  Form1.HinwMemo.Lines.Add('-> Scheibe ' + IntToStr(N) + ' von Feld ' +
            IntToStr(aFromField) + ' nach Feld ' + IntToStr(aToField));
  inc(Runde);

  if aFromField = 1 then
  begin
    TLabel(Form1.FindComponent('A' + IntToStr(BelA))).Caption := 'II';
    TLabel(Form1.FindComponent('A' + IntToStr(BelA))).Left := 144;
    dec(BelA);
  end;

  if aFromField = 2 then
  begin
    TLabel(Form1.FindComponent('B' + IntToStr(BelB))).Caption := 'II';
    TLabel(Form1.FindComponent('B' + IntToStr(BelB))).Left := 144;
    dec(BelB);
  end;

  if aFromField = 3 then
  begin
    TLabel(Form1.FindComponent('C' + IntToStr(BelC))).Caption := 'II';
    TLabel(Form1.FindComponent('C' + IntToStr(BelC))).Left := 144;
    dec(BelC);
  end;

  if aToField = 1 then
  begin
    inc(BelA);
    TLabel(Form1.FindComponent('A' + IntToStr(BelA))).Caption := ScheibArray[N];
    TLabel(Form1.FindComponent('A' + IntToStr(BelA))).Left := 150 -
      TLabel(Form1.FindComponent('A' + IntToStr(BelA))).Width div 2;
  end;

  if aToField = 2 then
  begin
    inc(BelB);
    TLabel(Form1.FindComponent('B' + IntToStr(BelB))).Caption := ScheibArray[N];
    TLabel(Form1.FindComponent('B' + IntToStr(BelB))).Left := 150 -
      TLabel(Form1.FindComponent('B' + IntToStr(BelB))).Width div 2;
  end;

  if aToField = 3 then
  begin
    inc(BelC);
    TLabel(Form1.FindComponent('C' + IntToStr(BelC))).Caption := ScheibArray[N];
    TLabel(Form1.FindComponent('C' + IntToStr(BelC))).Left := 150 -
      TLabel(Form1.FindComponent('C' + IntToStr(BelC))).Width div 2;
  end;

  Application.ProcessMessages;
  Sleep(StrToInt(Form1.GeschwEdit.Text));

  If N > 1 Then
    MoveTower (N - 1, aUsingField, aToField, aFromField);
end;
Einloggen, um Attachments anzusehen!
_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 08.05.05 20:02 
warum tut sich aber bei meinem code nischt ? Bin aus deinem Code net schlauer geworden (weil mein system anders funzt)
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 09.05.05 16:23 
Hab meinen Source optimiert:

ausblenden volle Höhe Delphi-Quelltext
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:
procedure MoveTower (N: Integer; aFromField, aToField, aUsingField: Integer);
begin
  If N > 1 Then
    MoveTower (N - 1, aFromField, aUsingField, aToField);

  Form1.HinwMemo.Lines.Add('-> Scheibe ' + IntToStr(N) + ' von Feld ' +
            IntToStr(aFromField) + ' nach Feld ' + IntToStr(aToField));
  inc(Runde);

  // Scheibe entfernen
  TLabel(Form1.FindComponent(FeldArray[aFromField] +
        IntToStr(BelArray[aFromField]))).Caption := 'II';
  TLabel(Form1.FindComponent(FeldArray[aFromField] +
        IntToStr(BelArray[aFromField]))).Left := 144;
  BelArray[aFromField] := BelArray[aFromField] - 1;

  // Scheibe hinzufügen
  BelArray[aToField] := BelArray[aToField] + 1;
  TLabel(Form1.FindComponent(FeldArray[aToField] +
        IntToStr(BelArray[aToField]))).Caption := ScheibArray[N];
  TLabel(Form1.FindComponent(FeldArray[aToField] +
        IntToStr(BelArray[aToField]))).Left := 150 -
        TLabel(Form1.FindComponent(FeldArray[aToField] +
        IntToStr(BelArray[aToField]))).Width div 2;

  Application.ProcessMessages;
  Sleep(StrToInt(Form1.GeschwEdit.Text));

  If N > 1 Then
    MoveTower (N - 1, aUsingField, aToField, aFromField);
end;
Einloggen, um Attachments anzusehen!
_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Larus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 431



BeitragVerfasst: So 15.05.05 14:30 
Rofl: 33791 Schritte um 15 Scheiben zu bewegen! Wozu braucht man so ne Berechnung denn bitteschön! Es wird keiner so Lebensmüde sein diese Anzahl an schritten per Hand durchzuführen oder?
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: So 15.05.05 14:51 
Zitat:

Wozu braucht man so ne Berechnung denn bitteschön!

braucht man nicht, außerdem kann man es ja grafisch darstellen 8)
Micho
Hält's aus hier
Beiträge: 7



BeitragVerfasst: So 15.05.05 19:43 
user profile iconDie letzte Tröte hat folgendes geschrieben:
Man kann alles Iterative Rekursiv lösen, aber nicht alles Rekursive Iterativ...oder versuch ma die Koch Kurve Iterativ auf die beine zu stellen :D

Die Koch-Kurve kann man iterativ mit dem L-System erzeugen. Sind nur zwei Schleifen ...

Außerdem kann man jedes rekursive Programm auch iterativ lösen, wenn man z.B. einen Stapel oder eine Schlange (stack bzw. queue) benutzt.
_________________
www.michael-kreil.de
F34r0fTh3D4rk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5284
Erhaltene Danke: 27

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Di 14.03.06 16:48 
so ich hab mich nochmal dran gemacht, dieses mal mit grafischer umsetzung, jedoch habe ich probleme, da zwischendurch einige teile nicht dargestellt sind, ich weiß einfach nicht, wo die hin sind Oo

EDIT: habs musste nur 3 highs durch lenghts ersetzen ^^