Autor Beitrag
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 16:11 
das mit dem = hat sich erledigt

aber jetzt hab ich n anderes
_Permutation soll definiert werden als Variable
Tilman
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1405
Erhaltene Danke: 51

Win 7, Android
Turbo Delphi, Eclipse
BeitragVerfasst: Mi 12.12.07 16:11 
user profile icon110022 hat folgendes geschrieben:
brauch ich nich
der meint der Fehle liegt vor dem =


Egal, poste es trotzdem ;) die Stelle die der Compiler bemängelt muss noch lange nicht die Stelle sein an der's hapert. Ist eine wichtige Erkenntnis die z.B. php Programmier schnell lernen, die aber für fast alle Sprachen gilt.

_________________
Bringe einen Menschen zum grübeln, dann kannst du heimlich seinen Reis essen.
(Koreanisches Sprichwort)
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 16:13 
hab das an die falsche stelle gesetzt :D

hab aber n anders Problem der will
_Permutation als variable haben
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 17:27 
weiß keiner ne antwort?
Regan
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 2157
Erhaltene Danke: 72


Java (Eclipse), Python (Sublimetext 3)
BeitragVerfasst: Mi 12.12.07 17:30 
Poste doch bitte einfach den Quelltext.
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 17:33 
Wenns euch froh macht
hier mal der ganze quelltext.
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:
unit Unit1;

interface

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

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

var
  Form1: TForm1;


implementation

{$R *.dfm}
type
TCharSet = Set Of Char;
procedure TForm1.Button1Click(Sender: TObject);
Procedure Permutations (Const aString : String; aResults : TStrings);
  Procedure _Permutation(Const aString, aResult : String; anIndex : Integer; aUsedChars : TCharSet);
  Var
    i : Integer;

  Begin
    For i:=1 To Length (aString) Do
      If Not (aString[i] In aUsedChars) Then
  If anIndex = Length (aString) Then
    aResults.Add(aResult+aString[i])
  Else
    _Permutation (aString, aResult + aString[i], anIndex + 1, aUsedChars + [aString[i]]);
  End;

Begin
  _Permutation (aString, '', 1, []);
end;
end.

Das soll mit nem editfeld als zahleneingabe und nem memo als zahlenausgabe sein
wenn was falsch is dann bitte verbessern.
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Mi 12.12.07 17:50 
Hallo!

Probier es mal damit.
Bei Dir existieren noch sehr, sehr viele Wissenslücken, vor allem in den Grundlagen, scheint mir.
Bevor Du versuchst ein Programm via Copy&Paste zu "programmieren", versuch lieber zu verstehen, was Du da überhaupt machst.

Mal was Copy&Paste-kompatibles:
ausblenden 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:
type
  TCharSet = set of char;

Procedure Permutations (Const aString : String; aResults : TStrings);
  Procedure _Permutation(Const aString, aResult : String; anIndex : Integer; aUsedChars : TCharSet);
  Var
    i : Integer;
  Begin
    For i:=1 To Length (aString) Do
      If Not (aString[i] In aUsedChars) Then
  If anIndex = Length (aString) Then
    aResults.Add(aResult+aString[i])
  Else
    _Permutation (aString, aResult + aString[i], anIndex + 1, aUsedChars + [aString[i]]);
  End;
Begin
  _Permutation (aString, '', 1, []);
End;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  Permutations(Edit1.Text, Memo1.Lines);
end;

TMemo, TEdit & TButton auf die Form, dem TButton die Ereignisbehandlung Button1Click zuweisen, fertig. :wink:

Und jetzt versuch es zu verstehen :!: Wenn Du fragen hast: immer her damit!

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 18:14 
hoffe das klappt


Zuletzt bearbeitet von 110022 am Mi 12.12.07 18:15, insgesamt 1-mal bearbeitet
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 18:14 
Danke @ Dunkel. :D
klappt super.
deinen tipp werde ich mir zu herzen nehmen.
ich guck mal ob ichs verstehe.

