-
Notifications
You must be signed in to change notification settings - Fork 102
kotlin 2(fixed), 3, 4 #174
Conversation
authorЕлизавета [mokryienot@icloud.com] lesson2.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 7 / 7 Example: 1 / 1 Succeeded:
Seed: -3905744759704403537 lesson2.task2Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 4 / 5 Example: 1 / 1 Succeeded:
Failed:
Seed: -3905744759704403537 ownermilkyway23 [] |
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/lesson2/task1/IfElse.kt
Outdated
*/ | ||
fun ageDescription(age: Int): String = TODO() | ||
fun ageDescription(age: Int): String { | ||
if ( ( age in 5..20 ) or ( age in 105..120 ) ) return "$age лет" |
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.
Лучше вместо неленивого or
использовать ленивый ||
. В данном случае особой разницы нет, но во многих случаях это критически важно
src/lesson2/task1/IfElse.kt
Outdated
t2: Double, v2: Double, | ||
t3: Double, v3: Double): Double = TODO() | ||
t3: Double, v3: Double): Double { | ||
val p:Double =t1*v1+t2*v2+v3*t3 |
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.
Тип локальных переменных обычно выводится автоматически. Кроме этого, рекомендуется расставлять пробелы в единообразном стиле: val p = t1 * v1 + t2 * v2 + t3 * v3
. Такой стиль можно получить автоматически, использовав комбинацию клавиш Ctrl+Alt+L в IDEA
src/lesson2/task1/IfElse.kt
Outdated
rookX2: Int, rookY2: Int): Int = TODO() | ||
|
||
rookX2: Int, rookY2: Int): Int { | ||
var rook:Int=0; var bishop:Int=0; var p:Int=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.
Определение нескольких переменных в одной строке выглядит очень некрасиво
src/lesson2/task1/IfElse.kt
Outdated
rookX2: Int, rookY2: Int): Int { | ||
var rook:Int=0; var bishop:Int=0; var p:Int=0 | ||
if ((rookX1==kingX)or(rookY1==kingY)) rook = 1 | ||
if ((rookX2==kingX)or(rookY2==kingY)) bishop = 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.
or
--> ||
. Обе переменные rook
, bishop
следует сделать логическими, так как они обозначают наличие угрозы от ладьи (слона). Угроза или есть, или её нет.
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.
Вы, судя по всему, скопировали текст этой функции с последующей, в которой действительно есть ладья и слон. Здесь же есть две ладьи, поэтому переменные следовало назвать rook1
и rook2
.
src/lesson2/task1/IfElse.kt
Outdated
if ((rook==0)&&(bishop==0)) p=0 else | ||
if ((rook==1)&&(bishop==1)) p=3 else | ||
if (bishop==1) p=2 else | ||
p=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 (!rook && !bishop) p = 0
else if (rook && bishop) p = 3
else if (bishop) p = 2
else p = 1
или с помощью when
:
when {
!rook && !bishop -> p = 0
rook && bishop -> p = 3
bishop -> p = 2
else -> p = 1
}
И не забывайте расставлять пробелы правильно (Ctrl+Alt+L)
src/lesson2/task1/IfElse.kt
Outdated
if (c<=a && d>=b) n = (b - a) else | ||
if (c<=a && d>=a && d<=b) n = (d-a) else | ||
if (c>=a && c<=b && d>=b) n = (b-c) else | ||
if (c>=a && c<=b && d<=b) n = (d-c) else n = -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..else if (см. пример выше), пробелы
src/lesson2/task2/Logical.kt
Outdated
fun isNumberHappy(number: Int): Boolean = TODO() | ||
|
||
fun isNumberHappy(number: Int): Boolean { | ||
if ((number % 10 + number / 10 % 10) == (number / 100 % 10 + number / 1000)) return true else return false |
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 (x) return true else return false
эквивалентно return x
.
src/lesson2/task2/Logical.kt
Outdated
fun queenThreatens(x1: Int, y1: Int, x2: Int, y2: Int): Boolean { | ||
if ((x1 == x2) || (y2 == y1)) return true | ||
else if (Math.abs(x1 - x2) == Math.abs(y1 - y2)) return true | ||
else return false |
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 (x) return true else if (y) return true else return false
эквивалентно return x || y
.
src/lesson2/task2/Logical.kt
Outdated
|
||
x2: Double, y2: Double, r2: Double): Boolean { | ||
if ((Math.sqrt(sqr(x2 - x1) + sqr(y2 - y1)) + r1) <= r2) return true | ||
else return false |
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 (x) return true else return false
src/lesson2/task2/Logical.kt
Outdated
*/ | ||
fun brickPasses(a: Int, b: Int, c: Int, r: Int, s: Int): Boolean = TODO() | ||
fun brickPasses(a: Int, b: Int, c: Int, r: Int, s: Int): Boolean { | ||
if (((a <= r) && (b <= s)) || ((a <= s) && (b <= r)) || ((a <= r) && (c <= s)) || ((a <= s) && (a <= r)) || ((c <= r) && (b <= s)) || ((c <= s) && (b <= r))) return true else return false |
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.
Эта очень длинная строка. В ней довольно просто ошибиться, что вы и сделали (см. сообщение бота). Добавьте в тестовую функцию тот случай, который привёл для вас бот. А эту функцию попробуйте записать короче. Используйте тот факт, что кирпич в любом случае следует вставлять самой длинной стороной вдоль отверстия, то есть, самая длинная сторона кирпича должна игнорироваться при сравнении
authorЕлизавета [mokryienot@icloud.com] lesson2.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 7 / 7 Example: 1 / 1 Succeeded:
Seed: 8819397182519864960 lesson2.task2Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 5 / 5 Example: 1 / 1 Succeeded:
Seed: 8819397182519864960 ownermilkyway23 [] |
authorЕлизавета [mokryienot@icloud.com] lesson3.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 10 / 18 Example: 4 / 4 Succeeded:
Seed: 2797484711808635803 ownermilkyway23 [] |
Название Pull Request не соответствует его содержанию. Будьте любезны его исправить |
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/lesson2/task1/IfElse.kt
Outdated
rookX2: Int, rookY2: Int): Int = TODO() | ||
|
||
rookX2: Int, rookY2: Int): Int { | ||
var rook: Int = 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.
val rook1 = rookX1 == kingX || rookY1 == kingY
. Раз речь идёт о 1-й ладье, то и назвать переменную нужно rook1
, а не просто rook
. Кроме этого, у этой переменной может быть всего два значения: есть угроза или нет. А значит, она должна быть логической, а не целой. То же самое со 2-й ладьёй.
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/lesson2/task1/IfElse.kt
Outdated
var p: Int = 0 | ||
if ((rookX1 == kingX) || (rookY1 == kingY)) rook = 1 | ||
if ((rookX2 == kingX) || (rookY2 == kingY)) rook1 = 1 | ||
if ((rook == 0) && (rook1 == 0)) p = 0 else |
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.
Подобные многоэтажные проверки лучше записывать через when
. Заодно, с форматированием кода будет проще -- сейчас это читать невозможно
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/lesson2/task1/IfElse.kt
Outdated
bishopX: Int, bishopY: Int): Int = TODO() | ||
|
||
bishopX: Int, bishopY: Int): Int { | ||
var rook = 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.
См. замечания к предыдущей функции
fun triangleKind(a: Double, b: Double, c: Double): Int { | ||
var n: Int = 0 | ||
if ((a + b > c) && (a + c > b) && (c + b > a)) { | ||
if ((a * a + b * b < c * c) || (a * a + c * c < b * b) || (b * b + c * c < a * a)) n = 2 |
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.
Здесь тоже лучше использовать when
или, по крайней мере, написать все три проверки на одном уровне, а не лестницей.
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/lesson2/task1/IfElse.kt
Outdated
fun segmentLength(a: Int, b: Int, c: Int, d: Int): Int = TODO() | ||
fun segmentLength(a: Int, b: Int, c: Int, d: Int): Int { | ||
var n: Int = 0 | ||
if (c <= a && d >= b) n = (b - a) |
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/lesson2/task2/Logical.kt
Outdated
*/ | ||
fun isNumberHappy(number: Int): Boolean = TODO() | ||
fun isNumberHappy(number: Int): Boolean { | ||
return ((number % 10 + number / 10 % 10) == (number / 100 % 10 + number / 1000)) |
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.
Для этой функции можно использовать expression body: fun isNumberHappy(number: Int): Boolean =
и далее выражение, которое у вас стоит после return
.
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/lesson3/task1/Loop.kt
Outdated
var n2 = n | ||
if (n == 0) return 1 | ||
else while (n2 != 0) { | ||
n2 = n2 / 10 |
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.
Лучше n2 /= 10
src/lesson3/task1/Loop.kt
Outdated
fun minDivisor(n: Int): Int { | ||
var a = n | ||
for (i in 2..n) { | ||
if (n % i == 0) if (i <= a) a = 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.
Поскольку вы перебираете возможные делители по возрастанию, вы можете сразу же вернуть делитель из функции, когда убедились, что n
делится на него без остатка. Промежуточная переменная a
здесь не нужна.
src/lesson3/task1/Loop.kt
Outdated
* 15751 -- палиндром, 3653 -- нет. | ||
*/ | ||
fun isPalindrome(n: Int): Boolean = TODO() | ||
fun isPalindrome(n: Int): Boolean { |
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.
Эта функция практически повторяет предыдущую, попробуйте выразить isPalindrome
через revert
А пока я не исправлю замечания, урок не будет учитываться при промежуточной аттестации? |
authorЕлизавета [mokryienot@icloud.com] lesson3.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 14 / 18 Example: 4 / 4 Succeeded:
Failed:
Seed: 3870592699220730581 ownermilkyway23 [] |
maven[INFO] Scanning for projects... Downloaded: https://jitpack.io/com/github/belyaev-mikhail/kcheck/master-SNAPSHOT/maven-metadata.xml (398 B at 0.5 KB/sec) Downloaded: https://jitpack.io/com/github/belyaev-mikhail/kotlin-quasi-reflection/master-SNAPSHOT/maven-metadata.xml (407 B at 0.8 KB/sec) [ERROR] /var/lib/jenkins/workspace/kotlin-as-first.fall-2016/test/lesson4/task1/Tests.kt: (126, 35) Too many arguments for @test @tag public final fun polynom(): Unit defined in lesson4.task1.Tests |
authorЕлизавета [mokryienot@icloud.com] lesson4.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 11 / 21 Example: 7 / 7 Succeeded:
Seed: -7567457683177422940 ownermilkyway23 [] |
Conflicts: src/lesson3/task1/Loop.kt
authorЕлизавета [mokryienot@icloud.com] lesson4.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 11 / 21 Example: 7 / 7 Succeeded:
Seed: -1786036863822967648 ownermilkyway23 [] |
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.
Довольно много замечаний к урокам 2, 3 и 4. Прошу их исправить, перед тем как решать следующие уроки.
src/lesson2/task1/IfElse.kt
Outdated
rookX2: Int, rookY2: Int): Int = TODO() | ||
|
||
rookX2: Int, rookY2: Int): Int { | ||
var rook: Int = 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.
Это замечание всё ещё в силе
src/lesson2/task1/IfElse.kt
Outdated
var p: Int = 0 | ||
if ((rookX1 == kingX) || (rookY1 == kingY)) rook = 1 | ||
if ((rookX2 == kingX) || (rookY2 == kingY)) rook1 = 1 | ||
if ((rook == 0) && (rook1 == 0)) p = 0 else |
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.
Это замечание всё ещё в силе
fun triangleKind(a: Double, b: Double, c: Double): Int { | ||
var n: Int = 0 | ||
if ((a + b > c) && (a + c > b) && (c + b > a)) { | ||
if ((a * a + b * b < c * c) || (a * a + c * c < b * b) || (b * b + c * c < a * a)) n = 2 |
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/lesson2/task2/Logical.kt
Outdated
*/ | ||
fun isNumberHappy(number: Int): Boolean = TODO() | ||
fun isNumberHappy(number: Int): Boolean { | ||
return ((number % 10 + number / 10 % 10) == (number / 100 % 10 + number / 1000)) |
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/lesson3/task1/Loop.kt
Outdated
fun isPalindrome(n: Int): Boolean = TODO() | ||
fun isPalindrome(n: Int): Boolean { | ||
var a = revert(n) | ||
return (a == n) |
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.
Переменная a
здесь не нужна. А вместо return
для такой простой функции следует использовать expression body: fun isPalindrome(...): Boolean = ...
.
src/lesson4/task1/List.kt
Outdated
fun abs(v: List<Double>): Double = TODO() | ||
fun abs(v: List<Double>): Double { | ||
val n: Int = v.size | ||
var length: Double = 0.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.
В котлине почти никогда не нужно указывать тип локальных переменных -- он очевиден из контекста.
var length: Double = 0.0 | ||
for (i: Int in 0..n - 1) { | ||
length = length + v[i] * v[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.
Здесь лучше использовать for-each: for (elem in v) { ... }
, перебирая все элементы вектора. Индексация может быть довольно медленной операцией, да и лишняя переменная появляется
var length: Double = 0.0 | ||
for (i: Int in 0..n - 1) { | ||
length = length + list[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.
Можно просто val length = list.sum()
.
fun times(a: List<Double>, b: List<Double>): Double { | ||
return if (a.size != b.size) Double.NaN | ||
else if (a.isEmpty() || b.isEmpty()) 0.0 | ||
else a.zip(b, { elementOfa, elementOfb -> elementOfa * elementOfb }).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.
Поясните мне в комментарии, что происходит в этой строчке, пожалуйста
if (i % 2 == 1) si = si - number | ||
else si = si + number | ||
|
||
} |
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.
В этой функции (и для косинуса тоже) у вас возникают проблемы с точностью для больших значений x
. Попробуйте написать тест для вычисления sin(100 * Math.PI)
, точность задайте 1e-10
, ожидаемый результат равен 0. Из-за того, что вам потребуется просуммировать очень большое количество членов ряда, нужной точности достигнуть вам не удастся. Подумайте, как решить эту проблему, используя хорошо известные математические свойства синуса.
Вы довольно сильно отстаёте от графика. Вам следует продолжать решать задачи учебного проекта. |
Извините, просто давно не отсылала из-за неполадок с интернетом( Отправлено с iPad
|
А на упражнения ходить что мешает? |
authorЕлизавета [mokryienot@icloud.com] lesson2.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 7 / 7 Example: 1 / 1 Succeeded:
Seed: -5342678992742420004 lesson2.task2Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 5 / 5 Example: 1 / 1 Succeeded:
Seed: -5342678992742420004 lesson3.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 14 / 18 Example: 4 / 4 Succeeded:
Failed:
Seed: -5342678992742420004 lesson4.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 11 / 21 Example: 7 / 7 Succeeded:
Seed: -5342678992742420004 ownermilkyway23 [] totalAuthor: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 37 / 51 Example: 13 / 13 |
Я только на одном занятии не была(
Просто с того компьютера не отправляла ничего. Не ругайтесь, пожалуйста((
Отправлено с iPad
… 24 нояб. 2016 г., в 11:58, Mikhail Glukhikh ***@***.***> написал(а):
А на упражнения ходить что мешает?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Я пока ещё не очень сильно ругаюсь :) |
some tasks
authorЕлизавета [mokryienot@icloud.com] lesson5.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 5 / 12 Example: 2 / 2 Succeeded:
Seed: 8461624710135959556 lesson6.task1Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 7 / 16 Example: 4 / 4 Succeeded:
Seed: 8461624710135959556 lesson6.task2Author: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 2 / 11 Example: 1 / 1 Succeeded:
Seed: 8461624710135959556 ownermilkyway23 [] totalAuthor: Елизавета [mokryienot@icloud.com] Owner: milkyway23 [] Total: 14 / 39 Example: 7 / 7 |
А исправить все замечания к урокам 2-4? Посмотрите, пожалуйста, замечания и вопросы на вкладке Files Changed: https://github.com/Kotlin-Polytech/KotlinAsFirst2016/pull/174/files. Потом буду смотреть остальное. |
"Зачёт" готов поставить только после исправления ВСЕХ замечаний. |
Замечания вы можете найти на вкладке Files Changed |
No description provided.