+ 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!
50 ответов
+ 5
commented version :
https://code.sololearn.com/cFcE1Ow8w0GO/#py
+ 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
+ 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
+ 8
Here I present another miserable attempt at being relevant.
https://code.sololearn.com/cQrt7eyuDA5K/#cpp
+ 8
Let this be it.
https://code.sololearn.com/crGJd865C1lo/
+ 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!!
+ 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.
+ 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
+ 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!
+ 7
@Ipang, I tried my best (really hard with the character limit and my lack of creativity when it comes to write sentences ^^)
+ 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)
+ 6
It shouldn't return true :)
+ 6
@firosuke Thanks for pointing that out. Yes, Code Playground is not running console codes atm for some reason. :/
+ 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 :^)
+ 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.
+ 6
Thank you so much for the advice, you are completely right this is better and clearer now! :)
+ 5
Just Monika.
https://code.sololearn.com/c1aEC4b6OshG/?ref=app
+ 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.
+ 5
@firosuke Nothing gets past your eyes. :>
+ 5
You made me wanting an anime about programming *︿*