+ 17

CHALLENGE: Strings stuff

The function takes 2 strings and returns false only if there is no way for you to: - choose a character index in the 2nd string as your starting point, - keep moving to the right or left char, - keep going until you eventually have read the 1st string. For instance: - "dcdcb" in "abcde", I can start at the 4th char ("d"), and do the following moves: ←→←←, so that at the end I got "dcdcb". It is possible, returns true. - "ac" in "abc", no solution exists, it returns false. Good luck!

10th Jan 2018, 1:43 AM
Dapper Mink
Dapper Mink - avatar
50 ответов
14th Jan 2018, 12:57 PM
Cépagrave
Cépagrave - avatar
+ 9
This is the latest one I came up with, and I low key know it will fail for some conditions. Will introduce a fix in future. https://code.sololearn.com/cwRBfMTNT27P/?ref=app
10th Jan 2018, 1:32 PM
Hatsy Rei
Hatsy Rei - avatar
+ 8
More or less dup-posting at this point, but this is the latest revision which takes care of the case stated by @Cpasgrave, as I have seen coming. https://code.sololearn.com/cwRBfMTNT27P/?ref=app
12th Jan 2018, 3:16 AM
Hatsy Rei
Hatsy Rei - avatar
+ 8
Here I present another miserable attempt at being relevant. https://code.sololearn.com/cQrt7eyuDA5K/#cpp
12th Jan 2018, 6:22 AM
Hatsy Rei
Hatsy Rei - avatar
12th Jan 2018, 3:49 PM
Hatsy Rei
Hatsy Rei - avatar
+ 8
Really nice explainations @Cpasgrave Thank you, you made me discover another totally valid way to do the challenge which I find really clever too :') Also congratulations!!
14th Jan 2018, 1:12 PM
Dapper Mink
Dapper Mink - avatar
+ 7
OK... at least now I understand the challenge (... change direction at anytime... ) and see why recursion would make life easier for this case. Will reattempt, hopefully without it.
10th Jan 2018, 12:55 PM
Hatsy Rei
Hatsy Rei - avatar
+ 7
Recursion was exactly the solution I expected :') I just coded my solution for it in C: https://code.sololearn.com/c4Odv4G9t0Ee/?ref=app I'm sorry for not being able to explain a challenge clearly, this one was weird tho
10th Jan 2018, 1:19 PM
Dapper Mink
Dapper Mink - avatar
+ 7
Thank you to you for solving it!! did not fully understand your code so I can't guarantee you successfully did it but I want to believe it :) Congratulations!
13th Jan 2018, 12:50 AM
Dapper Mink
Dapper Mink - avatar
+ 7
@Ipang, I tried my best (really hard with the character limit and my lack of creativity when it comes to write sentences ^^)
14th Jan 2018, 5:09 AM
Dapper Mink
Dapper Mink - avatar
+ 6
I think it's done, tell me if I made a mistake with some hidden case, I liked a lot this challenge :) https://code.sololearn.com/cY2j843lyJrv/?ref=app (P.S Natsuki rules <3)
10th Jan 2018, 3:12 AM
Sebastián Zapata
Sebastián Zapata - avatar
+ 6
It shouldn't return true :)
11th Jan 2018, 9:30 PM
Dapper Mink
Dapper Mink - avatar
+ 6
@firosuke Thanks for pointing that out. Yes, Code Playground is not running console codes atm for some reason. :/
12th Jan 2018, 5:46 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
I'll be honest Rei: I don't understand your code at all xD But it seems to work so... I wish for you firosuke isn't going to find any more bug :^)
12th Jan 2018, 3:53 PM
Dapper Mink
Dapper Mink - avatar
+ 6
The code takes the length of the first string, and create a corresponding string with length-1 which stores all 1 bits. Then, it converts this binary value to decimal, and iterates from 0 to this decimal value. The purpose of this is to get "all possible paths" which can occur. E.g. if 1 is "left", and 0 is "right", 01101 would mean to go right, left, left, right and left. That's the basic idea for this one. Even if it works, it's an overkill and certainly not my best work.
12th Jan 2018, 3:57 PM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Thank you so much for the advice, you are completely right this is better and clearer now! :)
14th Jan 2018, 5:19 AM
Dapper Mink
Dapper Mink - avatar
10th Jan 2018, 3:27 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
New test case : "trirtotrtopip", "tptirtopit" It should return "true", try it. Some of the codes here don't get it right. I think because of many direction changes and also the first letter "t" is present 3 times in the second string. If your code starts on the wrong one, it can't see the right solution.
11th Jan 2018, 9:38 PM
Cépagrave
Cépagrave - avatar
+ 5
@firosuke Nothing gets past your eyes. :>
12th Jan 2018, 11:12 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
You made me wanting an anime about programming *︿*
12th Jan 2018, 3:23 PM
Dapper Mink
Dapper Mink - avatar