Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. | /
  2. |/ / /
  3. | /
  4. |
  5.  
  6. procedure TForm1.Button1Click(Sender: TObject);
  7. label
  8. 0,1;
  9. const
  10. prLen0=4; // Length of Progression -1
  11. seqLen0=4199; // Length of Sequence -1
  12. var
  13. prLen,l:Byte;
  14. i,j,k,d,d0,imin,seqLen:Word;
  15. l1:Integer;
  16. b:array[0..seqLen0-1]of Byte; // b[i]=a[i+1]-a[i]
  17. SOut:String;
  18. begin
  19. Memo1.Lines.Add('Seq.Length='+IntToStr(seqLen0+1));
  20. Memo1.Lines.Add('Prog.Length='+IntToStr(prLen0+1));
  21. FillChar(b,SizeOf(b),0);
  22. imin:=seqLen0-prLen0;
  23. prLen:=prLen0-1;
  24. seqLen:=seqLen0-1;
  25. repeat
  26. for i:=imin downto 0 do for j:=1 to (seqLen0-i) div prLen0 do begin
  27. d0:=b[i];for k:=i+1 to i+j-1 do inc(d0,b[k]);
  28. for l:=1 to prLen do begin
  29. d:=b[i+j*l];for k:=i+j*l+1 to i+j*(l+1)-1 do inc(d,b[k]);
  30. if d<>d0 then goto 1; // Search for next progression
  31. end;
  32. // Progression found, go to the next sequence
  33. for l1:=i-1 downto 0 do b[l1]:=0;
  34. l1:=i; while b[l1]=1 do begin b[l1]:=0;inc(l1) end;
  35. b[l1]:=1;
  36. goto 0;
  37. 1:
  38. end;
  39. // No progessions found
  40. SOut:='';
  41. for i:=seqLen downto 0 do if b[i]=1 then SOut:=SOut+'x' else SOut:=SOut+'o';
  42. Memo1.Lines.Add(SOut);
  43. Break;
  44. 0:
  45. until b[seqLen]=1; // by the symmetry , without loss of genearily we can assume b[0]=0
  46. Memo1.Lines.Add('Done');
  47. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement