8 kyu
Rock Paper Scissors!
50,600 of 136,106brunolm
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
This comment has been hidden.
Solution sharing != kata suggestion.
This comment has been hidden.
This comment has been hidden.
This kata was a bit annoying. I think it could have been a 7 KYU
Please approve Shell Translation
https://www.codewars.com/kumite/67025dce1bd1710b319b05eb?sel=67025dce1bd1710b319b05eb
The code I wrote is correct. I checked it on VS and it runs smothly, but it still gives an error when testing with the sample tests. As a beginner, the fact that no kind of info is given to know more or less where to start is disssapointing.
Your code is not exactly correct, it's not a valid solution of a Codewars kata. See this article for some hints: https://docs.codewars.com/training/training-example#writing-a-solution
No args, int arg or string args ??
No int args, string args!
okay gotcha
yay
My
Haskell
code works perfectly in GHCi. Fails on each test when I hit "Attempt" button. Seems like many others have same issue in other languages.Your code is not correct, and I honestly doubt it works in your GHCi correctly.
I have no idea how you can see the various codes that I entered and why you doubt me?! I have three versions of this code running in GHCi, all correctly. Including one version with error handling if input text isn't one of the three std input strings. I was talking on Discord FP server in the #haskell-beginners channel and getting some help.
There seems to be an issue with the read command (and readMaybe) working in GHC and not in Codewars. I removed all the use of datatypes and just used strings instead so i didn't need the read or readMaybe functions and it works in CodeWars too. Seems Codewars does not like
read
.We can just do that, after we ourselves had solved it. Mods can see it in even more detail.
Why the heck do you doubt the tests?! How could it be approved and sit for years if the tests were wrong? This isn't even factoring that there seems to be a real issue of no random tests available (but that's beside the point).
We hear this every day, and at least 9/10 times it isn't "all correctly", or it doesn't conform to CW's interface. Your local environment is not the same as codewars environment.
Were you asked to do error handling for this kata? No, it's only valid inputs. So, don't worry about handling it. For this kata, monads shouldn't even come into the picture.
It seems that you're overcomplicating the task and trying to involve I/O ? Just focus on function signature at hand and keep things pure.
I cannot see various codes, because except complaining, you did not bother to share the actual code which does not work for you. All I could do is to check your most recent code (which I can sometimes do), and I saw that it does not conform to input specification of the task.
I can also see that you completed the kata, what I presume means that you found your mistake. However I still do not understand where the "works perfectly in GHCi" came from, as it did not handle valid inputs at all.
I had it with Python but that is valid as there might be some edge cases that would have been left by you to check for.
This comment has been hidden.
I spent half my time working on English grammar, which was a real ordeal for being a non-native English speaker。
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Player 2 wins Log Player 2 won! None should equal 'Player 2 won!' Log Player 2 won! None should equal 'Player 2 won!' Log Player 2 won! None should equal 'Player 2 won!'
I don't understand, languague is python
I guess you've printed your answer instead of returning it because result of a function without a return is None and it seems like you are printing something.
If I'm right than changing
print(answer)
toreturn answer
should fix it.Yesss, I made the exchange and it resolved
This comment has been hidden.
I got it ahaha. I realized that I put 'playar' instead of 'player'. Check your spelling folks.
you're joking men
bcs you spelled player wrong instead u said playar
This comment has been hidden.
This comment has been hidden.
check the solutions, there are plenty good solutions out there!
Please don't post solutions in Discourse, use Solutions section to discuss your solution.
This comment has been hidden.
Player 1 wins 'Player 1 won!' should equal 'Player 2 won!' Completed in 0.01ms what does dis mean
The second sample test was mislabeled, it should be Player 2 wins. Your code is wrong btw and it is failing that test.
In PHP when i run my code through test it passes, but when i hit attempt it returns the following issues:
Your solution has a bug, it's not a kata issue.
I got the same problem, did you solve this issue by any chance?
This comment has been hidden.
Honestly i didn't get this ahah can anyone explain pls?
There are 2 players, each of them will either receive
scissors
/rock
/paper
as arguments. You need to determine whether the output should bePlayer 1 won!
/Player 2 won!
/Draw!
.In case you have not heard of the game before, here it is ^^
No random tests in Haskell
Given that
rps
is a pure function and the fixed tests are exhaustive, random tests don't really serve much purpose other than to weed outunsafePerformIO
shenanigans. Nevertheless, I've added in random tests in a fork.Test hasn't check for no args, one arg or not string args.
How in the world is this where im supposed to start as a beginner? Like when it said fundamentals, I thought itd be something a bit simpler than this.
bruh....
Liquidouz has a point. There is not information in the description for someone new to programming that provides any form of suggestion or hints on how to approach this
The code that I checked in the browser console works correctly, but in the test it gives an error.
so, your code passes some tests, but not all tests
same problem here...!
This comment has been hidden.
Please read this: https://docs.codewars.com/training/training-example#writing-a-solution
This comment has been hidden.
p1 и p2 - строковые параметры Не понятно как вы собираетесь применять операторы сравнения (>,<) к типу string
This comment has been hidden.
This comment has been hidden.
You had a typo in your code, the tests are fine.
Be very careful with the spellings laddies. Got stuck for 14 minutes before realizing I had spelled one of the paper as papers.
Tests has next issue: missing '!' in the end of the string "Player 2 won!" in some tests
player 2 win expected 'Player 2 won' to equal 'Player 2 won!' Completed in 2ms
The tests are fine.
Not a kata issue.
Ok. My bad
(Rock Paper Scissors) "expected undefined to equal 'Player 2 won!'" what does this means? other two sections are passed.
Your code is wrong, not a kata issue. It reaches the first case where p1 equals something and enters that if, because it doesn't find a match, the code ends there returning
undefined
. Use this to see how your code works.And please read this: https://docs.codewars.com/training/troubleshooting
hint for java: it would be better to do "draw!" as separate cause of if else, not else. it was my mistake
This comment has been hidden.
I guess mine doesn't count as a one-liner, but I'm kinda happy with it
I can use it if I want to write so many if else statments but how I can come up with clever solution. What TOOL should I use!!!
OP left the building, closing...
what is the technical term for ths definitio of data winner = {'rock':'scissors', 'scissors':'paper', 'paper':'rock'} is it an enumerated data type ?
Hi @Deniz0418 and welcome to Codewars - since you are working in Python, such a data structure is called a
dictionary
- you can learn about them here for example:https://www.programiz.com/python-programming/dictionary
(Not an endorsement of this site, just the first decent google search result typing "python dictionary").
Would probably be better if it used
impl AsRef<str>
or something alike for the return type. This would allow the use ofString
allocation from theformat!
macro or something else.took me half an hour to realize i misspelled scissors (without the last "s")...
Feel your pain. When it comes to me, usually it's something as simple as " or , or / ...
I forgot <!> sign and it faild test#3. In my output I had: "Draw", instead of "Draw!". Pay attention to small things. Stay calm/focus.)
rock paper scissors player 1 win expected 'Player 1 won' to equal 'Player 1 won!' Completed in 3ms player 2 win expected 'Player 2 won' to equal 'Player 2 won!' Completed in 1ms draw expected 'Draw' to equal 'Draw!' Completed in 9ms
I don't see any issue except your code not returning the correct strings. If you're really sure there is an issue please at least let us know the language.
You're missing the character
!
in your returned values./home/codewarrior/node/test.js:7 }; ^
SyntaxError: Unexpected token } at new Script (vm.js:80:7) at createScript (vm.js:274:10) at Object.runInThisContext (vm.js:326:10) at Module._compile (internal/modules/cjs/loader.js:664:28) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18) at /home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/lib/mocha.js:250:27 at Array.forEach () at Mocha.loadFiles (/home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/lib/mocha.js:247:14) at Mocha.run (/home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/lib/mocha.js:576:10) at Object. (/home/codewarrior/node/node_modules/.registry.npmjs.org/mocha/5.2.0/node_modules/mocha/bin/_mocha:637:18) at Module._compile (internal/modules/cjs/loader.js:701:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10) at Module.load (internal/modules/cjs/loader.js:600:32) at tryModuleLoad (internal/modules/cjs/loader.js:539:12) at Function.Module._load (internal/modules/cjs/loader.js:531:3) at Function.Module.runMain (internal/modules/cjs/loader.js:754:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
Issue in your code is not a kata issue, you're missing an ending
}
somewhere in your codeThere is an error in the python language in the tests:
"Traceback (most recent call last): File "/workspace/default/tests.py", line 2, in from solution import rps ImportError: cannot import name 'rps' from 'solution' (/workspace/default/solution.py)"
Backup your code, click Reset, paste it and try again. Also, make sure your function's name is rps.
Nice Kata 8, thanks !
This comment has been hidden.
It's scissors, not scisors. That's a problem with your code, not a kata issue.
i have coded it and it is not showing any errors and it is not allowing me move to the next problem
Your solution codespace has a return statement floating fully outside the scope of the function. This makes no sense. Remove that and you will see that your function does not pass the sample tests. You'll have to re-think your logic on solving this kata.
HashMap is most flexible solution cuz it allow you to add new entities to the game.
This comment has been hidden.
easy one
Kotlin translation
This comment has been hidden.
Hi, it is forbidden to post solutions. I have added the spoiler flag to your post.
This comment has been hidden.
paste your code (with spoiler flag)
This comment has been hidden.
You have to return the answer, not just print it
Thanks man!
I have tested the solution and have passed it, but when I attempt the solution it give me errors, is this a common problem?
The sample tests do not test every input. When you click "attempt" you run against all inputs, so yes it is quite common for solutions to pass sample tests but fail submit tests.
@kacarott when i click "attempt" it does not give me error , but it is not submitting
Factor translation
Approved
Go translation
Approved!
This comment has been hidden.
Requires returning, rather than printing.
Rust translation
Approved!
Test cases should be exhausted here, but draws are not for some reason.
This shouldn't be 8 kyu
Unfortunately, 9 kyu doesn't exist.
lol the usual 8 kyus are way more straightforward and less verbose
Description should be language-agnostic
^^
This is good a task!
C# Initial solution's unnecessary imports should be removed
done
This comment has been hidden.
You need to
return
the result, not print it.Please use markdown tags when you post code or it's not usable. Refer to the documentation about this and more: https://docs.codewars.com/training/troubleshooting/#post-discourse
I can't figure it out. I've ported all the code to VSCode and it runs correctly. When I check rps('rock', 'scissors') I get the "Player rock won!" in the console But on the site I get the error "Player rock won! to equal Player 1 won!"
You should return which player won, not which item the winning player selected. Player 1 is the first argument and Player 2 is the second argument
Oh! now I see. Thank you! It cost's me 2 hrz before I decide to ask )
in Python, and all other languages, test cases are not the unique cases
What are "the unique cases"?
And it should be the same in all katas. The issue is the contrary: https://docs.codewars.com/authoring/guidelines/submission-tests
Under "the unique cases" i mean that random test cases have duplicates tests. for example "testing for paper, rock" can be duplicated more than two times.
Seen the small number of inputs possible, and considering tests are random, this is not a problem.
My first answer was incorrect because I didnd't understand what you meant. Better wording would have been "... are not unique cases".
In TS/JS, there's a tedious and clever way of writing this up.
This comment has been hidden.
You must
return
the result, you only print it to the screen. Please use spoiler flag when you post code, and use markdown tags to format them. Have a look at the documentation (see left panel).my program works but codewars doesn't accept it 🤦♂️
Some more details could be useful, but I'd rather say that if codewars does not accept your program, then it does not work.
This comment has been hidden.
Please see the last bullet point of this paragraph: https://docs.codewars.com/training/troubleshooting/#expected-the-same
This comment has been hidden.
read the error messages on codewars... your code should never return 'undefined' for this kata, but it does. it would seem your offline testing situation is either wrong or incomplete
This comment has been hidden.
Copied/pasted your code and it worked just fine. Also, please mark your post as having spoiler content next time.
This comment has been hidden.
I also just copied it and it works fine. Are you adding some extra code that you're not showing us? To attach a screenshot, you can upload it somewhere, and show it here using syntax:

See: https://docs.codewars.com/references/markdown/#links
This comment has been hidden.
You can always hit 'Attempt', no matter if 'Test' fails or not (it's different tests suite). The error message tells you that you returned 'Draw', but it should be 'Draw!'. Maybe you modified the code after posting it here?
This comment has been hidden.
This comment has been hidden.
It's because you modified sample tests yourself, that's why. Look at the last line in your screenshot, there's no expected value for it. That's why they're sample tests, because you can modify them at any time. If you want to see what sample tests there should be, copy your solution and hit 'reset'.
This comment has been hidden.
You have a typo, it's
scissors
notscissor
.This comment has been hidden.
I keep getting an EOFError. Looked it up and didn't have a clue ("Raised when the input() function hits an end-of-file condition (EOF) without reading any data."). Any advice?
Don't use input, use the function's arguments.
Thanks, it worked.
motherfucker bitch @brunolm
Expected: equal to "Player 1 won!" Actual: "Player 1 won!"
?
Which language are you using?
I used c++
I've just tried to use your code (which passed all tests) 50000 times and could not reproduce the error, that's really weird.
I really don't know. But the important thing is that it works anyway, thanks.
This comment has been hidden.
Approved :)
Trying to solve this Kata in Typescript (I am really new to Typescript) but keep getting
error TS1128: Declaration or statement expected.
When running "test". The function itself is fine though (returns all green when running "attempt").
You're right. My bad, I'm the one who approved the translation. It should be fixed soon (the last line in the tests must be removed). Thanks for alerting.
Should be fixed now.
yep, could submit now :)
COBOL translation
approved at some point
the sample code is running when I try in visual code but it's giving error here.... I'm new to coding and this codewars platform! It'll be great if anyone can explain why it's happening
Read this: https://docs.codewars.com/getting-started/solving-kata
Assert::That(rps("rock", "paper"), Equals("Player 1 won!")); this test is bugged
Where are you seeing that test? The sample test for C++ is like this:
This comment has been hidden.
Please mark you post as having spoiler content next time. That's not how
switch
works.ok , I'm just starting go and using codewars
No random tests in
no entiendo
PHP tests are faulty
Crystal translation
Julia translation
Thanks :)
This comment has been hidden.
Stuck how? What language?
This comment has been hidden.
This comment has been hidden.
Well you don't need break after return and the
()
in the ternary operatorNoted. Thank you
Anyone else missed Spock and Lizard?
This comment has been hidden.
I see you're new, next time mark your post as having spoiler content, why are you randomly overwriting the values of the function's arguments?
OP solved it, closing
elegant and simple solutions ... so amazing but sometimes it's hard to guess =(
This comment has been hidden.
Nice coffee break kata!
This comment has been hidden.
I couldn't agree more! Still an awesome infographic though... It really ties the room together!
i bet you can make a gif of that somehwere
@brunolm thanks for the nice kata!!!
I don't know what to do. I always get the error: not all code paths return a value
I use only if-clauses and I don't know what to do know. Can someone please help me?
Add a return after the if/else chain.
This comment has been hidden.
.
This is weird -- when I run my code in repl.it, it works as expected with my manual input. When I run it in the Codewars window, I'm getting return = defaultvalue errors...
Guess I just don't know enough about test-driven development...??
AH, stupid oversight -- I was being case insensitive. X(
This comment has been hidden.
It's like jo ken po.
https://en.wikipedia.org/wiki/Rock%E2%80%93paper%E2%80%93scissors
Dumb question but is the result basing this off of having two players playing the game or one player playing against the computer?
This comment has been hidden.
Welcome to Codewars! I've tried to explain the basics in detail for you.
1.) You need to return the output statement, not print it to the console using print(). Use the reserved word
return
instead of print(). All Katas on this website work by returning the output statement.Programming functions behave like mathematical functions where they require an input and give their output. The parameters serve as the input and the statement you return serves as the output. This is required so you can get a return value from the calling of the function. This means you can expected a certain return value from the function, leading to equality checks through testing via testcases.
2.) You need to change "win" to "won" in all the statements.
3.) You need to consider draws - in which player1 and player2 have the same input (player1 == player2).
4.) I suggest using "==" instead of "is" when checking equality (read stuff like http://stackoverflow.com/questions/2239737/is-it-better-to-use-is-or-for-number-comparison-in-python)
5.) You can remove the default values for the parameters. The default values you put is tuple containing the choices (a fixed collection of items) and if no parameters are entered, it will use the tuple and won't pass any if statements.
Thank you very much for your reply! Really apreciate it! Will try to modify it :)
Your Kata (PHP Version) needs more extensive test coverage to prevent easy cheap-cheat solutions and/or logically flawed solutions. The most common way to increase test coverage is through the inclusion of randomly generated test cases at runtime so please add these. The lack of test coverage in a Kata as an Issue is recognised as an official CW stance.
Please only file issues, post approval, if they are actively causing people problems with completing the kata. Also, for 8 kyu kata, especially one like this, random test cases are not as important. I will be updating the CW wiki (soon to replace our docs section) with more details about this as an official stance.
This comment has been hidden.
I think that this kata is harder than 8 kyu.
Please don't file opinions like these as issues. You can make it a suggestion.
This comment has been hidden.
Your code does work, it's just that you've redeclared the p1 and p2 even though they are given to you. You've set them so they give a random choice but you're meant to get the result from p1 and p2 choices. Get rid of these.
Yeah, it was one of the first katas I was doing so I thought I had to provide them, took me a while to figure it out but finally did ^^
This comment has been hidden.
Your code fails in these tests:
Your logic is not right.
Thx, already found a mistake!
Java translation kumited. I intended to translate it into Clojure but this language is not propsed for your kata...
That is because a Clojure translation was already submitted ;)
I didn't see it:-( Grand merci Monsieur:-) Always on the go!
De rien à nouveau, monsieur.
Upvoted, ranked and translated into both Python and Ruby, if you want to approve them :)
On a side note, I don't see the point in having random tests when 9 cases are all the possibilities of this kind of kata ^^'.
Cool thank you :)
haha it has become like muscle memory, I will just write random tests without thinking
what does "None should equal 'Player 1 won!'" mean in Python?
This is my first kata on the site. Am I using it wrong? I don't want to post my code because I think it's correct. (It works fine on my local machine)
You should
return
a value ofPlayer 1 won!
in that case, while apparently it seems like you are not returning anything.Edit: are you sure you are not printing it and that you are using Python 2.7?
Bingo! Exactly what I was doing. Used to hackerRank. Thanks. Love the site.
Glad you overcame your problem :)
This comment has been hidden.
Done
Marking as resolved