From 80c4f19c4b415de276372d2350605b74e0dd7057 Mon Sep 17 00:00:00 2001 From: CVB Date: Wed, 13 Aug 2025 23:12:30 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=B0=D0=BC=D0=B0=D1=88=D0=BD=D1=8F?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 14 +++++++++++++- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 10 +++++++++- 2 files changed, 22 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..6ab23a8 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -2,5 +2,17 @@ package ru.otus.homework fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + /* Функция не требует никаких дополнительных проверок. Т.к. либо исключение, либо пустой массив. */ + val nArr = Array(n, {it}) + val sRes = Array(n, {""}) + for ((i, v) in nArr.withIndex()) { + sRes[i] = if (v == 0 || ((v % 3 == 0) && (v % 5 == 0))) { + "FizzBuzz" + } else if (v % 5 == 0) { + "Buzz" + } else if (v % 3 == 0) { + "Fizz" + } else "$v" + } + return sRes } \ 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..3ba4bc7 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,5 +2,13 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + val nRes = IntArray(2) + for ((i, v) in numbers.withIndex()) { + for (j in i + 1 until numbers.count()) { + if (v + numbers[j] == target) { + return intArrayOf(i, j) + } + } + } + throw IllegalArgumentException("No result") } \ No newline at end of file From c8394076e7bb4a41df85a0f5a3efd8efe854c2a3 Mon Sep 17 00:00:00 2001 From: CVB Date: Wed, 13 Aug 2025 23:22:10 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83=D0=B5?= =?UTF-8?q?=D0=BC=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 3ba4bc7..31bb39a 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,7 +2,6 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - val nRes = IntArray(2) for ((i, v) in numbers.withIndex()) { for (j in i + 1 until numbers.count()) { if (v + numbers[j] == target) {