Исправил пару примеров

This commit is contained in:
Mikhalkovich Stanislav 2020-07-26 13:07:35 +03:00
parent bdb87cb824
commit cf6e4ba9bd
4 changed files with 27 additions and 12 deletions

View file

@ -1,26 +1,24 @@
// "Решето Эратосфена" - вычисление простых чисел
const n = 100000;
var primes: set of integer;
begin
primes := [2..n];
var primes := HSet(2..n);
for var i:=2 to round(sqrt(n)) do
for var i:=2 to Round(Sqrt(n)) do
begin
if not (i in primes) then
continue;
var x := i*i;
while x<=n do
begin
Exclude(primes,x);
primes -= x;
x += i;
end;
end;
writeln('Простые числа < ',n,':');
writeln(primes);
writeln;
writeln('Время вычисления: ',Milliseconds/1000);
Writeln('Простые числа < ',n,':');
Writeln(primes);
Writeln;
Writeln('Время вычисления: ',Milliseconds/1000);
end.

View file

@ -47,7 +47,7 @@ begin
for var x := 0 to dimx-1 do
begin
var c := f.ReadChar;
a[y,x]:= c='*' ? 1 : 0;
a[y,x]:= if c='*' then 1 else 0;
end;
f.Readln
end;

View file

@ -0,0 +1,17 @@
// Быстрая сортировка Ч. Хоара
// Неэффективный алгоритм, иллюстрирующмй суть
function QS(a: array of integer): array of integer;
begin
if a.Length < 2 then
Result := a
else Result := QS(a[1:].Where(y->y<=a[0]).ToArray) + |a[0]| + QS(a[1:].Where(y->y>a[0]).ToArray)
//QS(ArrGen(a[1:],y->y<=a[0]))
//QS(|y:y in a[1:] where y<=a[0]|)
end;
begin
var a := ArrRandom(20);
a.Println;
var b := QS(a);
b.Println;
end.

View file

@ -78,7 +78,7 @@ namespace PascalABCCompiler.SyntaxTreeConverters
cv.ProcessNode(root);
cv.Output(@"Light1.txt");*/
try
/*try
{
root.visit(new SimplePrettyPrinterVisitor(@"d:\\zzz1.txt"));
}
@ -86,7 +86,7 @@ namespace PascalABCCompiler.SyntaxTreeConverters
{
System.IO.File.AppendAllText(@"d:\\zzz1.txt",e.Message);
}
}*/
#endif