From 614f9dc1a6772b13d178771f4c08248c5c096cd0 Mon Sep 17 00:00:00 2001 From: "d.boldyrev" Date: Thu, 20 Feb 2025 11:37:46 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=94=D0=97=20homework01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 20 ++++++++++++++++++-- 1 file changed, 18 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..973b0cf 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,6 +1,22 @@ package ru.otus.homework - fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + var i = 0 + val arrInt = Array(n, {i++}) + val arrStr = Array(n, {""}) + + i = 0 + for (elem in arrInt) { + if ((elem % 3) == 0) { + arrStr[i] += "Fizz" + } + if ((elem % 5) == 0) { + arrStr[i] += "Buzz" + } + if (arrStr[i] == "") { + arrStr[i] = "$elem" + } + i++ + } + return arrStr } \ No newline at end of file From b58f0ed5ee6e3e2a1d96741d7c32cc4007e75ca7 Mon Sep 17 00:00:00 2001 From: "d.boldyrev" Date: Thu, 20 Feb 2025 11:37:55 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=94=D0=97=20homework01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 70d72e5..e7afb21 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,6 +1,20 @@ package ru.otus.homework - fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + var i = 0 + var j = 1 + + if (numbers.size < 2) + throw IllegalArgumentException("size < 2") + while (i <= numbers.size-2) { + while (j <= numbers.size-1) { + if (numbers[i] + numbers[j] == target) { + return intArrayOf(numbers[i], numbers[j]) + } + ++j + } + ++i + j = i + 1 + } + throw IllegalArgumentException("Not found") } \ No newline at end of file From dc5f0391670731bf484194208dd0248d2e861c40 Mon Sep 17 00:00:00 2001 From: "d.boldyrev" Date: Thu, 20 Feb 2025 11:58:22 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=94=D0=97=20homework01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index e7afb21..783d7de 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,5 +1,11 @@ package ru.otus.homework +fun main() { + val arr : IntArray = intArrayOf(1, 2, 3, 4, 5) + val res : IntArray = sumOfTwo(arr, 9) + print("${res[0]} ${res[1]}") +} + fun sumOfTwo(numbers: IntArray, target: Int): IntArray { var i = 0 var j = 1 @@ -9,7 +15,7 @@ fun sumOfTwo(numbers: IntArray, target: Int): IntArray { while (i <= numbers.size-2) { while (j <= numbers.size-1) { if (numbers[i] + numbers[j] == target) { - return intArrayOf(numbers[i], numbers[j]) + return intArrayOf(i, j) } ++j } From 8539f59e79bc46cb7e14b9a219a9b997dfca1a1c Mon Sep 17 00:00:00 2001 From: "d.boldyrev" Date: Thu, 20 Feb 2025 11:58:50 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=94=D0=97=20homework01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 783d7de..a6a2697 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -1,11 +1,5 @@ package ru.otus.homework -fun main() { - val arr : IntArray = intArrayOf(1, 2, 3, 4, 5) - val res : IntArray = sumOfTwo(arr, 9) - print("${res[0]} ${res[1]}") -} - fun sumOfTwo(numbers: IntArray, target: Int): IntArray { var i = 0 var j = 1