-
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
Sem4 problem 5 #64
base: master
Are you sure you want to change the base?
Sem4 problem 5 #64
Conversation
@@ -0,0 +1,6 @@ | |||
namespace Network | |||
|
|||
type BadOS () = |
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.
Классам для тестов по-хорошему тоже нужны комментарии, в реальных проектах могут быть десятки тысяч тестов, которые тоже надо как-то сопровождать
member this.IsSomeoneHealthy() = isSomeoneHealthy | ||
member this.IsBFS() = isBFS |
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.
Это было лучше 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 |
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.
Самодельный List.iter?
if state = expectedState then | ||
failwith "Test success!" | ||
else | ||
failwith "Test failure!" |
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.
Что за управление программой на исключениях? Если всё хорошо, исключения вообще бросаться не должны (без веских причин), это базовое правило работы с исключениями в почти всех распространённых языках.
abstract member Name : string | ||
abstract member InfectionChance : float |
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.
К методам тоже надо комментарии по-хорошему
|
||
/// Windows OS | ||
type Windows() = | ||
interface IOperatingSystem with |
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.
Непонятно, зачем Вам наследование. По мне так это просто объекты типа IOperatingSystem. Вам же не нужно различать несколько разных Windows
used.[head] <- true | ||
used |> log.LogState |> ignore | ||
|
||
nextStep (handlingQueue @ graph.[head]) used |
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.
Из 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.
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 |
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.
Вообще, это ведь не то, что просили, так у Вас за каждый ход может заражаться ровно один компьютер. А должно быть, например, в такой конфигурации: ( ) --- (*) --- ( )
, чтобы вся сеть заразилась за один ход (где * отмечен комп с вирусом). У Вас, кстати, даже нельзя никак сказать, какие из компов заражены изначально.
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.
Теперь похоже на правду, зачтена
open System | ||
|
||
let computers = [| for i in 1..5 -> ( {new IOperatingSystem with | ||
member this.InfectionChance = 1.0}) |] |
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.
Интересное решение, но я имел в виду сделать IOperatingSystem конкрентым классом, а вероятность заражения принимать в конструктор просто
let rec virusJump queue states = | ||
match queue with | ||
| [] -> states | ||
| virusQueue -> |
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.
Можно было просто | _ ->
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мм, они же не infected, а соседи инфицированных?
No description provided.