Conversation
| @@ -0,0 +1,6 @@ | |||
| namespace Network | |||
|
|
|||
| type BadOS () = | |||
There was a problem hiding this comment.
Классам для тестов по-хорошему тоже нужны комментарии, в реальных проектах могут быть десятки тысяч тестов, которые тоже надо как-то сопровождать
| member this.IsSomeoneHealthy() = isSomeoneHealthy | ||
| member this.IsBFS() = isBFS |
There was a problem hiding this comment.
Это было лучше read-only-свойствами сделать, методы тут использовать противоестественно
| 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 |
| if state = expectedState then | ||
| failwith "Test success!" | ||
| else | ||
| failwith "Test failure!" |
There was a problem hiding this comment.
Что за управление программой на исключениях? Если всё хорошо, исключения вообще бросаться не должны (без веских причин), это базовое правило работы с исключениями в почти всех распространённых языках.
| abstract member Name : string | ||
| abstract member InfectionChance : float No newline at end of file |
There was a problem hiding this comment.
К методам тоже надо комментарии по-хорошему
|
|
||
| /// Windows OS | ||
| type Windows() = | ||
| interface IOperatingSystem with |
There was a problem hiding this comment.
Непонятно, зачем Вам наследование. По мне так это просто объекты типа IOperatingSystem. Вам же не нужно различать несколько разных Windows
| used.[head] <- true | ||
| used |> log.LogState |> ignore | ||
|
|
||
| nextStep (handlingQueue @ graph.[head]) used |
There was a problem hiding this comment.
Из handlingQueue, кажется, надо убрать head, мы его всё равно ведь только что заразили и больше рассматривать не будем.
| /// Keeps trying to infect it | ||
| | head :: tail when not used.[head] -> | ||
| used |> log.LogState |> ignore | ||
| nextStep (handlingQueue @ [head]) used |
There was a problem hiding this comment.
И тут, мы его не убрали из головы и попытаемся заразить снова
| not used.[head] && | ||
| (random.NextDouble() < computers.[head].InfectionChance) -> | ||
| used.[head] <- true | ||
| used |> log.LogState |> ignore |
There was a problem hiding this comment.
Вообще, это ведь не то, что просили, так у Вас за каждый ход может заражаться ровно один компьютер. А должно быть, например, в такой конфигурации: ( ) --- (*) --- ( ), чтобы вся сеть заразилась за один ход (где * отмечен комп с вирусом). У Вас, кстати, даже нельзя никак сказать, какие из компов заражены изначально.
yurii-litvinov
left a comment
There was a problem hiding this comment.
Теперь похоже на правду, зачтена
| open System | ||
|
|
||
| let computers = [| for i in 1..5 -> ( {new IOperatingSystem with | ||
| member this.InfectionChance = 1.0}) |] |
There was a problem hiding this comment.
Интересное решение, но я имел в виду сделать IOperatingSystem конкрентым классом, а вероятность заражения принимать в конструктор просто
| let rec virusJump queue states = | ||
| match queue with | ||
| | [] -> states | ||
| | virusQueue -> |
| let newNetwork = nextStep virusQueue states List.Empty | ||
| virusJump (fst newNetwork) (snd newNetwork) | ||
|
|
||
| let infected = startState |> Array.indexed |> Array.filter (fun (i, x) -> x = true) |
There was a problem hiding this comment.
Мм, они же не infected, а соседи инфицированных?
No description provided.