[Community Puzzle] Rock Paper Scissors Lizard Spock

Since your post didn’t get deleted it seems to be ok ^^ (I don’t know either)

I did it like this: While playing I saved the matches played into a list. When I knew the winner, I went through the list and gave out every opponent of the winner. (the tricky part for my solution was to go through this list in the right way)

I would say, that this is a classic tradeoff between CPU and memory.

As an opposit to CPU, you can store opponents for all players in a vector, and than traverse winner’s opponents list in a backward direction.

BUT
It is also possible to trace opponents without extra memory while only running game once.

hint: approach is similar to sorting an array.

2 Likes

Blargh! I was wracking my brain for a whole day trying to figure out why my array was sometimes getting filled with garbage data. Then I had the epiphany that the player numbers are 1 to N+1 and my array was 0 to N. Doh!

Hi,

Great Puzzle!

One question: With my solution all the test cases worked and the validators 1 to 4 worked too.
Just validator 5 did not work.

Any tips to what the problem with my code might be?

Greetings!

Maybe your code is false just in one case; for example you coded that Spock wins against X (that is false) and only this validator tests it.

1 Like

Beautiful puzzle. On one hand - simple enough to be considered “easy”, but on the other hand it contains interesting “depth” once you start thinking about possible approaches, including optimizations.

Continuing the point by @djmil , there is also a memoization approach “per player” which lends itself nicely to this problem.

Another nice optimization is the understanding that there is not really a need for a “rule table” for this game, and that it can be solved with a simple math formula

And finally, I had fun training my code-golfing on this problem. With the above optimization, the result is surprisingly slim

1 Like

Hi everybody !!
I have a little problem, i have a code who worked with all cases. But i can’t put it on the console.log. On the last instruction, if i put the response, i have the good response on my output. But a fail is in screen, with a wrong expected result. Example in the picture.
And if on the last instruction i put a console.log with an other information before my console.log(response), i have a fail in screen, but the good expected result.
And if i reverse these two lines, another output again. It’s seems like my line with the response is totally ignored.
It’s very strange and i can’t validate this exercise.
I hope my text is understandable to everyone :nerd_face:



Output exactly what you are asked to output. No more. No less.

When the expected answer is
3
You output
3
3
You fail.

But you can output debug messages without affecting your correct answer.
To debug: console.error(‘Debug messages…’);

2 Likes

Thanks for your answer.
Yes i really understand how it works normally.
But if you see the first pic, i have console.log in line 159.
winners[0].NUMPLAYER is my answer, and give exactly what is expected. You can see on the console, “Sortie standard”, i have just one output and it’s this one. But you can see also “Echec”, that’s mean “fail”, and “trouvé” that mean "find, “Rien” that mean “nothing”. But we have an output who give “128” just above it. So in the first case, i have an output, and he find nothing. And you can see what is expected, “75 2 18 29…” is not the real thing expected by the exercise.
That’s why, on the pics 2 and 3, i put a second console.log, to see the comportment of the output and the expected. But maybe it’s give more difficult the comprehension of my problem.
However, if we just take the pic 1, the answer is send in line 159, but is not finded by the program.
And if we take pic 2 and 3, i send the same two lines, but not in the same order, and every time a responses is finded, but every time it take the wrong, and the expected thing is not the same.
So when the program read my good answer alone, or in first, he ignore it and give an error on expected answer. My response appear on the output, but is not read by the program.
I try to find something wrong on my code, but i just see that the program can read all the console.logs, but not if i put my answer on. My answer appears on the output, but is not reading for the answer expected. And if i put my answer on a console.error, no problem my answer is reading and on the output.
So i try different things like const answer = winner[0].NUMPLAYER and console.log(answer), or build something different but nothing’s work.
So i know my code gives the good answer in every case, i just can’t validate :grin:

Wow sorry for the Big Text :pleading_face:

There are two lines of output expected:

Line 1: the number of the winner
Line 2: the list of its opponents separated by spaces

On pic 1 it’s only seen the first line and is saying it expected the second line but found nothing. Pic 2 is saying that your sentence is incorrect for line 1 and pic 3 is showing that your sentence is incorrect for line 2.

2 Likes

Oh my god you’re right, i never send the list of its opponents… :man_facepalming:
So it can’t works, i just missed this.
Thank you a lot :pray:

I don’t know how this puzzle is solved in other languages, but in C++, in addition to everything, I had to use the class to optimize the code.
learn “class” - check :white_check_mark:

Your code can be reused in another puzzle. Don’t waste it.

2 Likes

I was wrong validator 3 and 5 . I don’t know where my mistake is

You may have to create random custom cases to test your code.

So, on this website. I struggle with one main thing, that stops me from progressing in any meaningful way. I am not sure what I am allowed/expected to do. I dont know what I am allowed to change.

Can I change the original code?

I keep wanting to add to it, but again… I get stopped…

You can change the original code, as long as you know the effects of the changes.

Okay. Ive been so hesitant to touch anything. I wasnt exactly sure what the rules were. Other than of course, answer the question.

The same problem here :flushed: Give a hint please, what to start with :pleading_face: