Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/main/kotlin/ru/otus/homework/fizzbuzz.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,18 @@ package ru.otus.homework


fun fizzbuzz(n: Int): Array<String> {
TODO("Выполните задание")
}

val list = mutableListOf<String>()

for(i in 0..n - 1){
if ( i % 3 == 0 && i % 5 == 0)
list.add("FizzBuzz")
else if ( i % 3 == 0 )
list.add("Fizz")
else if ( i % 5 == 0)
list.add("Buzz")
else
list.add(i.toString())
}
return list.toTypedArray()
}
11 changes: 9 additions & 2 deletions src/main/kotlin/ru/otus/homework/sumoftwo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,12 @@ package ru.otus.homework


fun sumOfTwo(numbers: IntArray, target: Int): IntArray {
TODO("Выполните задание")
}
val n = numbers.size
for (i in 0..n-1){

Choose a reason for hiding this comment

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

Тут можно использовать until для полуоткрытых интервалов: 0 until n и i+1 until n вместо 0..n-1 и i+1..n-1
until явно показывает, что конец не включается. Это стандартная практика в Kotlin для итерации по индексам.

for ( j in i+1..n-1){
if( numbers[i] + numbers[j] == target)
return intArrayOf(i, j)
}
}
throw IllegalArgumentException()

Choose a reason for hiding this comment

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

Исключение выбрасывается, если пара не найдена. Можно еще добавить сообщение типа: IllegalArgumentException("No two numbers sum to target")

}