Created
May 1, 2012 13:52
-
-
Save jermenkoo/2568062 to your computer and use it in GitHub Desktop.
Bulls & Cows by jermenkoo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit Unit1; | |
interface | |
uses | |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | |
Dialogs, StdCtrls; | |
type | |
TForm1 = class(TForm) | |
Memo1: TMemo; | |
Button1: TButton; | |
procedure FormCreate(Sender: TObject); | |
procedure Button1Click(Sender: TObject); | |
private | |
{ Private declarations } | |
public | |
{ Public declarations } | |
end; | |
var | |
Form1: TForm1; | |
implementation | |
{$R *.dfm} | |
var N : integer = 4; //pocet cifier | |
pocB, pocK : integer; //pocet bykov, krav | |
tajne : string = ''; //tajne cislo :) | |
count : integer; //Memo1.Lines.Count | |
procedure Hodnot(a, b : string; var byk, krava : integer); | |
var i, j : integer; | |
begin | |
byk := 0; | |
krava := 0; | |
for i := 1 to N do | |
if a[i] = b[i] then begin | |
inc(byk); | |
a[i] := 'a'; | |
b[i] := 'b'; | |
end; | |
for i := 1 to N do | |
for j := 1 to N do | |
if a[i] = b[j] then begin | |
inc(krava); | |
a[i] := 'a'; | |
b[i] := 'b'; | |
end; | |
end; | |
procedure TForm1.FormCreate(Sender: TObject); | |
var i : integer; | |
begin | |
Randomize; | |
for i := 1 to N do tajne := tajne + chr(random(9) + 49); | |
end; | |
procedure TForm1.Button1Click(Sender: TObject); | |
begin | |
count := Memo1.Lines.Count; | |
Hodnot(tajne, Memo1.Lines[count-1], pocB, pocK); | |
Memo1.Lines[count-1] := Memo1.Lines[count-1] + | |
' => ' + IntToStr(pocB) + 'B ' + IntToStr(pocK) + 'K'; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment