Skip to content

Commit 8ada223

Browse files
committed
1 parent e87a68a commit 8ada223

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# [Sentence Calculator](https://www.codewars.com/kata/sentence-calculator "https://www.codewars.com/kata/5970fce80ed776b94000008b")
22

3-
<h3>Sentence Calculator</h3>
3+
Calculate the total score (sum of the individual character scores) of a sentence given the following score rules for each allowed group of
4+
characters:
45

5-
Calculate the total score (sum of the individual character scores) of a sentence given the following score rules for each allowed group of characters:
6-
1. Lower case [a-z]: 'a'=1, 'b'=2, 'c'=3, ..., 'z'=26
7-
2. Upper case [A-Z]: 'A'=2, 'B'=4, 'C'=6, ..., 'Z'=52
8-
3. Digits [0-9] their numeric value: '0'=0, '1'=1, '2'=2, ..., '9'=9
9-
4. Other characters: 0 value
6+
1. Lower case [a-z]: 'a'=1, 'b'=2, 'c'=3, ..., 'z'=26
7+
2. Upper case [A-Z]: 'A'=2, 'B'=4, 'C'=6, ..., 'Z'=52
8+
3. Digits [0-9] their numeric value: '0'=0, '1'=1, '2'=2, ..., '9'=9
9+
4. Other characters: 0 value
1010

11-
<em>Note: input will always be a string</em>
11+
*Note: input will always be a string*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface SentenceCalculator {
2+
static int lettersToNumbers(String s) {
3+
return s.replaceAll("\\W", "").chars().map(c -> c < 48 ? 0 : c < 58 ? c - 48 : c < 91 ? 2 * (c - 64) : c - 96).sum();
4+
}
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import static org.junit.jupiter.api.Assertions.assertEquals;
2+
3+
import org.junit.jupiter.params.ParameterizedTest;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
6+
class SampleTests {
7+
@ParameterizedTest
8+
@CsvSource(delimiter = '|', textBlock = """
9+
Give me 5! | 73
10+
Give me five! | 110
11+
oops, i did it again! | 152
12+
I Love You | 170
13+
ILoveYou | 170
14+
ARE YOU HUNGRY? | 356
15+
""")
16+
void sample(String input, int expected) {
17+
assertEquals(expected, SentenceCalculator.lettersToNumbers(input));
18+
}
19+
}

0 commit comments

Comments
 (0)