-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(8-kyu): kata/multiply-the-number
- Loading branch information
1 parent
d6fed40
commit 5ed0b07
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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¹ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
kata/8-kyu/multiply-the-number/test/MultiplyExampleTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |