Two identical strings: Difference between revisions

no edit summary
m (RPL: optimized version)
No edit summary
Line 1,714:
957: 1110111101
990: 1111011110</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
function IntToBinStr(IValue: Int64) : string;
{Convert integer to binary string, with no leading zero}
var I: integer;
begin
Result:='';
I:=IntPower2(32-1);
while I <> 0 do
begin
if (IValue and I)<>0 then Result:=Result + '1'
else if Length(Result)>0 then Result:=Result + '0';
I:=I shr 1;
end;
if Result='' then Result:='0';
end;
 
 
procedure IdenticalBinaryStrings(Memo: TMemo);
var S,S1,S2: string;
var Len,I: integer;
begin
for I:=2 to 1000-1 do
begin
{Get binary String}
S:=IntToBinStr(I);
{Only look at string evenly divisible by 2}
Len:=Length(S);
if (Len and 1)=0 then
begin
{Split string into equal pieces}
S1:=LeftStr(S,Len div 2);
S2:=RightStr(S,Len div 2);
{Each half should be the same}
if S1=S2 then Memo.Lines.Add(IntToStr(I)+': '+S);
end;
end;
end;
 
 
 
</syntaxhighlight>
{{out}}
<pre>
3: 11
10: 1010
15: 1111
36: 100100
45: 101101
54: 110110
63: 111111
136: 10001000
153: 10011001
170: 10101010
187: 10111011
204: 11001100
221: 11011101
238: 11101110
255: 11111111
528: 1000010000
561: 1000110001
594: 1001010010
627: 1001110011
660: 1010010100
693: 1010110101
726: 1011010110
759: 1011110111
792: 1100011000
825: 1100111001
858: 1101011010
891: 1101111011
924: 1110011100
957: 1110111101
990: 1111011110
 
Elapsed Time: 58.641 ms.
 
</pre>
 
 
=={{header|Draco}}==
465

edits