Skip to content
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

Homework 2 is ready #5

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Homework 2 is ready #5

wants to merge 15 commits into from

Conversation

viktoriia-fomina
Copy link
Owner

No description provided.

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

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

1 и 4 надо немного поправить, 2 и 3 зачтены

// Использование рекурсии не допускается, зато нужен FsCheck для проверки функций
// на эквивалентность

/// <summary>Counts even numbers in the list using map.</summary>

Choose a reason for hiding this comment

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

Вообще, в F# не принято писать summary, пишут просто ///. Тулы про это знают и могут понять, что это и есть summary


/// <summary>Counts even numbers in the list using map.</summary>
let countEvenInListMap list =
if list = [] then None

Choose a reason for hiding this comment

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

Не-а, в пустом списке ровно 0 чётных чисел

/// <summary>Counts even numbers in the list using map.</summary>
let countEvenInListMap list =
if list = [] then None
else Some(List.sum(List.map(fun x -> if x % 2 = 0 then 1 else 0) list))

Choose a reason for hiding this comment

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

Это было бы красивее через |>

let infiniteSeqOfPrimes =
let rec isPrime n acc =
if n = 2 then true
elif float acc > sqrt (float n) then true

Choose a reason for hiding this comment

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

Проще было бы acc * acc > n


Seq.initInfinite(fun index ->
let n = index + 1
findNPrime n 2)

Choose a reason for hiding this comment

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

Да ну, слишком сложно. Можно сгенерить последовательность всех чисел вообще и выбрать (через Seq.filter) из них те, которые удовлетворяют предикату isPrime. Думайте в терминах ленивых вычислений :)

// let myTree = Node(5, Node(2, Leaf, Leaf), Leaf)
// let sq x = x * x

// mapTree myTree sq

Choose a reason for hiding this comment

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

Закомментированный код нехорошо, да и вообще, есть тесты и F# Interactive, main не очень полезен


[<Test>]
let ``CountEvenInListMap for the list [2; 2; 2; 2] should return Some(4)`` () =
countEvenInListMap[2; 2; 2; 2] |> should equal (Some 4)

Choose a reason for hiding this comment

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

Тут просили FsCheck


[<Test>]
let ``Infinite sequence of primes should return 0`` () =
Seq.findIndex(fun x -> x = 2) infiniteSeqOfPrimes |> should equal 0

Choose a reason for hiding this comment

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

Мне кажется, проще через Seq.nth

Copy link

@yurii-litvinov yurii-litvinov left a comment

Choose a reason for hiding this comment

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

В целом всё так, зачтены

Comment on lines +5 to +6
if list = [] then 0
else List.sum <| List.map(fun x -> if x % 2 = 0 then 1 else 0) list

Choose a reason for hiding this comment

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

Зачем if, List.map и для пустого списка работает

/// Counts even numbers in the list using filter.
let countEvenInListFilter list =
if list = [] then 0
else List.filter(fun x -> x % 2 = 0) list |> List.length

Choose a reason for hiding this comment

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

Что-то с пробелами беда. Это же не вызов функции filter от аргумента (fun x -> x % 2 = 0), это вызов от двух аргументов, первый из которых в скобках, чтобы приоритет операций ничего не сломал. Перед "(" надо пробел.

Seq.initInfinite(fun index ->
let n = index + 1
findNPrime n 2)
*)

Choose a reason for hiding this comment

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

Закомментированный код не нужен. Если хочется иметь возможность к нему вернуться, сделайте тэг в репозитории :)

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