From 0638ab7bcfa5c81d5f280428dc608e16eecf26fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B0=D0=B7=D1=83=D0=BD=D0=B8=D0=BD=20=D0=90=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=95=D0=B2=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D1=8C=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 20 Apr 2026 19:44:27 +0300 Subject: [PATCH 1/3] Tasks "fizzbuzz" and "sumoftwo" completed --- settings.gradle | 3 ++ src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 19 +++++++++- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 39 +++++++++++++++++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/settings.gradle b/settings.gradle index 995211b..0171928 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,2 +1,5 @@ +plugins { + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.10.0' +} rootProject.name = 'homework01' diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 6e04be1..8c3e52b 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -2,5 +2,22 @@ package ru.otus.homework fun fizzbuzz(n: Int): Array { - TODO("Выполните задание") + if(n <= 0){ + return emptyArray() + } + + val tempArray: Array = Array(size = n) { it } + + val resArray: Array = Array(size = n){""} + + for(i in 0.. "FizzBuzz" + (i % 3 == 0) -> "Fizz" + (i % 5 == 0) -> "Buzz" + else -> i.toString() + } + } + + return resArray } \ 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..4d6e8ff 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -2,5 +2,42 @@ package ru.otus.homework fun sumOfTwo(numbers: IntArray, target: Int): IntArray { - TODO("Выполните задание") + if(numbers.isEmpty()){ + return IntArray(size = 0) + } + + for(i in 1..numbers.size){ + val indexes: IntArray = IntArray(size = i){it} + + do{ + // calculate sum of current elements + var sum: Int = 0 + for(j in indexes){ + sum += numbers[j] + } + + // if sum equal target then return array of indexes + if(sum == target){ + return indexes + } + + var endOfCycle: Boolean = true + // check if we can create new combination of the indexes + findIndexLoop@ for(index in indexes.lastIndex downTo 0){ + if(indexes[index] < numbers.lastIndex - (indexes.lastIndex - index)){ + // index not in the end + // create new combination - move this index one step right + // follow indexes set right behind it + indexes[index] ++; + for(k in index + 1 .. indexes.lastIndex){ + indexes[k] = indexes[k-1] + 1 + endOfCycle = false + break@findIndexLoop + } + } + } + }while(!endOfCycle) + } + + throw IllegalArgumentException("Target is impossible") } \ No newline at end of file From fec05f3d5bec793fdbbf862da2d01058c425c5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B0=D0=B7=D1=83=D0=BD=D0=B8=D0=BD=20=D0=90=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=95=D0=B2=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D1=8C=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 20 Apr 2026 19:48:56 +0300 Subject: [PATCH 2/3] Clear programm code from warnings --- src/main/kotlin/ru/otus/homework/fizzbuzz.kt | 2 +- src/main/kotlin/ru/otus/homework/sumoftwo.kt | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt index 8c3e52b..33e6c51 100644 --- a/src/main/kotlin/ru/otus/homework/fizzbuzz.kt +++ b/src/main/kotlin/ru/otus/homework/fizzbuzz.kt @@ -10,7 +10,7 @@ fun fizzbuzz(n: Int): Array { val resArray: Array = Array(size = n){""} - for(i in 0.. "FizzBuzz" (i % 3 == 0) -> "Fizz" diff --git a/src/main/kotlin/ru/otus/homework/sumoftwo.kt b/src/main/kotlin/ru/otus/homework/sumoftwo.kt index 4d6e8ff..579f96d 100644 --- a/src/main/kotlin/ru/otus/homework/sumoftwo.kt +++ b/src/main/kotlin/ru/otus/homework/sumoftwo.kt @@ -7,11 +7,11 @@ fun sumOfTwo(numbers: IntArray, target: Int): IntArray { } for(i in 1..numbers.size){ - val indexes: IntArray = IntArray(size = i){it} + val indexes = IntArray(size = i){it} do{ // calculate sum of current elements - var sum: Int = 0 + var sum = 0 for(j in indexes){ sum += numbers[j] } @@ -21,14 +21,14 @@ fun sumOfTwo(numbers: IntArray, target: Int): IntArray { return indexes } - var endOfCycle: Boolean = true + var endOfCycle = true // check if we can create new combination of the indexes findIndexLoop@ for(index in indexes.lastIndex downTo 0){ if(indexes[index] < numbers.lastIndex - (indexes.lastIndex - index)){ // index not in the end // create new combination - move this index one step right // follow indexes set right behind it - indexes[index] ++; + indexes[index] ++ for(k in index + 1 .. indexes.lastIndex){ indexes[k] = indexes[k-1] + 1 endOfCycle = false From 5295dad6f91471e40fd5e0a96e45223a1c90f141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B0=D0=B7=D1=83=D0=BD=D0=B8=D0=BD=20=D0=90=D0=BB?= =?UTF-8?q?=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=95=D0=B2=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D1=8C=D0=B5=D0=B2=D0=B8=D1=87?= Date: Mon, 20 Apr 2026 19:53:49 +0300 Subject: [PATCH 3/3] Add file gradle-daemon-jvm.properties --- gradle/gradle-daemon-jvm.properties | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 gradle/gradle-daemon-jvm.properties diff --git a/gradle/gradle-daemon-jvm.properties b/gradle/gradle-daemon-jvm.properties new file mode 100644 index 0000000..382c699 --- /dev/null +++ b/gradle/gradle-daemon-jvm.properties @@ -0,0 +1,3 @@ +#This file is generated by updateDaemonJvm +toolchainVendor=jetbrains +toolchainVersion=21