Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions F#/Primes.Test/Primes.Test.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
<GenerateProgramFile>true</GenerateProgramFile>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<Compile Include="PrimesTest.fs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="FsUnit" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.0.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Primes\Primes.fsproj" />
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions F#/Primes.Test/PrimesTest.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Primes.Test

open NUnit.Framework
open FsUnit

[<Test>]
let testStart () =
primes |> Seq.take 5 |> Seq.toList |> should equal [ 2; 3; 5; 7; 11 ]
12 changes: 12 additions & 0 deletions F#/Primes/Primes.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Primes

/// <summary>
/// Generates infinite sequence of prime numbers
/// </summary>
let primes =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот тут хоть комментарии напишите :)

let isPrime n =
let sequence = { 2 .. (n |> float |> sqrt |> int) }
Seq.forall (fun x -> n % x <> 0) sequence

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Искать делители до самого числа — дело довольно безнадёжное, наверняка можно быстрее


Seq.initInfinite id |> Seq.filter (fun x -> x >= 2) |> Seq.filter isPrime

12 changes: 12 additions & 0 deletions F#/Primes/Primes.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<Compile Include="Primes.fs" />
</ItemGroup>

</Project>
14 changes: 12 additions & 2 deletions F#/forSpbu.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PriorityQueue", "PriorityQu
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PriorityQueue.Test", "PriorityQueue.Test\PriorityQueue.Test.fsproj", "{89A935E8-B5F3-435D-ACC3-A99DD7C66178}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "07.03", "07.03", "{5CA9053B-DE9B-4824-9F19-AEB464E3B9D8}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Homework1", "Homework1\Homework1.fsproj", "{04B15EE4-079A-42ED-ACC8-E2DCD25281C6}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Primes", "Primes\Primes.fsproj", "{08A49E6C-ED35-45C3-ABC1-F4CBCA608AD4}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Primes.Test", "Primes.Test\Primes.Test.fsproj", "{14716888-914A-477A-A0B4-654AF7483B86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -58,6 +60,14 @@ Global
{89A935E8-B5F3-435D-ACC3-A99DD7C66178}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89A935E8-B5F3-435D-ACC3-A99DD7C66178}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89A935E8-B5F3-435D-ACC3-A99DD7C66178}.Release|Any CPU.Build.0 = Release|Any CPU
{08A49E6C-ED35-45C3-ABC1-F4CBCA608AD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08A49E6C-ED35-45C3-ABC1-F4CBCA608AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08A49E6C-ED35-45C3-ABC1-F4CBCA608AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08A49E6C-ED35-45C3-ABC1-F4CBCA608AD4}.Release|Any CPU.Build.0 = Release|Any CPU
{14716888-914A-477A-A0B4-654AF7483B86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14716888-914A-477A-A0B4-654AF7483B86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14716888-914A-477A-A0B4-654AF7483B86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14716888-914A-477A-A0B4-654AF7483B86}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{7937CDA8-8285-4E23-AD1A-FC0F04FEEFE6} = {91E3BDA2-0836-46C2-95F0-02513FD7F13F}
Expand Down