AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

LottoTippErstellen

Ein Thema von YXCVBNM1 · begonnen am 1. Sep 2011 · letzter Beitrag vom 2. Sep 2011
 
Bjoerk

Registriert seit: 28. Feb 2011
Ort: Mannheim
1.384 Beiträge
 
Delphi 10.4 Sydney
 
#9

AW: LottoTippErstellen

  Alt 2. Sep 2011, 01:19
War ein Indexfehler und Sortieren hat auch gefehlt. Die Lösung mit dem repeat/until ist übrigens nicht besonders schön, aber das soll jetzt erst mal egal sein.

Delphi-Quellcode:
unit uLotto;

interface

type
  TLotto = class(TObject)
  private
    Tipp: array of array of integer;
  public
    procedure LottoTippErstellen(Anzahl: integer);
  end;

implementation

procedure TLotto.LottoTippErstellen(Anzahl: integer);
const
  N = 6;
var
  I, J, K, T: integer;
  Result: boolean;
begin
  SetLength(Tipp, Anzahl, N);
  for K:= 0 to Anzahl-1 do
    for I:= 0 to N-1 do
      repeat
        Result:= true;
        Tipp[K, I]:= Random(49)+1;
        for J:= 0 to I-1 do
          if Tipp[K, I] = Tipp[K, J] then Result:= false;
      until Result;
  for K:= 0 to Anzahl-1 do
    for I:= 0 to N-2 do
       for J:= I+1 to N-1 do
       begin
         if Tipp[K, I] > Tipp[K, J] then
         begin
           T:= Tipp[K, I];
           Tipp[K, I]:= Tipp[K, J];
           Tipp[K, J]:= T;
         end;
       end;
end;

end.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:57 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz