Skip to content

Commit 6a2bbe9

Browse files
* docs: kata description * feat: kata/sentence-calculator * refactor: remove unreachable condition --------- Co-authored-by: ParanoidUser <[email protected]>
1 parent d1e513c commit 6a2bbe9

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

kata/6-kyu/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@
308308
- [Row of the odd triangle](row-of-the-odd-triangle "5d5a7525207a674b71aa25b5")
309309
- [Salesman's Travel](salesmans-travel "56af1a20509ce5b9b000001e")
310310
- [Same matrix (2 * 2)](same-matrix-2-star-2 "635fc0497dadea0030cb7936")
311+
- [Sentence Calculator](sentence-calculator "5970fce80ed776b94000008b")
311312
- [Separate The Wheat From The Chaff](separate-the-wheat-from-the-chaff "5bdcd20478d24e664d00002c")
312313
- [Sequence convergence](sequence-convergence "59971e64bfccc70748000068")
313314
- [Sequences and Series](sequences-and-series "5254bd1357d59fbbe90001ec")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# [Sentence Calculator](https://www.codewars.com/kata/sentence-calculator "https://www.codewars.com/kata/5970fce80ed776b94000008b")
2+
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:
5+
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
10+
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 < 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)