diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..dfcd66f 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,6 +1,26 @@ package ru.otus.homework +import kotlin.random.Random + fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") -} \ No newline at end of file + + val names = arrayOf("Fizz", "Buzz") + val numbers = arrayOfNulls(n) + val result = arrayOfNulls(n) + + numbers[0] = 0 + for( i in 1..n-1) { + numbers[i] = Random.nextInt(0, 25) + } + for( i in 0..n-1) { + result[i] = when{ + numbers[i] == 0 -> names[0]+names[1] + numbers[i]?.rem(3) ==0 && numbers[i]?.rem(5) ==0 -> names[0]+names[1] + numbers[i]?.rem(3) == 0 -> names[0] + numbers[i]?.rem(5) == 0 -> names[1] + else -> numbers[i].toString() + } + } + return result as Array +} diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 70d72e5..7bd67be 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,5 +2,14 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + val inputCnt = numbers.count() + + for( i in 0 .. inputCnt-2){ + for( j in i+1 .. inputCnt-1){ + if (numbers[i] + numbers[j] == target) { + return intArrayOf( i, j ) + } + } + } + throw IllegalArgumentException("Target not found") } \ No newline at end of file