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)
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!
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
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
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
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.
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
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…