ArfIsAToe

2T1V

Jan 7th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.48 KB | None | 0 0
  1. program s2t1v ;
  2. uses WinCrt ;
  3. var
  4.  csn,inn,tf : string;
  5. procedure randn(var csn : string);
  6.     var
  7.      vf : Boolean;
  8.      b,a : integer;
  9.     begin
  10.      repeat
  11.       str(random(8643)+1234,csn);
  12.         vf := true;
  13.         for a:=1 to 4 do
  14.          for b:=1 to 4 do
  15.           if (csn[a] = csn[b] ) and (a <> b ) then
  16.                 vf := false;
  17.      Until vf = true
  18.     End;
  19.     procedure inpn(var inn : string ; tries : integer);
  20.         var
  21.         a,b,n : integer;
  22.             vf : Boolean;
  23.         begin
  24.              repeat
  25.                 write(tries,'- N= ');
  26.                     readln(n);
  27.                  str(n,inn);
  28.                  vf := true;
  29.                  for a:=1 to 4 do
  30.                   for b:=1 to 4 do
  31.                      if (inn[a] = inn[b] ) and (a <> b ) then
  32.                          vf := false;
  33.              until (vf = true ) and ( (n>=1000) and (n <=9999) );
  34.         End;
  35.         procedure check(var tf : string ;inn,csn : string ) ;
  36.             var
  37.              a,b,t,v : integer ;
  38.             begin
  39.              t:=0;
  40.              v:=0;
  41.              for a:=1 to 4 do
  42.               for b:=1 to 4 do
  43.                  if (csn[a] = inn[b]) and (a = b )  then
  44.                   t:=t+1
  45.                  Else
  46.                   if (csn[a] = inn[b]) and (a <> b ) then
  47.                         v:=v+1;
  48.              tf := chr(ord('0')+t)+'T'+chr(ord('0')+v)+'V' ;
  49.             end;
  50.             procedure aff(tf,inn,csn : string);
  51.              var
  52.                 tries : integer;
  53.              begin
  54.                  tries := 0 ;
  55.                  repeat
  56.                       tries:= tries+1;
  57.                         inpn(inn,tries);
  58.                         check(tf,inn,csn);
  59.                           if tf[1] <> '4' then
  60.                              writeln(tf);
  61.                  Until tf[1] = '4';
  62.                  writeln('congrats you found ',csn,' with ',tries,' attempts ');
  63.              End;
  64. begin
  65.  Randomize;
  66.  randn(csn);
  67.  writeln('csn',csn);
  68.  aff(tf,inn,csn);
  69.  
  70.  
  71. End.
Advertisement
Add Comment
Please, Sign In to add comment