Nochmal Danke und an den rest auch
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 18:19 
noch ne letzte frage :
wie kann man die entstandenen Permutationen zählen?
und wie bekomme ich es hin das eine zahl mehrmal vorkommen kann?
Fiete
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 621
Erhaltene Danke: 371

W7
Delphi 6 pro
BeitragVerfasst: Mi 12.12.07 18:40 
Versuchs mal mit dem Turmproblem. (Schachfigur)

Gruß
Fiete

_________________
Fietes Gesetz: use your brain (THINK)
Dragonclaw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 196

Windows Vista
Delphi 7 Prof.
BeitragVerfasst: Mi 12.12.07 18:45 
Der Code ist von Dunkel, siehe oben. Die markieren Zeilen sind die änderungen.

Du musst nur noch unter var einen Interger der Counter heißt deklarieren.

ausblenden 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:
type
  TCharSet = set of char;

Procedure Permutations (Const aString : String; aResults : TStrings);
  Procedure _Permutation(Const aString, aResult : String; anIndex : Integer; aUsedChars : TCharSet);
  Var
    i : Integer;
  Begin
    For i:=1 To Length (aString) Do
      If Not (aString[i] In aUsedChars) Then
  If anIndex = Length (aString) Then
    begin
      aResults.Add(aResult+aString[i])
      Inc(Counter);
    end;

  Else
    _Permutation (aString, aResult + aString[i], anIndex + 1, aUsedChars + [aString[i]]);
  End;
Begin
  _Permutation (aString, '', 1, []);
End;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  Counter := 0;
  Permutations(Edit1.Text, Memo1.Lines);
  Memo1.Lines.add(IntToStr(Counter));
end;



Was meinst du mit das eine Zahl mehr mal vorkommen kann? Der Code sollte eigentlich alle Permutationen erzeugen. Wenn du aber z. B. die 5 mehrmals in der Permutation haben willst wird das ganze komplizierter.
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 18:50 
kombination: 1234555
so das meine ich
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Mi 12.12.07 18:54 
user profile iconDragonclaw hat folgendes geschrieben:
Der Code ist von Dunkel{ ... }

Nee, der code ist eigentlich von user profile iconalzaimar, siehe noch weiter oben

Warum eine extra Integer-Variable deklarieren und hochzählen wenn doch schon alles im Memo, bzw. in aResults : TStrings steht?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  Permutations(Edit1.Text, Memo1.Lines);
  Memo1.Lines.add('Anzahl der möglichen Permutationen: '+IntToStr(Memo1.Lines.Count));
end;

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Mi 12.12.07 19:07 
das Programm macht aber nix wenn ich 1234555 eingebe
wie kann man das beheben?

----------

wie bekomme ich das hin , dass es funktioniert wenn zahlen oder buchstaben bei der zahlen eingabe gleich sind?

----------

wenns keiner versteht hier mal ein bild

Moderiert von user profile iconNarses: Beiträge zusammengefasst.
Einloggen, um Attachments anzusehen!
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Do 13.12.07 16:17 
Na gut, ein letztes mal Copy&Paste-Kompatibles; aber auch nur, weil Rekursion für einen Anfänger nicht so einfach sind. :wink:
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:
procedure PermutationEx(const aString: string; aResults: TStringList);
  procedure _Permutation(aResult: string; index: integer);
    procedure ExChange(var aString: string; i1,i2: integer); {vertauscht Chars im String}
    var
      a: char;
    begin
      a:= aString[i2];
      aString[i2]:= aString[i1];
      aString[i1]:= a;
    end;
  var
    i: Integer;
  begin
    for i := 1 to Length(aResult)-1 do
      begin
        ExChange(aResult, i, i+1);    // nebeneinanderliegende Chars vertauschen
        aResults.Add(aResult);        // und zur TStringList hinzufügen
      end;
    if index < Length(aResult) then   // wenn wir noch nicht alle möglichen Chars vertauscht haben
      _Permutation(aResult, index+1); // nochmal das ganze, mit inkrementierten Index
  end;
begin
  aResults.Sorted:= True; // macht das alles etwas einfacher ...
  aResults.Duplicates:= dupIgnore; // weil Duplikate so automatisch nicht zugelassen werden
  _Permutation(aString, 1);  // do it, mit Index 1
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  aPermutations: TStringList;
  i: word;
begin
  aPermutations:= TStringList.Create;
  PermutationEx(Edit1.Text, aPermutations);
  Memo1.Lines.Clear;
  for i := 0 to aPermutations.Count-1 do
    Memo1.Lines.Add(aPermutations[i]);
  aPermutations.Free;
end;


Und nochmal: bitte nicht nur ungelesen in Dein Programm übernehmen, "Verstehen" heißt das Zauberwort! :wink:

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Do 13.12.07 16:24 
danke klappt wunderbar
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: Do 13.12.07 16:39 
user profile icon110022 hat folgendes geschrieben:
danke klappt wunderbar

Ja? :shock: Wenn Du meinst...
Da fehlen noch jede Menge Permutations-Möglichkeiten. Das kommt davon, wenn man das "mal eben" tippselt und nur unzureichend mit "abc" & "123" testet.

Aber da Du ja jetzt den Sourcecode verstehst, kannst Du denn Fehler ja selber beheben. 8)

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Do 13.12.07 16:44 
wie füge ich den rest denn ein??
und was soll ich einfügen?
110022 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 287

XP SP2
Delphi 7
BeitragVerfasst: Fr 14.12.07 21:42 
bei mir siehts jetzt so aus:
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:
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure PermutationEx(const aString: string; aResults: TStringList);
  procedure _Permutation(aResult: string; index: integer);
    procedure ExChange(var aString: string; i1,i2: integer); {vertauscht Chars im String}
    var
      a: char;
    begin
      a:= aString[i2];
      aString[i2]:= aString[i1];
      aString[i1]:= a;
    end;
  var
    i, j,p,u: Integer;  // j HINZUGEFÜGT
  begin
    for i := 1 to Length(aResult) do
      for j := 1 to Length(aResult)  do  // 2te Schleife HINZUGEFÜGT
       for p := 1 to Length(aResult)  do
        for u := 1 to Length(aResult)  do
        begin
          ExChange(aResult, i, j);    // nebeneinanderliegende Chars vertauschen
          aResults.Add(aResult);
           ExChange(aResult, i, p);
           aResults.Add(aResult);
            ExChange(aResult, i, u);
          aResults.Add(aResult);        // und zur TStringList hinzufügen
        end;
    ExChange(aResult, Length(aResult)-1, Length(aResult));  // Tauschen der letzten 2 Chars HINZUGEFÜGT
    aResults.Add(aResult);  // Hinzufügen HINZUGEFÜGT
    if index < (Length(aResult)*Length(aResult)) then // * Length(aResult)) then   // wenn wir noch nicht alle möglichen Chars vertauscht haben
      _Permutation(aResult, index+1); // nochmal das ganze, mit inkrementierten Index
  end;
begin
  aResults.Sorted:= True; // macht das alles etwas einfacher ...
  aResults.Duplicates:= dupIgnore; // weil Duplikate so automatisch nicht zugelassen werden
  _Permutation(aString, 1);  // do it, mit Index 1
end;
procedure TForm1.Button1Click(Sender: TObject);
var
  aPermutations: TStringList;
  i: word;
begin
  aPermutations:= TStringList.Create;
  PermutationEx(Edit1.Text, aPermutations);
  Memo1.Lines.Clear;
  for i := 0 to aPermutations.Count-1 do
    Memo1.Lines.Add(aPermutations[i]);
  aPermutations.Free;
  Memo1.Lines.add('Anzahl der möglichen Permutationen: '+IntToStr(Memo1.Lines.Count));
end;
end.


aber das is von vorne bis hinten falsch außer das was von dunkel ist.
Aber wie gehts richtig???