From 45dabb8a57e6c9ad052cd24fe5f8ae05273d0f11 Mon Sep 17 00:00:00 2001 From: YURY TILMAN Date: Wed, 13 Aug 2025 22:37:52 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=BC=D0=B0=D1=88=D0=BD?= =?UTF-8?q?=D0=B5=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 11 +++++++++-- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..6c73f19 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,6 +1,13 @@ package ru.otus.homework - +// шаг 1 задачи пропущен, так как индексы массива по заданию соответствуют числам на указанных индексах fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + return Array(n) { + when { + it % 3 == 0 && it % 5 == 0 -> "FizzBuzz" + it % 3 == 0 -> "Fizz" + it % 5 == 0 -> "Buzz" + else -> it.toString() + } + } } \ 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..24400c2 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,5 +2,16 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + val numbersSize = numbers.size + if (numbersSize < 1) throw IllegalArgumentException("Массив должен содержать хотя бы 2 элемента") + numbers.forEachIndexed { index, it -> + if (index == numbersSize - 1) throw IllegalArgumentException("Подходящих чисел не найдено") + if (it + numbers[index + 1] == target) return intArrayOf(index, index + 1) + for (i in index + 1 until numbersSize) { + if (it + numbers[i] == target) { + return intArrayOf(index, i) + } + } + } + throw IllegalArgumentException("Подходящих чисел не найдено") } \ No newline at end of file From ecf4890661892e21848ba6bb96e1476005b2c4b6 Mon Sep 17 00:00:00 2001 From: YURY TILMAN Date: Wed, 13 Aug 2025 22:39:11 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9A=20=D1=82=D0=B5=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D0=BC=20=D0=BA=D0=BE=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=BC?= =?UTF-8?q?=D1=83=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D1=8E=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BA=D0=B5?= =?UTF-8?q?=D0=B9=D1=81=D1=8B=20=D1=81=20=D0=BF=D0=BE=D0=B3=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=87=D0=BD=D1=8B=D0=BC=D0=B8=20=D0=B7=D0=BD=D0=B0?= =?UTF-8?q?=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=D0=BC=D0=B8=20=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=BC=D0=B5=D0=B6=D0=BD=D1=8B=D0=BC=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BD=D0=B4=D0=B5=D0=BA=D1=81=D0=B0=D0=BC=D0=B8,=20=D0=B4?= =?UTF-8?q?=D0=B0=D1=8E=D1=89=D0=B8=D0=BC=D0=B8=20target?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/ru/otus/homework/SumoftwoTest.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/kotlin/ru/otus/homework/SumoftwoTest.kt b/src/test/kotlin/ru/otus/homework/SumoftwoTest.kt index 2cc5d9d..7975788 100644 --- a/src/test/kotlin/ru/otus/homework/SumoftwoTest.kt +++ b/src/test/kotlin/ru/otus/homework/SumoftwoTest.kt @@ -26,4 +26,25 @@ class SumoftwoTest { sumOfTwo(intArrayOf(3, 2), 6) } } + + /** + * Кейс для пустого массива + * */ + @Test + fun `testcase 4`() { + assertThrows { + sumOfTwo(IntArray(0), 0) + } + } + + + /** + * Кейс когда числа дающие target находятся не на смежных индексах массива numbers + * */ + @Test + fun `testcase 5`() { + val actual = sumOfTwo(intArrayOf(3, 2, 3), 6) + val expected = intArrayOf(0, 2) + assertArrayEquals(expected, actual) + } } \ No newline at end of file