Skip to content

Conversation

@vologin-dmitry
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.

В целом всё так. Зачтена

Comment on lines +7 to +20
let isNotBracket (ch : Char) =
ch <> '[' && ch <> '{' && ch <> '(' && ch <> ']' && ch <> '}' && ch <> ')'

/// Checks if symbol is a opening bracket
let isOpenBracket (bracket : Char) =
bracket = '[' || bracket = '{' || bracket = '('

/// Checks if symbols are opening and closing brackets of the same type
let isMatchingBrackets (first : Char) (second : Char) =
match first with
| '(' -> second = ')'
| '[' -> second = ']'
| '{' -> second = '}'
| _ -> true

Choose a reason for hiding this comment

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

В принципе, это всё можно было бы заменить Map-ом и вызывать соответствующие его методы

Comment on lines +24 to +34
if str = []
then memory = []
else
let current = List.head str
if (isNotBracket current) then
checkLine (List.tail str) (memory)
elif (isOpenBracket current) then
checkLine (List.tail str) (current :: memory)
elif (memory <> [] && isMatchingBrackets (List.head memory) (current)) then
checkLine (List.tail str) (List.tail memory)
else false

Choose a reason for hiding this comment

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

Алгоритмически правильно, но технически лучше через match переписать. Вообще, rule of thumb таково, что List.head, List.tail и подобные функции редко встречаются где-то кроме параметров функций высших порядков, поэтому если их много, имеет смысл подумать, не будет ли код в полтора раза короче, если делать match по образцу (тут участвуют два списка, но никто не мешает матчить по паре).

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