s='s=%r;print s%%s';print s%sThis wikipedia article on Quines is a very good place to learn how these things work
s='s=%r;print s%%s';print s%s
qsort = lambda seq: [] if not seq else qsort(filter(lambda n: n<=seq[0], seq[1:]))+[seq[0]]+qsort(filter(lambda n: n>seq[0], seq[1:]))
triangle = lambda n: n*(n+1)/2
factorial = lambda n: 1 if n<2 else n*factorial(n-1)3) Get odd numbers
odds = lambda n: [k for k in range(1,n,2)]4) Test whether a number is prime
is_prime = lambda n: False if n<2 else (0 not in [n%k for k in range(2,int(n**.5)+1)])A number is prime when it has no factor other than 1 and itself. To determine whether the number is a prime, we need to check that it doesn't leave a reminder of 0 when divided by each number in the range of [2..square root of the number].
sieve = lambda n: [k for k in range(2,n+1) if (0 not in [k%i for i in range(2,int(k**.5)+1)])]It could also be written as:
is_prime = lambda n: False if n<2 else (0 not in [n%k for k in range(2,int(n**.5)+1)])
sieve = lambda n: [k for k in range(2,n+1) if is_prime(k)]
Step 2 (Loading the HTML file)implementation
{$R *.dfm}
uses
mshtml;
procedure TForm1.Button1Click(Sender: TObject);To load the file I used WebBrowser1.Navigate(OpenDialog1.FileName);
var
doc: IHTMLDocument2;
begin
if not OpenDialog1.Execute then
Exit;
WebBrowser1.Navigate(OpenDialog1.FileName);
doc:= WebBrowser1.Document as IHTMLDocument2;
while doc.readyState <> 'complete' do Application.ProcessMessages;
Scintilla1.Lines.Text:= doc.body.innerHTML;
end;
procedure TForm1.Button2Click(Sender: TObject);Now you can test the source code editor. But get the WYSISWYG part we got to the Next step…
var
doc: IHTMLDocument2;
begin
doc:= WebBrowser1.Document as IHTMLDocument2;
doc.body.innerHTML:= Scintilla1.Lines.Text;
end;
OK, That's it! We get this:procedure TForm1.Button3Click(Sender: TObject);
var
doc: IHTMLDocument2;
begin
doc:= WebBrowser1.Document as IHTMLDocument2;
doc.designMode:= 'on';
end;