Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ParanoidUser committed Feb 18, 2024
1 parent d6fed40 commit 5ed0b07
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions kata/8-kyu/multiply-the-number/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# [Multiply the number](https://www.codewars.com/kata/multiply-the-number "https://www.codewars.com/kata/5708f682c69b48047b000e07")

Jack really likes his number five: the trick here is that you have to multiply each number by 5 raised to the number of
digits of each number, so, for example:

```
Kata.multiply(3) == 15 // 3 * 5¹
Kata.multiply(10) == 250 // 10 * 5²
Kata.multiply(200) == 25000 // 200 * 5³
Kata.multiply(0) == 0 // 0 * 5¹
Kata.multiply(-3) == -15 // -3 * 5¹
```
5 changes: 5 additions & 0 deletions kata/8-kyu/multiply-the-number/main/Kata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface Kata {
static int multiply(int number) {
return number * (int) Math.pow(5, (int) (Math.log10(Math.abs(number)) + 1));
}
}
16 changes: 16 additions & 0 deletions kata/8-kyu/multiply-the-number/test/MultiplyExampleTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class MultiplyExampleTests {
@Test
void sample() {
assertEquals(-15, Kata.multiply(-3));
assertEquals(0, Kata.multiply(0));
assertEquals(15, Kata.multiply(3));
assertEquals(250, Kata.multiply(10));
assertEquals(25000, Kata.multiply(200));
assertEquals(-3728750, Kata.multiply(-5966));
assertEquals(-2048000000, Kata.multiply(-131072));
}
}

0 comments on commit 5ed0b07

Please sign in to comment.