-
Notifications
You must be signed in to change notification settings - Fork 102
Lesson 4. Task 1 #184
Lesson 4. Task 1 #184
Conversation
…on sequenceDigit()
authorStupidman00 [bva1138@yandex.ru] lesson1.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 12 / 12 Example: 4 / 4 Succeeded:
Seed: -6267269258667053021 lesson4.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 20 / 21 Example: 7 / 7 Succeeded:
Failed:
Seed: -6267269258667053021 ownerStupidman00 [] |
Ошибку нашел. Понимаю как решить. |
Надеюсь, сегодня на лекции я ответил на ваш вопрос про глобальные переменные |
recheck all |
authorStupidman00 [bva1138@yandex.ru] lesson1.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 12 / 12 Example: 4 / 4 Succeeded:
Seed: 4944206926986033707 lesson2.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 7 / 7 Example: 1 / 1 Succeeded:
Seed: 4944206926986033707 lesson2.task2Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 5 / 5 Example: 1 / 1 Succeeded:
Seed: 4944206926986033707 lesson3.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 18 / 18 Example: 4 / 4 Succeeded:
Seed: 4944206926986033707 lesson4.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 21 / 21 Example: 7 / 7 Succeeded:
Seed: 4944206926986033707 ownerStupidman00 [] |
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/lesson4/task1/List.kt
Outdated
fun abs(v: List<Double>): Double = TODO() | ||
fun abs(v: List<Double>): Double { | ||
return if (v.isEmpty()) 0.0 | ||
else Math.sqrt(v.map { it * it }.sum()) |
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.
Проверка на isEmpty
здесь не нужна. Кроме этого, функцию можно было записать в виде expression body: = Math.sqrt(v.map ...)
.
src/lesson4/task1/List.kt
Outdated
var mutN: Int = n | ||
do { | ||
result = listOf(mutN%base)+ result | ||
mutN/=base |
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/lesson4/task1/List.kt
Outdated
listOf('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | ||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', | ||
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | ||
'u', 'v', 'w', 'x', 'y', 'z') |
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.
Вместо списков символов лучше использовать строки вроде "01234..."
, тогда у вас будет поменьше одинарных кавычек.
src/lesson4/task1/List.kt
Outdated
* Например: 23 = XXIII, 44 = XLIV, 100 = C | ||
*/ | ||
fun roman(n: Int): String = TODO() | ||
val table: Map<Int,String> = |
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.
Map<Int, String>
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.
И, кстати, явное указание типа здесь и для последующих Map
вообще не требуется.
result += i.value | ||
mutN -= i.key | ||
} | ||
} |
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 ((key, value) in table) {
while (mutN >= key) {
result += value
mutN -= key
}
}
fun tripletProcessing(triplet: Int, | ||
unitsTable: Map<Int, String>, | ||
diclensionOfTripletWord: List<String> = listOf()): List<String> { | ||
var result: MutableList<String> = mutableListOf() |
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.
Дело вкуса, но мне var result = mutableListOf<String>()
кажется короче
src/lesson4/task1/List.kt
Outdated
} | ||
|
||
if (diclensionOfTripletWord.isNotEmpty()) { | ||
if (diclensionOfTripletWord.size == 3) { |
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.
Мне кажется, при наличии этой проверки проверка на isNotEmpty()
избыточно
src/lesson4/task1/List.kt
Outdated
* Например: n = 100, base = 4 -> 1210, n = 250, base = 14 -> 13c | ||
*/ | ||
fun convertToString(n: Int, base: Int): String = TODO() | ||
fun <T> List<T>.indexOf(value: T): Int { |
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/lesson4/task1/List.kt
Outdated
var result: List<Int> = listOf() | ||
while (newN != 1) { | ||
result = result + listOf(minDivisor(newN)) | ||
newN = newN / minDivisor(newN) |
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.
Лучше использовать +=
и /=
authorStupidman00 [bva1138@yandex.ru] lesson4.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 20 / 21 Example: 7 / 7 Succeeded:
Failed:
Seed: -1325375092465392529 ownerStupidman00 [] |
authorStupidman00 [bva1138@yandex.ru] lesson4.task1Author: Stupidman00 [bva1138@yandex.ru] Owner: Stupidman00 [] Total: 21 / 21 Example: 7 / 7 Succeeded:
Seed: -4710341070528094694 ownerStupidman00 [] |
Спасибо за исправления, урок 4 принят. |
Использование глобальных переменных - это плохой стиль. Какие варианты решения данной проблемы есть в этом задании?