Worst of all: Didn't use std::string everywhere !!Quote:
Originally Posted by exterminator
:D :D :D
Printable View
Worst of all: Didn't use std::string everywhere !!Quote:
Originally Posted by exterminator
:D :D :D
I think I got all 3 under 10 minutes (didn't really time it).Quote:
Originally Posted by RoboTact
Have you ran your program? How fast does it find the solution?
And is there a fourth one???
P.S. Sorry I couldn't rate your beautiful post. Apparently, I have to "spread" stuff...
It's SLOW. It only parsed 30 symbols by now. Multithreading may help here.
It is still running on my machine since I posted my last post in this thread and that is about 1 hour 10 minutes back. It hasn't found any until yet. I am going to sleep now... so will have to terminate it... sorry RoboTact for stopping your program... I should clarify that I don't mean any disrespect to it... Will try again in leisure... :DQuote:
Originally Posted by RoboTact
And yes, use std::string and std::vector :D :D ;)
//Go have some fresh air... smoke should help ;)
Got all 3 :thumb: It took some time for me as simultaneously solved some production issue for one of our client. Though solving this was fun than production problem
Vinod
I think I found the third solution first. But overall it took me a few minutes for finding all of them, it's not that easy.
The first two I found did not involve a whitespace. But perhaps this is a hint to the third one.....hmmm :DQuote:
Just what I thought! The first two were pretty easy, but still struggling with the last one!!
ok people, you can go ahead and post solutions now if you have them. I think enough people have suffered ;)
Here are the first two I found, with the character changed highlighted in red...
Took me about 30 minutes to find these two. Hopefully this is never asked in an interview because I would probably not get the job lol.
1)
2)Code:int i, n = 20;
for (i=0; i<n; n--)
{
cout << "x" << endl;
}
But for the love of all that is holy what is the third solution!?!?!?!?Code:int i, n = 20;
for (i=0; i+n; i--)
{
cout << "x" << endl;
}
Negating a negative gives you a positive.
Regards,Code:int i, n = 20;
for (i=0;-i<n; i--)
{
cout << "x" << endl;
}
Paul McKenzie
I got nr 1 and 3, but nr 2?? Still cant see that!! Have to look closer at it tomorrow! When is that actually teminating?
OMG! Noooooooooooooooo.....
I was totally thinking that for the third solution and was going to check it, but then my hot pockets were ready from the microwave, and when I came back I lost my train of thought.
Nice job everyone, this was fun!
Gonna ask my buddy to send me more of those whenever he gets them :D
-20 + 20 = 0.Quote:
Originally Posted by laitinen
Take a look at the for loop, and the terminating condition. Since on the 20th iteration:
i + n =
-20 + 20 =
0 =
false
The loop terminates.
Regards,
Paul McKenzie
Actually i got 3rd as 2nd & 2nd as 3rd ;)
But i guess we are going 1st & 2nd based on what dcjr84 knew
Vinod
I got the same three for-loop internals, in this order:
i=0;i+n;i--
i=0;-i<n;i--
i=0;i<n;n--
Interesting, it seems we were struggling to find different 3rd solutions.
You must be one smart cookie if you got the i+n first :)Quote:
Originally Posted by Zaccheus
My buddy says everyone gets these two within a reasonable amount of time
But this one he said most people never figure out, and if they do it takes them a long timeCode:i=0;i<n;n--
i=0;-i<n;i--
But, I guess everyone thinks differently because I got the i+n second, but couldn't figure out the -i<nCode:i=0;i+n;i--
It took me a while to stop looking at the termination condition and consider decrementing n.
:blush:
Also I was initially convinced that something could be done with the n = 20 statement, that cost me a lot of time.