From 2246a9da7c9015941048b42ab331eb6c92036699 Mon Sep 17 00:00:00 2001 From: Dima_ Date: Mon, 17 Apr 2023 15:38:40 +0300 Subject: [PATCH 1/3] add realization in fizzbuzz function --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index cf6e9f6..7fc270a 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -1,5 +1,21 @@ package ru.otus.homework -fun fizzbuzz(n: Int): Array { +fun fizzbuzz(n: Int): Array { + val outputArray: Array = Array(n){""} + + for (i in n - 1 downTo 0) { + + if (i%3 == 0 && i%5 != 0) { + outputArray[i] = "Fizz" + } else if (i%5 == 0 && i%3 != 0) { + outputArray[i] = "Buzz" + } else if (i == 0 || i%3 == 0 && i%5 ==0) { + outputArray[i] = "FizzBuzz" + } else { + outputArray[i] = i.toString() + } + } + + return outputArray } \ No newline at end of file From b0c30ea664683f326952f0e2bd41a07321bdc7f8 Mon Sep 17 00:00:00 2001 From: Dima_ Date: Wed, 19 Apr 2023 13:23:10 +0300 Subject: [PATCH 2/3] add realization in sumOfTwo function --- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index d92d467..593b5b7 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,4 +2,27 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { -} \ No newline at end of file + val arrIndexes = IntArray(2) + var sum: Int + + if (numbers.size < 2) throw IllegalArgumentException() + + for ((k, value) in numbers.withIndex()) { + for ((i, value) in numbers.withIndex()) { + if (k == i) { + continue + } else { + sum = numbers[k] + numbers[i] + + if (sum == target) { + arrIndexes[0] = i + arrIndexes[1] = k + } + } + } + } + + if (arrIndexes[0] == 0 && arrIndexes[1] == 0) throw IllegalArgumentException() + + return arrIndexes +} From c647b400b33bd3bcd074d07bfca9f706d79e5065 Mon Sep 17 00:00:00 2001 From: Dima_ Date: Fri, 21 Apr 2023 15:58:41 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B7=D0=B0=D0=BC=D0=B5=D1=87=D0=B0=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=BF=D0=BE=202=20=D0=B7=D0=B0=D0=B4=D0=B0=D1=87=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 593b5b7..1a979e6 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,8 +2,6 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - val arrIndexes = IntArray(2) - var sum: Int if (numbers.size < 2) throw IllegalArgumentException() @@ -12,17 +10,12 @@ fun sumOfTwo(numbers: IntArray, target: Int): IntArray { if (k == i) { continue } else { - sum = numbers[k] + numbers[i] - - if (sum == target) { - arrIndexes[0] = i - arrIndexes[1] = k + if (numbers[k] + numbers[i] == target) { + return intArrayOf(k, i) } } } } - if (arrIndexes[0] == 0 && arrIndexes[1] == 0) throw IllegalArgumentException() - - return arrIndexes + throw IllegalArgumentException() }