Thue-Morse: Difference between revisions

m
Fix pascal version to run in delphi
m (→‎{{header|Phix}}: added syntax colouring the hard way)
m (Fix pascal version to run in delphi)
Line 1,256:
=={{header|Pascal}}==
{{works with|Free Pascal}}
{{works with|Delphi}}
Like the C++ Version [[http://rosettacode.org/wiki/Thue-Morse#C.2B.2B]] the lenght of the sequence is given in advance.
<lang pascal>Program ThueMorse;
 
function fThueMorse(maxLen: NativeInt):AnsiString;
//double by appending the flipped original 0 -> 1;1 -> 0
Line 1,265 ⟶ 1,266:
const
cVal0 = '^';cVal1 = 'v';// cVal0 = '0';cVal1 = '1';
 
var
pOrg,
pRpl : pCharpansiChar;
i,k,ml : NativeUInt;//MaxLen: NativeInt
Begin
Line 1,278 ⟶ 1,279:
//setlength only one time
setlength(result,Maxlen);
 
pOrg := @result[1];
pOrg[0] := cVal0;
IF maxlen = 1 then
EXIT;
 
pRpl := pOrg;
inc(pRpl);
Line 1,291 ⟶ 1,292:
i := 0;
repeat
pRpl[0] := chransichar(Ord(cVal0)+Ord(cVal1)-Ord(pOrg[i]));
inc(pRpl);
inc(i);
Line 1,302 ⟶ 1,303:
IF k > 0 then
repeat
pRpl[0] := chransichar(Ord(cVal0)+Ord(cVal1)-Ord(pOrg[i]));
inc(pRpl);
inc(i)
Line 1,314 ⟶ 1,315:
writeln(i:3,' ',fThueMorse(i));
fThueMorse(1 shl 30);
{$IFNDEF LINUX}readln;{$ENDIF}
end.</lang>
{{Output}}<pre>Compile with /usr/lib/fpc/3.0.1/ppc386 "ThueMorse.pas" -al -XX -Xs -O4 -MDelphi
478

edits