From 64acde6460e9b0ec445cc3d45417d279b822227a Mon Sep 17 00:00:00 2001 From: Mikhalkovich Stanislav Date: Wed, 31 Jul 2024 18:21:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=B2?= =?UTF-8?q?=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D1=8B=D0=BC=20=D0=BD=D0=B5?= =?UTF-8?q?=D1=8F=D0=B2=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=B3=D0=BE=20=D1=82=D0=B8=D0=BF=D0=B0=20?= =?UTF-8?q?=D0=BA=20array=20of=20T=20(=D0=BF=D1=80=D0=B8=20=D0=BE=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=B0=D0=BD=D0=B8=D0=B8=20=D0=BE=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=B0=20=D0=B2=20=D0=B2=D0=B8=D0=B4?= =?UTF-8?q?=D0=B5=20=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit School - IsPrime(n) --- Configuration/GlobalAssemblyInfo.cs | 2 +- Configuration/Version.defs | 4 +- .../WhatsNew/3_9_1/ZipCartesianFuncs.pas | 3 + Release/pabcversion.txt | 2 +- ReleaseGenerators/PascalABCNET_version.nsh | 2 +- TestSuite/CompilationSamples/School.pas | 84 ++++++++++--------- TreeConverter/TreeRealization/types.cs | 15 ++++ bin/Lib/School.pas | 84 ++++++++++--------- 8 files changed, 113 insertions(+), 83 deletions(-) diff --git a/Configuration/GlobalAssemblyInfo.cs b/Configuration/GlobalAssemblyInfo.cs index 4e05f639b..819c8725e 100644 --- a/Configuration/GlobalAssemblyInfo.cs +++ b/Configuration/GlobalAssemblyInfo.cs @@ -15,7 +15,7 @@ internal static class RevisionClass public const string Major = "3"; public const string Minor = "9"; public const string Build = "0"; - public const string Revision = "3520"; + public const string Revision = "3521"; public const string MainVersion = Major + "." + Minor; public const string FullVersion = Major + "." + Minor + "." + Build + "." + Revision; diff --git a/Configuration/Version.defs b/Configuration/Version.defs index bcf15dc1f..b02447251 100644 --- a/Configuration/Version.defs +++ b/Configuration/Version.defs @@ -1,4 +1,4 @@ -%COREVERSION%=0 -%REVISION%=3520 %MINOR%=9 +%REVISION%=3521 +%COREVERSION%=0 %MAJOR%=3 diff --git a/InstallerSamples/WhatsNew/3_9_1/ZipCartesianFuncs.pas b/InstallerSamples/WhatsNew/3_9_1/ZipCartesianFuncs.pas index 166104f64..5ab1a9ea2 100644 --- a/InstallerSamples/WhatsNew/3_9_1/ZipCartesianFuncs.pas +++ b/InstallerSamples/WhatsNew/3_9_1/ZipCartesianFuncs.pas @@ -8,4 +8,7 @@ Cartesian(1..4,3..5,(x,y) -> x*y).Println; Cartesian(1..2,4..5,6..7).Println; Cartesian(1..2,4..5,6..7,(x,y,z) -> x*y*z).Println; + + foreach var (a,b) in Cartesian(1..2,3..5) do + Print($'{a}+{b}') end. \ No newline at end of file diff --git a/Release/pabcversion.txt b/Release/pabcversion.txt index 5d669df3d..73d44ffea 100644 --- a/Release/pabcversion.txt +++ b/Release/pabcversion.txt @@ -1 +1 @@ -3.9.0.3520 +3.9.0.3521 diff --git a/ReleaseGenerators/PascalABCNET_version.nsh b/ReleaseGenerators/PascalABCNET_version.nsh index 8865837f5..578847a42 100644 --- a/ReleaseGenerators/PascalABCNET_version.nsh +++ b/ReleaseGenerators/PascalABCNET_version.nsh @@ -1 +1 @@ -!define VERSION '3.9.0.3520' +!define VERSION '3.9.0.3521' diff --git a/TestSuite/CompilationSamples/School.pas b/TestSuite/CompilationSamples/School.pas index 40952558e..ba0409884 100644 --- a/TestSuite/CompilationSamples/School.pas +++ b/TestSuite/CompilationSamples/School.pas @@ -1,4 +1,4 @@ -/// Учебный модуль, реализующий базовые алгоритмы информатики (18.07.2024) +/// Учебный модуль, реализующий базовые алгоритмы информатики (31.07.2024) unit School; interface @@ -203,6 +203,9 @@ function НОДНОК(a, b: int64): (int64, int64); /// Разложение числа на простые множители function Factorize(n: integer): List; +/// возвращает True, если число n простое и False в противном случае +function IsPrime(n: integer): boolean; + /// Простые числа на интервале [2;n] function Primes(n: integer): List; @@ -705,6 +708,47 @@ Factorize(Self); {$region Primes} +// Внутреняя процедура для заполнения LPrimes +// Решето Эратосфена +procedure PrimesInternal; +begin + LPrimes := new List; + var Sieve := new boolean[ubPrimeDivs + 1]; + for var i := 2 to ubPrimeDivs do + if not Sieve[i] then + begin + LPrimes.Add(i); + var k := i; + while k <= ubPrimeDivs - i do + begin + k += i; + Sieve[k] := True + end + end +end; + +/// возвращает True, если число n простое и False в противном случае +function IsPrime(n: integer): boolean; +begin + if n < 2 then + Result := False + else + begin + Result := True; + foreach var prime in LPrimes do + if Sqr(prime) > n then + break + else if n mod prime = 0 then + begin + Result := False; + break + end + end +end; + +/// возвращает True, если число простое и False в противном случае +function IsPrime(Self: integer): boolean; extensionmethod := IsPrime(Self); + /// Простые числа на интервале [2;n] function Primes(n: integer): List; // Решето Эратосфена @@ -732,44 +776,6 @@ begin Result.Add(i) end; -// Внутреняя процедура для заполнения LPrimes -// Решето Эратосфена -procedure PrimesInternal; -begin - LPrimes := new List; - var Sieve := new boolean[ubPrimeDivs + 1]; - for var i := 2 to ubPrimeDivs do - if not Sieve[i] then - begin - LPrimes.Add(i); - var k := i; - while k <= ubPrimeDivs - i do - begin - k += i; - Sieve[k] := True - end - end -end; - -/// возвращает True, если число простое и False в противном случае -function IsPrime(Self: integer): boolean; extensionmethod; -begin - if Self < 2 then - Result := False - else - begin - Result := True; - foreach var prime in LPrimes do - if Sqr(prime) > Self then - break - else if Self mod prime = 0 then - begin - Result := False; - break - end - end -end; - /// Простые числа на интервале [m;n] function Primes(m, n: integer): List; begin diff --git a/TreeConverter/TreeRealization/types.cs b/TreeConverter/TreeRealization/types.cs index 2fe3a3dd7..e0d3aaf54 100644 --- a/TreeConverter/TreeRealization/types.cs +++ b/TreeConverter/TreeRealization/types.cs @@ -2459,6 +2459,21 @@ namespace PascalABCCompiler.TreeRealization { fn = fn.get_instance(ctn.instance_params, true, null); } + else if (ctn.type_special_kind == SemanticTree.type_special_kind.array_kind) + // надо ещё проверить rank - а его просто проверить только у compiled_type_node - как у common_type_node - не знаю + { + var rank = 1; + if (ctn is compiled_type_node comptn) + rank = comptn.rank; + else if (ctn is compiled_type_node commtn) + rank = commtn.rank; + if (rank == 1) + { + List instance_params = new List(); + instance_params.Add(ctn.element_type); + fn = fn.get_instance(instance_params, false, null); + } + } else if (fn.get_generic_params_list() != null && fn.get_generic_params_list().Count > 0) { if (ctn.IsPointer) diff --git a/bin/Lib/School.pas b/bin/Lib/School.pas index 40952558e..ba0409884 100644 --- a/bin/Lib/School.pas +++ b/bin/Lib/School.pas @@ -1,4 +1,4 @@ -/// Учебный модуль, реализующий базовые алгоритмы информатики (18.07.2024) +/// Учебный модуль, реализующий базовые алгоритмы информатики (31.07.2024) unit School; interface @@ -203,6 +203,9 @@ function НОДНОК(a, b: int64): (int64, int64); /// Разложение числа на простые множители function Factorize(n: integer): List; +/// возвращает True, если число n простое и False в противном случае +function IsPrime(n: integer): boolean; + /// Простые числа на интервале [2;n] function Primes(n: integer): List; @@ -705,6 +708,47 @@ Factorize(Self); {$region Primes} +// Внутреняя процедура для заполнения LPrimes +// Решето Эратосфена +procedure PrimesInternal; +begin + LPrimes := new List; + var Sieve := new boolean[ubPrimeDivs + 1]; + for var i := 2 to ubPrimeDivs do + if not Sieve[i] then + begin + LPrimes.Add(i); + var k := i; + while k <= ubPrimeDivs - i do + begin + k += i; + Sieve[k] := True + end + end +end; + +/// возвращает True, если число n простое и False в противном случае +function IsPrime(n: integer): boolean; +begin + if n < 2 then + Result := False + else + begin + Result := True; + foreach var prime in LPrimes do + if Sqr(prime) > n then + break + else if n mod prime = 0 then + begin + Result := False; + break + end + end +end; + +/// возвращает True, если число простое и False в противном случае +function IsPrime(Self: integer): boolean; extensionmethod := IsPrime(Self); + /// Простые числа на интервале [2;n] function Primes(n: integer): List; // Решето Эратосфена @@ -732,44 +776,6 @@ begin Result.Add(i) end; -// Внутреняя процедура для заполнения LPrimes -// Решето Эратосфена -procedure PrimesInternal; -begin - LPrimes := new List; - var Sieve := new boolean[ubPrimeDivs + 1]; - for var i := 2 to ubPrimeDivs do - if not Sieve[i] then - begin - LPrimes.Add(i); - var k := i; - while k <= ubPrimeDivs - i do - begin - k += i; - Sieve[k] := True - end - end -end; - -/// возвращает True, если число простое и False в противном случае -function IsPrime(Self: integer): boolean; extensionmethod; -begin - if Self < 2 then - Result := False - else - begin - Result := True; - foreach var prime in LPrimes do - if Sqr(prime) > Self then - break - else if Self mod prime = 0 then - begin - Result := False; - break - end - end -end; - /// Простые числа на интервале [m;n] function Primes(m, n: integer): List; begin