-
Notifications
You must be signed in to change notification settings - Fork 102
6th lesson started #178
6th lesson started #178
Conversation
(сорри за флуд)
Some fixes for lesson 4
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 2 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: -7825333907411151869 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 4 / 12 Example: 2 / 2 Succeeded:
Seed: 2787544051375233094 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 4 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: 3394674177550604011 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 6 / 12 Example: 2 / 2 Succeeded:
Seed: -3392941498761949660 ownergrafovdenis [] |
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.
В целом всё очень хорошо, решения верные, имеются отдельные замечания по стилю.
src/lesson5/task1/Parse.kt
Outdated
val parts = str.split(" ") | ||
val day = parts[0].toInt() | ||
var month = 0 | ||
for (i in 0..listOfMonths.size - 1) { |
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.indexOf
.
src/lesson5/task1/Parse.kt
Outdated
fun dateStrToDigit(str: String): String = TODO() | ||
fun dateStrToDigit(str: String): String { | ||
if (str.matches(Regex("""\d+\s[а-я]+\s\d+"""))) { | ||
val parts = str.split(" ") |
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.
Может быть, если вы уж применяете регулярное выражение, лучше сразу же и разбить его на отдельные группы, и не делать потом отдельно split
?
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.
То есть сначала разбивать на группы через regex, а затем ловить исключения, я правильно понял?
fun dateDigitToStr(digital: String): String = TODO() | ||
fun dateDigitToStr(digital: String): String { | ||
if (digital.matches(Regex("""\d+\.\d+\.\d+"""))) { | ||
val parts = digital.split(".") |
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.
См. выше по поводу Regex / split
src/lesson5/task1/Parse.kt
Outdated
if (jumps.matches(Regex("""[\d\s%\-]+"""))) { | ||
val parts = jumps.split(Regex("""[\D]+""")) | ||
var result = -1 | ||
for (i in 0..parts.size - 1) { |
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.
Здесь лучше так: for (part in parts) { ... }
, не занимаясь перебором индексов. Так короче, а во многих случаях также быстрее (например, у линейного списка индексация может требовать числа операций, пропорционального индексу).
src/lesson5/task1/Parse.kt
Outdated
listOfHits.add(parts[i].toInt()) | ||
} | ||
} | ||
for (element in listOfHits) { |
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.
Здесь можно так: return listOfHits.max() ?: -1
. list.max()
возвращает максимальный элемент списка, а для пустого списка null
. Элвис-оператор ?:
подставит вместо null
правую часть (-1), сохранив левую часть в неприкосновенности, если там не null
. Завтра на лекции расскажу про это подробнее
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 7 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: 459732344021748350 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 9 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: 3500122098385888032 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 9 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: -6159818669175382977 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 9 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: 8176807465642520824 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 8 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: 8356354001548602930 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 10 / 12 Example: 2 / 2 Succeeded:
Failed:
Seed: -8100048644932380814 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson5.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 11 / 12 Example: 2 / 2 Succeeded:
Seed: -8166568301791892636 ownergrafovdenis [] |
authorDenis Grafov [grafov.denis@gmail.com] lesson6.task1Author: Denis Grafov [grafov.denis@gmail.com] Owner: grafovdenis [] Total: 7 / 16 Example: 4 / 4 Succeeded:
Seed: -6074543812260368049 ownergrafovdenis [] |
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.
Не считая нескольких незначительных замечаний, всё в порядке. Пожалуйста, исправьте их в следующем PR.
namesList += list[0] | ||
pricesList += list[1].toDouble() | ||
} else { | ||
toBreak = 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.
Почему бы здесь сразу же не написать return?
fun fromRoman(roman: String): Int { | ||
if (roman.matches(Regex("""[MDCLXVI]+""")) || roman.isEmpty()) { | ||
val listOfArabic = mutableListOf(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1) | ||
val listOfRoman = mutableListOf("M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I") |
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.
Здесь лучше mapOf
, но мы его ещё не проходили. Если вам интересно, разберитесь сами. Ну и лучше, конечно, просто listOf
, а не mutableListOf
.
if (toBreak) return "" | ||
else { | ||
for (i in 0..pricesList.size - 1) { | ||
if (pricesList[i] >= maxPrice && pricesList.size != 1) { |
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.
Проверка на размер здесь не нужна
} | ||
if (toBreak) return "" | ||
else { | ||
for (i in 0..pricesList.size - 1) { |
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.
Ещё лучше for ((i, price) in pricesList.withIndex()) { ... }
No description provided.