Skip to content

Hw 2#2

Open
AnNyiiik wants to merge 9 commits intomainfrom
HW_2
Open

Hw 2#2
AnNyiiik wants to merge 9 commits intomainfrom
HW_2

Conversation

@AnNyiiik
Copy link
Owner

No description provided.


let countEvenMap list = list |> Seq.map (fun x -> (1 - Math.Abs(x % 2))) |> Seq.sum

let countEvenFold list = list |> Seq.fold (fun sum element -> (+) sum <| Math.Abs (element + 1) % 2) 0 No newline at end of file

Choose a reason for hiding this comment

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

можно было понятнее записать (:

Suggested change
let countEvenFold list = list |> Seq.fold (fun sum element -> (+) sum <| Math.Abs (element + 1) % 2) 0
let countEvenFold list = list |> Seq.fold (fun sum element -> if element % 2 = 0 then sum else sum + 1) 0

open FsUnit
open EvenNumbers.СountEvenNumbers

let testCases =

Choose a reason for hiding this comment

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

В данном задании можно было использовать FSCheck, чтобы быстро сравнить функции между собой наборами сгенерированных сценариев

Comment on lines +5 to +7
type Tree<'a> =
| Tree of 'a * Tree<'a> * Tree<'a>
| Leaf of 'a

Choose a reason for hiding this comment

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

Дерево не самое корректное, потому что через него нельзя определить вырожденное дерево, не содержащее ни единого элемента.

Comment on lines +3 to +6
type ExpressionTree =
| ExpressionTree of Operation * ExpressionTree * ExpressionTree
| Leaf of int

Choose a reason for hiding this comment

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

Операции могут быть как бинарными, так и унарными. Сейчас унарные операции вообще ни в каком виде не поддерживаются, давайте это исправим

let rec checkDelimeters delimeter =
delimeter >= bound || (n % (int delimeter) <> 0 && checkDelimeters (delimeter + bigint 1))
checkDelimeters (bigint 2)
seq {yield! Seq.filter (fun number -> isPrimeNumber number) (Seq.initInfinite (fun i -> i + 2))} No newline at end of file

Choose a reason for hiding this comment

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

тут можно записать проще

Suggested change
seq {yield! Seq.filter (fun number -> isPrimeNumber number) (Seq.initInfinite (fun i -> i + 2))}
Seq.initInfinite (fun i -> i + 2) |> Seq.filter isPrimeNumber

Comment on lines +7 to +11
let isPrimeNumber n =
let bound = n |> float |> Math.Sqrt |> Math.Round |> bigint |> (+) (bigint 1)
let rec checkDelimeters delimeter =
delimeter >= bound || (n % (int delimeter) <> 0 && checkDelimeters (delimeter + bigint 1))
checkDelimeters (bigint 2)

Choose a reason for hiding this comment

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

вся математика с bigint тут бессильна, поскольку Seq.initInfinite генерирует int последовательность, isPrimeNumber так же принимает int. Если Seq.initInfinite будет генерировать biginit, это все будет иметь смысл

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants