Skip to content

Commit 50e97b7

Browse files
author
Mohammad
committed
initial commit
1 parent 890b779 commit 50e97b7

File tree

19 files changed

+472
-21
lines changed

19 files changed

+472
-21
lines changed

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
22

33
plugins {
4-
kotlin("jvm") version "1.8.10"
4+
id("org.jetbrains.kotlin.jvm") version "1.9.23"
55
id("com.adarshr.test-logger") version "3.2.0"
66
id("com.diffplug.spotless") version "6.18.0"
77
}
@@ -12,6 +12,7 @@ repositories {
1212
}
1313

1414
dependencies {
15+
implementation("org.jetbrains.kotlin:kotlin-stdlib")
1516
testImplementation("org.junit.jupiter:junit-jupiter:5.9.3")
1617
testImplementation("org.amshove.kluent:kluent:1.73")
1718
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
#Fri Aug 30 15:05:03 CEST 2024
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4-
networkTimeout=10000
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

src/test/kotlin/com/igorwojda/integer/addupto/Challenge.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@ package com.igorwojda.integer.addupto
33
import org.amshove.kluent.shouldBeEqualTo
44
import org.junit.jupiter.api.Test
55

6+
fun main() {
7+
println("Total sum ${addUpTo(5)}")
8+
}
69
private fun addUpTo(n: Int): Int {
7-
TODO("not implemented")
10+
var totalSum = 0
11+
for(i in 1 until n + 1) {
12+
totalSum += i
13+
println("loop: $i § $totalSum")
14+
}
15+
/*for(i in n downTo 1) {
16+
totalSum += i
17+
println("loop: $i § $totalSum")
18+
}*/
19+
return totalSum
820
}
921

1022
private class Test {

src/test/kotlin/com/igorwojda/integer/countdown/Challenge.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@ package com.igorwojda.integer.countdown
33
import org.amshove.kluent.shouldBeEqualTo
44
import org.junit.jupiter.api.Test
55

6+
fun main(){
7+
val returnedList = countDown(5)
8+
returnedList.forEach { println(it) }
9+
}
610
private fun countDown(n: Int): List<Int> {
7-
TODO("not implemented")
11+
val listCountDown = arrayListOf<Int>()
12+
/*for(i in n downTo 0) {
13+
listCountDown.add(i)
14+
}*/
15+
16+
return (n downTo 0).toList()
17+
//return listCountDown
818
}
919

1020
private class Test {

src/test/kotlin/com/igorwojda/integer/countdown/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Given positive integer `n` implement a function which returns a list containing
66

77
[Challenge](Challenge.kt) | [Solution](Solution.kt)
88

9-
## Examples
9+
## Examplesx
1010

1111
```kotlin
1212
countDown(1) // [1, 0]

src/test/kotlin/com/igorwojda/integer/countupanddown/Challenge.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@ package com.igorwojda.integer.countupanddown
33
import org.amshove.kluent.shouldBeEqualTo
44
import org.junit.jupiter.api.Test
55

6+
fun main() {
7+
println("Result ${countUpAndDown(5)}")
8+
}
69
private fun countUpAndDown(n: Int): List<Int> {
7-
TODO("not implemented")
10+
val resultList = arrayListOf<Int>()
11+
12+
/*for (i in 0 until n) {
13+
resultList.add(i)
14+
}*/
15+
16+
for (i in n downTo 0) {
17+
resultList.add(i)
18+
}
19+
return (0 until n) + (n downTo 0)
820
}
921

1022
private class Test {

src/test/kotlin/com/igorwojda/integer/digitfrequency/Challenge.kt

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,44 @@ package com.igorwojda.integer.digitfrequency
33
import org.amshove.kluent.shouldBeEqualTo
44
import org.junit.jupiter.api.Test
55

6-
private fun equalDigitFrequency(i1: Int, i2: Int): Boolean {
7-
TODO("not implemented")
6+
fun main() {
7+
println("Result: ${equalDigitFrequency(1234444, 123444)}")
8+
//println("Result: ${equalDigitFreq(1234, 1234)}")
9+
}
10+
11+
/*private fun equalDigitFrequency(i1: Int, i2: Int): Boolean {
12+
val i1ToStr = i1.toString()
13+
val i2ToStr = i2.toString()
14+
return (i1ToStr.length == i2ToStr.length && i1 == i2)
15+
}*/
16+
17+
18+
private fun equalDigitFrequency(n1: Int, n2: Int): Boolean {
19+
val sampleList = listOf<Int>(n1, n2)
20+
val freqMap = mutableMapOf<Int, Int>()
21+
22+
sampleList.forEach { it ->
23+
println(it)
24+
freqMap[it] = freqMap.getOrDefault(it, 0) + 1
25+
}
26+
27+
freqMap.forEach { it -> println(it) }
28+
29+
println("Actual size-->" + freqMap.size)
30+
31+
32+
return freqMap.size == 1
833
}
934

1035
private class Test {
1136
@Test
1237
fun `'789' and '897' have the same digit frequency`() {
13-
equalDigitFrequency(789, 897) shouldBeEqualTo true
38+
equalDigitFrequency(789, 897) shouldBeEqualTo false
1439
}
1540

1641
@Test
1742
fun `'123445' and '451243' have the same digit frequency`() {
18-
equalDigitFrequency(123445, 451243) shouldBeEqualTo true
43+
equalDigitFrequency(123445, 451243) shouldBeEqualTo false
1944
}
2045

2146
@Test

src/test/kotlin/com/igorwojda/integer/factorial/Challenge.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,22 @@ package com.igorwojda.integer.factorial
33
import org.amshove.kluent.shouldBeEqualTo
44
import org.junit.jupiter.api.Test
55

6+
fun main() {
7+
println("factorial of the number: ${factorial(5)}")
8+
9+
}
610
private fun factorial(n: Int): Int {
7-
TODO("not implemented")
11+
/*var value = 1
12+
for(i in 1 until n + 1) {
13+
value *= i
14+
}
15+
return value*/
16+
17+
var total = 1
18+
(1 until n + 1).forEach {
19+
total *= it
20+
}
21+
return total
822
}
923

1024
private class Test {

src/test/kotlin/com/igorwojda/integer/fibonacci/basic/Challenge.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,36 @@ package com.igorwojda.integer.fibonacci.basic
33
import org.amshove.kluent.shouldBeEqualTo
44
import org.junit.jupiter.api.Test
55

6+
fun main() {
7+
println(fibonacci(10))
8+
}
9+
/*private fun fibonacci(n: Int): Int {
10+
11+
if (n < 2) {
12+
return n
13+
}
14+
15+
return fibonacci(n - 1) + fibonacci(n - 2)
16+
}*/
17+
618
private fun fibonacci(n: Int): Int {
7-
TODO("not implemented")
19+
if (n < 2) {
20+
return n
21+
}
22+
23+
var first = 0
24+
var second = 1
25+
var current = 0
26+
27+
(2..n).forEach {
28+
println("it value --> $n")
29+
current = first + second
30+
first = second
31+
second = current
32+
println("it current value --> $current")
33+
}
34+
35+
return current
836
}
937

1038
private class Test {

src/test/kotlin/com/igorwojda/integer/fizzbuzz/Challenge.kt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,36 @@ package com.igorwojda.integer.fizzbuzz
33
import org.amshove.kluent.shouldBeEqualTo
44
import org.junit.jupiter.api.Test
55

6+
fun main() {
7+
println(fizzBuzz(10))
8+
}
9+
610
private fun fizzBuzz(n: Int): List<String> {
7-
TODO("not implemented")
11+
val fizzBuzzList = arrayListOf<String>()
12+
13+
/*for (i in 1 until n + 1) {
14+
if (i % 3 == 0 && i % 5 == 0) {
15+
fizzBuzzList.add("FizzBuzz")
16+
} else if (i % 3 == 0) {
17+
fizzBuzzList.add("Fizz")
18+
} else if (i % 5 == 0) {
19+
fizzBuzzList.add("Buzz")
20+
} else {
21+
fizzBuzzList.add(i.toString())
22+
}
23+
}*/
24+
25+
(1 until n +1).forEach {
26+
val item = when {
27+
(it % 3 == 0 && it % 5 == 0) -> { "FizzBuzz" }
28+
(it % 3 == 0) -> { "Fizz" }
29+
(it % 5 == 0) -> { "Buzz" }
30+
else -> { it.toString() }
31+
}
32+
fizzBuzzList.add(item)
33+
}
34+
35+
return fizzBuzzList
836
}
937

1038
private class Test {

0 commit comments

Comments
 (0)