+ 14
🏆 [M💙 Challenge] Substring Reversal
Monday Blue 💙 Challenge Series #1 Write a program to accept both { string } and { length } to perform reverse on each of the substrings of the given length. Here are the test cases of "123456789":- ☑ Length 1 output: "123456789" ☑ Length 2 output: " 214365879" ☑ Length 3 output: "321654987" Assumption: 1 ≤ length ≤ string's length Happy Coding!!! 😁💻
20 Antworten
+ 10
> I'm loving Ruby..
> https://code.sololearn.com/cWKIN047NQMs
+ 11
@ysraelcon Another creative use of regex! You reminds me about the comic strip by xkcd below and it seems almost anything can be solved by regex. 😂
By ysraelcon 👇👍
https://code.sololearn.com/WP35CG6WZ66D/?ref=app
https://code.sololearn.com/WiBHxBs0BFmX/?ref=app
+ 11
https://code.sololearn.com/cmf0LR6eXRiw/#cs
My solution in C# :) .
+ 8
heres mine...
prints all possibility
##
https://code.sololearn.com/cdLqa08Oh7d7/?ref=app
+ 6
@Calvin Good job! We need a general approach to accept any length of substring with the constraint above by using one function only. I believe you can do it! 😄
+ 6
Here's my own C# implementation! ✌
LINQ One-Liner〰
string.Concat(
Enumerable.Range(0, input.Length)
.GroupBy(i => i / length)
.Select(g => string.concat(
g.Select(i => input[i])
.Reverse())))
Yup it's a LINQ solution again~ Enjoy! ❤
https://code.sololearn.com/c3QVlZ739VTl/?ref=app
+ 5
https://code.sololearn.com/WPA0zG5EI6i7/?ref=app
+ 5
@Zephyr: Thanks for mark mine as best answer! 😊👍
+ 5
@noobcøder You're welcome! 😄
Well the best answer was selected after every week, perhaps you're too busy to get notified about it. 😂
Glad that there are people still interested with the challenge since I BUMP it unintentionally by standardizing the tags across my post.
Thank you everyone again! 👍
+ 4
my one https://code.sololearn.com/WP35CG6WZ66D/?ref=app
example:
text: Sololearn
nro: 3
output: loSelonra
+ 4
My solution in python:
https://code.sololearn.com/cqVFK1xC4qFP/?ref=app
+ 4
My second solution in python. A bit longer but much better to anderstand:
https://code.sololearn.com/csd9zxe2cyt2/?ref=app
+ 4
Here you are.
https://code.sololearn.com/cbzvVc26NbeC/?ref=app
+ 3
+ 3
Here You go in Java. Checks for valid length input.
https://code.sololearn.com/cpwnmPxC5VtV/?ref=app
+ 3
https://code.sololearn.com/cMEgzsZh8s8L/?ref=app
+ 1
I will try
- 1
HERES A NEW CHALLENGE
CHECK IT AND TRY IF YOU WANT
https://www.sololearn.com/discuss/793924/?ref=app