-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
F# hw 6.2 #13
Open
uncerso
wants to merge
11
commits into
master
Choose a base branch
from
f#_6.2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
F# hw 6.2 #13
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
368ad7b
Updated hw5
uncerso 0e9040a
WorkFlow
uncerso 1f163ae
network virus
uncerso 6032793
Task 3
uncerso 8ac339d
Async programming
uncerso 76c28d9
New task3
uncerso 49db20f
hw 6.2
uncerso c5f98e0
beta
uncerso 388b63b
Pre-release
uncerso 7ba4924
rm .suo
uncerso 913b212
pre-release
uncerso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,5 @@ run | |
.gcda | ||
.gcno | ||
|
||
FirstSteps/FirstSteps/bin/* | ||
FirstSteps/FirstSteps/obj/* | ||
**/bin/* | ||
**/obj/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="prog.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="FsCheck" Version="3.0.0-alpha3" /> | ||
<PackageReference Include="FsUnit" Version="3.1.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\lastSteps\lastSteps.fsproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Update="FSharp.Core" Version="4.3.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
open NUnit.Framework | ||
open FsUnit | ||
open hw | ||
|
||
let rec permutations list taken = | ||
seq { if Set.count taken = List.length list then yield [] else | ||
for l in list do | ||
if not (Set.contains l taken) then | ||
for perm in permutations list (Set.add l taken) do | ||
yield l::perm } | ||
|
||
let testIterator (x:List<int>) = | ||
let bst = BinaryTree<int>() | ||
for t in x do bst.Insert t; | ||
let mutable t = 0 | ||
for it in bst do | ||
it |> should equal t | ||
t <- t + 1; | ||
t |> should equal x.Length | ||
|
||
let testFind (x:List<int>) = | ||
let bst = BinaryTree<int>() | ||
for t in x do bst.Insert t; | ||
for i in -1..x.Length do | ||
(bst.At i ) |> should equal (not (i < 0 || i >= x.Length)) | ||
|
||
let testErase (x:List<int>) = | ||
for k in -1..x.Length do | ||
let bst = BinaryTree<int>() | ||
for t in x do bst.Insert t | ||
bst.Erase k | ||
let mutable t = 0; | ||
for p in bst do | ||
if t = k then t <- t + 1 | ||
t |> should equal p | ||
t <- t + 1 | ||
|
||
let randomTest (n) = | ||
let bst = BinaryTree<int>() | ||
let mutable st = Set.empty | ||
for i in 1..n do | ||
let el = rnd.Next() | ||
if rnd.Next() % 2 = 0 then | ||
if Set.contains el st then | ||
bst.At el |> should be True | ||
else | ||
bst.At el |> should be False | ||
bst.Insert el | ||
bst.At el |> should be True | ||
else | ||
let sz = bst.Size() | ||
if Set.contains el st then | ||
bst.At el |> should be True | ||
bst.Erase el | ||
bst.At el |> should be False | ||
bst.Size() |> should equal (sz - 1) | ||
else | ||
bst.At el |> should be False | ||
bst.Erase el | ||
bst.At el |> should be False | ||
bst.Size() |> should equal sz | ||
|
||
[<Test>] | ||
let ``test`` () = | ||
let n = 8 | ||
for x in permutations (List.init n id) Set.empty do | ||
testIterator x | ||
|
||
for x in permutations (List.init n id) Set.empty do | ||
testFind x | ||
|
||
for x in permutations (List.init (n - 1) id) Set.empty do | ||
testErase x | ||
for i in 1..100 do | ||
randomTest(100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27130.2027 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "lastSteps", "lastSteps\lastSteps.fsproj", "{0D1A3D07-30A9-421F-9367-6AD852CF97D5}" | ||
EndProject | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Tests", "Tests\Tests.fsproj", "{DDA2F794-D1CC-4046-9237-3B2C1F7D7867}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{0D1A3D07-30A9-421F-9367-6AD852CF97D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{0D1A3D07-30A9-421F-9367-6AD852CF97D5}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{0D1A3D07-30A9-421F-9367-6AD852CF97D5}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{0D1A3D07-30A9-421F-9367-6AD852CF97D5}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DDA2F794-D1CC-4046-9237-3B2C1F7D7867}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DDA2F794-D1CC-4046-9237-3B2C1F7D7867}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DDA2F794-D1CC-4046-9237-3B2C1F7D7867}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DDA2F794-D1CC-4046-9237-3B2C1F7D7867}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {1507EBBF-D6FE-4AEA-B727-11CB0FEC1811} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="prog.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Update="FSharp.Core" Version="4.3.4" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Learn more about F# at http://fsharp.org | ||
module hw | ||
|
||
open System | ||
open System.Collections | ||
open System.Collections.Generic | ||
open System.IO | ||
|
||
let read = bigint.Parse << Console.ReadLine | ||
let readInt = Int32.Parse << Console.ReadLine | ||
let readStr = Console.ReadLine | ||
let rnd = System.Random() | ||
|
||
type Tree<'T> = | ||
| Tree of 'T * Tree<'T> * Tree<'T> | ||
| Leaf | ||
|
||
/// <summary> | ||
/// Implementation of simple binary tree | ||
/// </summary> | ||
type BinaryTree<'T when 'T : comparison>() = | ||
let mutable root = Leaf | ||
let mutable size = 0 | ||
|
||
let iterator () = | ||
let rec handle (node : Tree<'T>) = | ||
seq { | ||
match node with | ||
| Tree(curValue, left, right) -> | ||
yield! handle left | ||
yield curValue | ||
yield! handle right | ||
| Leaf -> yield! Seq.empty | ||
} | ||
handle root | ||
|
||
interface IEnumerable<'T> with | ||
|
||
member this.GetEnumerator(): IEnumerator<'T> = | ||
iterator().GetEnumerator() | ||
|
||
member this.GetEnumerator(): IEnumerator = | ||
iterator().GetEnumerator() :> IEnumerator | ||
|
||
member v.Empty () = size = 0 | ||
|
||
member v.Size () = size | ||
|
||
/// <summary> | ||
/// Inserts an element into the tree. | ||
/// </summary> | ||
member v.Insert (value : 'T) = | ||
let rec handle (value : 'T) (node : Tree<'T>) = | ||
match node with | ||
| Leaf -> Tree(value, Leaf, Leaf) | ||
| Tree(curValue, left, right) when value < curValue -> Tree(curValue, handle value left, right) | ||
| Tree(curValue, left, right) -> Tree(curValue, left, handle value right) | ||
root <- handle value root | ||
size <- size + 1 | ||
|
||
/// <summary> | ||
/// Removes an element from the tree, if exists. | ||
/// </summary> | ||
member v.Erase (value : 'T) = | ||
let rec cutLeft node = | ||
match node with | ||
| Tree(value, Leaf, right) -> (value, right) | ||
| Tree(value, left, right) -> | ||
let (cutted, newChild) = cutLeft left | ||
(cutted, Tree(value, newChild, right)) | ||
|
||
let rec handle value node = | ||
match node with | ||
| Leaf -> | ||
size <- size + 1; | ||
Leaf | ||
| Tree(curValue, left, right) when value < curValue -> Tree(curValue, handle value left, right) | ||
| Tree(curValue, left, right) when curValue < value -> Tree(curValue, left, handle value right) | ||
| Tree(_, left, right) -> | ||
if left = Leaf then right | ||
elif right = Leaf then left | ||
else | ||
let (cutted, newChild) = cutLeft right | ||
Tree(cutted, left, newChild) | ||
|
||
root <- handle value root | ||
size <- size - 1 | ||
|
||
/// <summary> | ||
/// Checks for the presence of an element in the tree. | ||
/// </summary> | ||
member v.At (value : 'T) = | ||
let rec handle (value : 'T) (node : Tree<'T>) = | ||
match node with | ||
| Tree(curValue, left, right) when value < curValue -> handle value left | ||
| Tree(curValue, left, right) when curValue < value -> handle value right | ||
| Leaf -> false | ||
| _ -> true | ||
handle value root | ||
|
||
(*_*) | ||
[<EntryPoint>] | ||
let main argv = | ||
|
||
0 // return an integer exit code |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Один большой тест не прокатит