diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..a039627 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -2,5 +2,16 @@ package ru.otus.homework fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + val numbers = Array(n) {it} + val result = Array(n) {""} + + for (i in numbers.indices) { + result[i] = when { + numbers[i] % 15 == 0 -> "FizzBuzz" + numbers[i] % 3 == 0 -> "Fizz" + numbers[i] % 5 == 0 -> "Buzz" + else -> numbers[i].toString() + } + } + return result } \ No newline at end of file diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 70d72e5..d2c75e8 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,5 +2,12 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + for (i in numbers.indices) { + for (j in i + 1 until numbers.size ) { + if (numbers[i] + numbers[j] == target) { + return intArrayOf(i, j) + } + } + } + throw IllegalArgumentException("No two numbers sum up to $target") } \ No newline at end of file