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

Sem4 problem 5 #64

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

Sem4 problem 5 #64

wants to merge 7 commits into from

Conversation

Timur-Zinnatulin
Copy link
Owner

No description provided.

@@ -0,0 +1,6 @@
namespace Network

type BadOS () =

Choose a reason for hiding this comment

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

Классам для тестов по-хорошему тоже нужны комментарии, в реальных проектах могут быть десятки тысяч тестов, которые тоже надо как-то сопровождать

Comment on lines 8 to 9
member this.IsSomeoneHealthy() = isSomeoneHealthy
member this.IsBFS() = isBFS

Choose a reason for hiding this comment

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

Это было лучше read-only-свойствами сделать, методы тут использовать противоестественно

Comment on lines 13 to 21
let rec printList number list =
match list with
| [] -> printf "\n"
| head :: tail ->
match head with
| true -> printfn "Computer #%d: Infected" number
| false -> printfn "Computer #%d: Healthy" number

printList (number + 1) tail

Choose a reason for hiding this comment

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

Самодельный List.iter?

Comment on lines 11 to 14
if state = expectedState then
failwith "Test success!"
else
failwith "Test failure!"

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
abstract member Name : string
abstract member InfectionChance : float

Choose a reason for hiding this comment

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

К методам тоже надо комментарии по-хорошему


/// Windows OS
type Windows() =
interface IOperatingSystem with

Choose a reason for hiding this comment

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

Непонятно, зачем Вам наследование. По мне так это просто объекты типа IOperatingSystem. Вам же не нужно различать несколько разных Windows

used.[head] <- true
used |> log.LogState |> ignore

nextStep (handlingQueue @ graph.[head]) used

Choose a reason for hiding this comment

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

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

/// Keeps trying to infect it
| head :: tail when not used.[head] ->
used |> log.LogState |> ignore
nextStep (handlingQueue @ [head]) used

Choose a reason for hiding this comment

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

И тут, мы его не убрали из головы и попытаемся заразить снова

not used.[head] &&
(random.NextDouble() < computers.[head].InfectionChance) ->
used.[head] <- true
used |> log.LogState |> ignore

Choose a reason for hiding this comment

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

Вообще, это ведь не то, что просили, так у Вас за каждый ход может заражаться ровно один компьютер. А должно быть, например, в такой конфигурации: ( ) --- (*) --- ( ), чтобы вся сеть заразилась за один ход (где * отмечен комп с вирусом). У Вас, кстати, даже нельзя никак сказать, какие из компов заражены изначально.

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.

Теперь похоже на правду, зачтена

open System

let computers = [| for i in 1..5 -> ( {new IOperatingSystem with
member this.InfectionChance = 1.0}) |]

Choose a reason for hiding this comment

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

Интересное решение, но я имел в виду сделать IOperatingSystem конкрентым классом, а вероятность заражения принимать в конструктор просто

let rec virusJump queue states =
match queue with
| [] -> states
| virusQueue ->

Choose a reason for hiding this comment

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

Можно было просто | _ ->

let newNetwork = nextStep virusQueue states List.Empty
virusJump (fst newNetwork) (snd newNetwork)

let infected = startState |> Array.indexed |> Array.filter (fun (i, x) -> x = true)

Choose a reason for hiding this comment

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

Мм, они же не infected, а соседи инфицированных?

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