File tree Expand file tree Collapse file tree 4 files changed +80
-1
lines changed
Expand file tree Collapse file tree 4 files changed +80
-1
lines changed Original file line number Diff line number Diff line change 146146- [ Multiply] ( multiply " 50654ddff44f800200000004 ")
147147- [ My head is at the wrong end!] ( my-head-is-at-the-wrong-end " 56f699cd9400f5b7d8000b55 ")
148148- [ Name on billboard] ( name-on-billboard " 570e8ec4127ad143660001fd ")
149+ - [ Neutralisation] ( neutralisation " 65128732b5aff40032a3d8f0 ")
149150- [ Never visit a . . . !?] ( never-visit-a " 56c5847f27be2c3db20009c3 ")
150151- [ No zeros for heroes] ( no-zeros-for-heros " 570a6a46455d08ff8d001002 ")
151152- [ OOP: Object Oriented Piracy ] ( oop-object-oriented-piracy " 54fe05c4762e2e3047000add ")
180181- [ Rock Paper Scissors!] ( rock-paper-scissors " 5672a98bdbdd995fad00000f ")
181182- [ Sentence Smash] ( sentence-smash " 53dc23c68a0c93699800041d ")
182183- [ Short Long Short] ( short-long-short " 50654ddff44f800200000007 ")
183- - [ simple calculator ] ( simple-calculator " 5810085c533d69f4980001cf ")
184+ - [ Simple calculator ] ( simple-calculator " 5810085c533d69f4980001cf ")
184185- [ Simple Fun #1 : Seats in Theater] ( simple-fun-number-1-seats-in-theater " 588417e576933b0ec9000045 ")
185186- [ Simple multiplication] ( simple-multiplication " 583710ccaa6717322c000105 ")
186187- [ Simple validation of a username with regex] ( simple-validation-of-a-username-with-regex " 56a3f08aa9a6cc9b75000023 ")
Original file line number Diff line number Diff line change 1+ # [ Neutralisation] ( https://www.codewars.com/kata/neutralisation " https://www.codewars.com/kata/65128732b5aff40032a3d8f0 ")
2+
3+ Given two strings comprised of ` + ` and ` - ` , return a new string which shows how the two strings interact in the following way:
4+
5+ - When positives and positives interact, they * remain positive* .
6+ - When negatives and negatives interact, they * remain negative* .
7+ - But when negatives and positives interact, they * become neutral* , and are shown as the number ` 0 ` .
8+
9+ ### Worked Example
10+
11+ ```
12+ ("+-+", "+--") ➞ "+-0"
13+ # Compare the first characters of each string, then the next in turn.
14+ # "+" against a "+" returns another "+".
15+ # "-" against a "-" returns another "-".
16+ # "+" against a "-" returns "0".
17+ # Return the string of characters.
18+ ```
19+
20+ ### Examples
21+
22+ ```
23+ ("--++--", "++--++") ➞ "000000"
24+
25+ ("-+-+-+", "-+-+-+") ➞ "-+-+-+"
26+
27+ ("-++-", "-+-+") ➞ "-+00"
28+ ```
29+
30+ ### Notes
31+
32+ The two strings will be the same length.
Original file line number Diff line number Diff line change 1+ import static java .util .stream .Collectors .joining ;
2+ import static java .util .stream .IntStream .range ;
3+
4+ interface Solution {
5+ static String neutralise (String s1 , String s2 ) {
6+ return range (0 , s1 .length ()).mapToObj (i -> s1 .charAt (i ) == s2 .charAt (i ) ? s1 .charAt (i ) + "" : "0" ).collect (joining ());
7+ }
8+ }
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 SolutionTest {
7+ @ ParameterizedTest
8+ @ CsvSource (textBlock = """
9+ '','',''
10+ +,+,+
11+ -,-,-
12+ +,-,0
13+ -,+,0
14+ -+,++,0+
15+ --,-+,-0
16+ +--,+--,+--
17+ -++,-+-,-+0
18+ +-+,-++,00+
19+ -++,+--,000
20+ -++-,-+-+,-+00
21+ --++,++++,00++
22+ ---+,-+++,-00+
23+ -----,-----,-----
24+ --++--,++--++,000000
25+ -+-+-+,-+-+-+,-+-+-+
26+ +-----+-,---++-++,0--00-+0
27+ --+++-+-,+++++---,00+++-0-
28+ +++--+---,++----++-,++0--000-
29+ -++-+-++-,+-++++---,00+0+000-
30+ ---++-+--,-+++--++-,-00+0-+0-
31+ ++-++--++-,-+++-++-++,0+0+0000+0
32+ +-----+++-,--+-+-++--,0-0-0-++0-
33+ -+--+-+---,-+--+-+-+-,-+--+-+-0-
34+ """ )
35+ void sample (String s1 , String s2 , String expected ) {
36+ assertEquals (expected , Solution .neutralise (s1 , s2 ));
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments