Skip to content

Commit 33ff883

Browse files
committed
2020-12-25 Update: Added "RGB To Hex Conversion" and "Leap Year"
1 parent 88b3723 commit 33ff883

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Profile on Codewars: [fartem](https://www.codewars.com/users/fartem).
3232
| Even numbers in an array | [Link](https://www.codewars.com/kata/5a431c0de1ce0ec33a00000c) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu7/EvenNumbersInAnArray.kt) |
3333
| Find Screen Size | [Link](https://www.codewars.com/kata/5bbd279c8f8bbd5ee500000f) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu7/FindScreenSize.kt) |
3434
| Hide password from jdbc url | [Link](https://www.codewars.com/kata/5a726f16373c2ee6c60000db) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu7/HidePasswordFromJDBCUrl.kt) |
35+
| Leap Year | [Link](https://www.codewars.com/kata/526c7363236867513f0005ca) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu7/LeapYear.kt) |
3536
| Move 10 | [Link](https://www.codewars.com/kata/57cf50a7eca2603de0000090) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu7/Move10.kt) |
3637
| Plus - minus - plus - plus - ... - Count | [Link](https://www.codewars.com/kata/5bbb8887484fcd36fb0020ca) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu7/PlusMinusPlusPlusCount.kt) |
3738
| Predict your age! | [Link](https://www.codewars.com/kata/5aff237c578a14752d0035ae) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu7/PredictYourAge.kt) |
@@ -47,6 +48,12 @@ Profile on Codewars: [fartem](https://www.codewars.com/users/fartem).
4748
| HTML dynamic color string generation | [Link](https://www.codewars.com/kata/56f1c6034d0c330e4a001059) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu6/HTMLDynamicColorStringGeneration.kt) |
4849
| Java format Unicode encoder/decorder | [Link](https://www.codewars.com/kata/58e2c062542a419083000033) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu6/JavaFormatUnicodeEncoderDecoder.kt) |
4950

51+
### 5 kyu
52+
53+
| Name | Link to Codewars | Link to solution |
54+
| --- | --- | --- |
55+
| RGB To Hex Conversion | [Link](https://www.codewars.com/kata/513e08acc600c94f01000001) | [Link](./src/main/kotlin/com/smlnskgmail/jaman/codewarskotlin/kyu5/RGBToHexConversion.kt) |
56+
5057
### 4 kyu
5158

5259
| Name | Link to Codewars | Link to solution |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.smlnskgmail.jaman.codewarskotlin.kyu5
2+
3+
// https://www.codewars.com/kata/513e08acc600c94f01000001
4+
class RGBToHexConversion(
5+
private val r: Int,
6+
private val g: Int,
7+
private val b: Int
8+
) {
9+
10+
fun solution(): String {
11+
@Suppress("MagicNumber")
12+
return "%02X%02X%02X".format(
13+
r.coerceIn(0..255),
14+
g.coerceIn(0..255),
15+
b.coerceIn(0..255)
16+
)
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.smlnskgmail.jaman.codewarskotlin.kyu7
2+
3+
// https://www.codewars.com/kata/526c7363236867513f0005ca
4+
class LeapYear(private val input: Int) {
5+
6+
fun solution(): Boolean {
7+
@Suppress("MagicNumber")
8+
return input % 4 == 0 && (input % 400 == 0 || input % 100 != 0)
9+
}
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.smlnskgmail.jaman.codewarskotlin.kyu5
2+
3+
import org.junit.Assert.assertEquals
4+
import org.junit.Test
5+
6+
class RGBToHexConversionTest {
7+
8+
@Test
9+
fun testFixed() {
10+
assertEquals(
11+
"000000",
12+
RGBToHexConversion(0, 0, 0).solution()
13+
)
14+
assertEquals(
15+
"000000",
16+
RGBToHexConversion(0, 0, -20).solution()
17+
)
18+
assertEquals(
19+
"FFFFFF",
20+
RGBToHexConversion(300, 255, 255).solution()
21+
)
22+
assertEquals(
23+
"ADFF2F",
24+
RGBToHexConversion(173, 255, 47).solution()
25+
)
26+
assertEquals(
27+
"9400D3",
28+
RGBToHexConversion(148, 0, 211).solution()
29+
)
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.smlnskgmail.jaman.codewarskotlin.kyu7
2+
3+
import org.junit.Assert.assertFalse
4+
import org.junit.Assert.assertTrue
5+
import org.junit.Test
6+
7+
class LeapYearTest {
8+
9+
@Test
10+
fun `Basic Tests`() {
11+
assertFalse(LeapYear(1234).solution())
12+
assertTrue(LeapYear(1984).solution())
13+
assertTrue(LeapYear(2000).solution())
14+
assertFalse(LeapYear(2010).solution())
15+
assertFalse(LeapYear(2013).solution())
16+
}
17+
18+
}

0 commit comments

Comments
 (0)