diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..dd9c970 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,6 +1,31 @@ package ru.otus.homework +fun main() { + val inpN = 6 + val resultTextArray = fizzbuzz(inpN) + println(resultTextArray.contentToString()) +} fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + var i = 0 + val numbArray = Array(n) { i++ } + val textArray = Array(n) { "textString" } + + for(index in numbArray.indices) { + val number = numbArray[index] + + if(number % 3 == 0 && number % 5 == 0) { + textArray[index] = "FizzBuzz" + } else if(number % 3 == 0) { + textArray[index] = "Fizz" + } else { + if (number % 5 == 0) { + textArray[index] = "Buzz" + } else { + textArray[index] = number.toString() + } + } + } + + return textArray } \ 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..7b3f2a3 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,6 +1,28 @@ package ru.otus.homework +fun main(args: Array) { + val numbersArray = intArrayOf(0, 9, 11, 15, 2) + val target = 9 + println(sumOfTwo(numbersArray, target).contentToString()) +} fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + + val indexcesArray = intArrayOf(0, 0) + numbers.forEachIndexed { index, value -> + + for (nextIndex in index + 1 until numbers.size) { + val nextValue = numbers[nextIndex] + val sumOfTwoValues = value + nextValue + + if (sumOfTwoValues == target) { + indexcesArray[0] = index + indexcesArray[1] = nextIndex + } + } + } + + if (indexcesArray[0] != 0 || indexcesArray[1] != 0) + return indexcesArray + else throw IllegalArgumentException("not values") } \ No newline at end of file