Skip to content

Sem4 problem 5#64

Open
Timur-Zinnatulin wants to merge 7 commits into
masterfrom
sem4-problem-5
Open

Sem4 problem 5#64
Timur-Zinnatulin wants to merge 7 commits into
masterfrom
sem4-problem-5

Conversation

@Timur-Zinnatulin
Copy link
Copy Markdown
Owner

No description provided.

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

type BadOS () =
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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!"
Copy link
Copy Markdown

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 No newline at end of file
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

@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}) |]
Copy link
Copy Markdown

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 ->
Copy link
Copy Markdown

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)
Copy link
Copy Markdown

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