From b465b9d598ba182f454d14fe7789bfda1d481ffb Mon Sep 17 00:00:00 2001 From: Mickey Sage Date: Sat, 26 Oct 2024 04:06:32 +0300 Subject: [PATCH] homework01 complete --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 9 ++++++++- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..6d49d33 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -2,5 +2,12 @@ package ru.otus.homework fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + return Array(n) { + when { + it % 15 == 0 -> "FizzBuzz" + it % 3 == 0 -> "Fizz" + it % 5 == 0 -> "Buzz" + else -> "$it" + } + } } \ 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..48ed183 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,5 +2,8 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + for (i in 0 until numbers.size - 1) + if (numbers[i] + numbers[i+1] == target) + return intArrayOf(i, i+1) + throw IllegalArgumentException() } \ No newline at end of file