Tricky Kotlin #7: Do multiple replacement
Description:
This is a series of Kotlin tricks.
This time! We're gonna do a code golf (it doesn't matter if you don't understand this phrase)!
Maybe you're fed up with those advanced language features in the recent Tricky Kotlin Katas, so this time let's take a look into Kotlin's standard library.
I have a string with wrong directed paranthesis, I want to replace ( with ) and ) with ( and <** with **> and > with **<** and **{** with **}** and **}** with **{** at same time, you should do it with a single **replace** method.
For example I have this string : You }}need{{ >extra< time ) or money (
Which should be like this : You {{need}} <extra> time ( or money )
You shouldn't use split
.
Since this is a code golf, you should write only one line of code, and less than 95 characters.
Empty lines are ignored so don't worry.
The final solution will fail if:
- You used split (don't use this word in your comments)
- You used more than 1 non-empty lines of code
- You used more than 95 characters
I will not check for multiple use of replace
s, but I recommend you to use only one.
My solution is of 90 characters. Have fun!
Similar Kata:
Stats:
Created | Jan 8, 2018 |
Published | Jan 8, 2018 |
Warriors Trained | 456 |
Total Skips | 86 |
Total Code Submissions | 987 |
Total Times Completed | 137 |
Kotlin Completions | 137 |
Total Stars | 14 |
% of votes with a positive feedback rating | 100% of 34 |
Total "Very Satisfied" Votes | 34 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 3 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 6 kyu |