File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ # [ Char Code Calculation] ( https://www.codewars.com/kata/char-code-calculation " https://www.codewars.com/kata/57f75cc397d62fc93d000059 ")
2
+
3
+ Given a string, turn each character into its ASCII character code and join them together to create a number - let's call this number
4
+ ` total1 ` :
5
+
6
+ ```
7
+ 'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667
8
+ ```
9
+
10
+ Then replace any incidence of the number ` 7 ` with the number ` 1 ` , and call this number 'total2':
11
+
12
+ ```
13
+ total1 = 656667
14
+ ^
15
+ total2 = 656661
16
+ ^
17
+ ```
18
+
19
+ Then return the difference between the sum of the digits in ` total1 ` and ` total2 ` :
20
+
21
+ ```
22
+ (6 + 5 + 6 + 6 + 6 + 7)
23
+ - (6 + 5 + 6 + 6 + 6 + 1)
24
+ -------------------------
25
+ 6
26
+ ```
Original file line number Diff line number Diff line change
1
+ import static org .apache .commons .lang3 .StringUtils .countMatches ;
2
+
3
+ interface Kata {
4
+ static int calc (String x ) {
5
+ return 6 * x .chars ().map (i -> countMatches (i + "" , "7" )).sum ();
6
+ }
7
+ }
Original file line number Diff line number Diff line change
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 CharCodeCalculationTest {
7
+ @ ParameterizedTest
8
+ @ CsvSource (textBlock = """
9
+ M, 12
10
+ jaam, 12
11
+ abcdef, 6
12
+ ifkhchlhfd, 6
13
+ aaaaaddddr, 30
14
+ jfmgklf8hglbe, 6
15
+ abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ, 96
16
+ """ )
17
+ void sample (String s , int expected ) {
18
+ assertEquals (expected , Kata .calc (s ));
19
+ }
20
+ }
Original file line number Diff line number Diff line change 79
79
- [ Ch4113ng3] ( ch4113ng3 " 59e9f404fc3c49ab24000112 ")
80
80
- [ Change two-dimensional array] ( change-two-dimensional-array " 581214d54624a8232100005f ")
81
81
- [ Changing letters] ( changing-letters " 5831c204a31721e2ae000294 ")
82
+ - [ Char Code Calculation] ( char-code-calculation " 57f75cc397d62fc93d000059 ")
82
83
- [ Character Counter] ( character-counter " 56786a687e9a88d1cf00005d ")
83
84
- [ Check contained matrix] ( check-contained-matrix " 5a46179ce626c5ef8d000024 ")
84
85
- [ Check three and two] ( check-three-and-two " 5a9e86705ee396d6be000091 ")
You can’t perform that action at this time.
0 commit comments