5 kyu
Digits
26 of 165RealSup
Loading description...
Algorithms
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.
I just wanted to say thank you for the author of this kata, took me 3 days to solve. And enjoyed the struggle. Thank you sir for the great work.
All for you, my friend! Also you can try my others katas, part of them are the same difficult
Quite challenging kata in fact, well done.
In the example I play 1 game, in the test do I play multiple games? If I just return {1,2,3,4} is there 1:5040 chance to pass?
500 games in the main test block, no chances
Nice kata, but difficult.
can someone explain the desired input and output to me again with another example?
Im not 100 what my code should be doing?
should it just be returning 'matches' when a value is in the correct place?
thanks
Your function should return array of four digits. Value 'matches' is respond to that return.
Yes, matches count only when value on the correct place
When I click the attempt, I get more than a hundred, but the array from the error works fine in VS. The test also goes perfectly.
Hi! You didn't implement beginning of the new game, when matches == -1
when matches = -1, my method returns an array 0 0 0 0, until two numbers are found, an array of identical numbers is returned, with each attempt ++.The control is matches 1 . The test works
Main tests contains 1000 games, each new game starts from -1
thanks ) I feel stupid
My code still needs to be refactored, but i'm getting time out at the 500 tests all at once. My code seems to work properly finding the answer in less than 17 attempts, but i think testing 500 sequences all at once it's causing the problem. Any hint on how to solve it?
very encouraging kata
Interesting kata :) Maybe you would like to make a kata with 100 digits ? :D
I really don't understand what I am supposed to to in this exercise.
I added a link on similar game to the description
The tests in C# are bugged. E.g. the code is 2463, I return 0000 and next input is matches = 1, which should be 0.
Hello. I could not repeat your problem. The test block is the same as the sample test, it does not have many places to hide bugs.
Your solution does not work for multiple guessing games in a row. The sample tests only do one game and the first game always works with your code.
Thanks guys. Been a while since I last solved a kata, I completely overlooked tests are sequential.
Python Translation ready for review.
Looks smart, thank you!
I'm using C#. I'm not understanding this. It says it's giving me the number of matches I have. I assume this is the number of indexes of the array that I create that match the indexes of the answer array, is that right? So, if the code array is {2, 4, 6, 9} and I return an array {2, 3, 5, 7} it will give 1 as the answer? So I then have to figure out which index matched and then change the others?
if the code array is {2, 4, 6, 9} and you return an array {2, 3, 5, 7}, it will give 1 as the answer (in next input) - yes
I dont know why but the tests are not working in the right way. I get matches where there are no matches and otherwise no matches when there correct. Try to solve it in C#
Hi! Your last well-commented and working solution doesn't mentioned this
You have to find the code in 16 calls or less
And you see something likeTest Failed The code was 8517 Expected: less than or equal to 16 But was: 27
Try to optimize your algorythmYeah i know but thats not my concern. I dont get it why but when i change specific things in my code it gives back wrong matches. I started coding 3 months ago so I cant really tell what is going on exactly but im frustrated :/
Don't give up:) You can modify and use sample tests for debugging
Yeah right know im not focused on the 16 steps, more that it simply works in 100 steps. But for instance the Code was 2478 and 2222 gave back 0 Matches.
I changed one thing, that takes matches as a parameter but doesnt change matches itself, but somehow the tests dont work now.
Im working on this now for 2,5 days and I im so stuck, so I will probably come back when im better. I looked at the other solutions and was just shocked hahaha
I worked on it from beta to release more than two months, and you want to get through it in just two days?
Yeah i know I will come back to it but right now it makes for me no sense that the tests give back wrong feedback so I cant adjust my code.
Haskell translation
Approved, thank you
Hi,
Question: I have to say, I don't like the general setup with the function. There is state involved here. As discussed below, it would be far more sensical to work with instances, one per code to find. Did you just update the kata to go from classes to functions?
Cheers
Thanks for the review.
-1
)".Added some more explanations to the initial solution
javascript: unlike other languages, we do not get a function to call to verify our guess in the solution setup. Did the way the user needs to interact with the kata got updated for JS only? If not, could you add the function call to the solution setup?
The interface got updated. I must say, I quite like the way JS does it.
Having different interfaces for different languages is Not A Good Idea™ though. Pick one.
C# interface updated, Java next in line
All languages have the same interface. Warriors welcome.
@ParanoidUser sorry for your work, there is no other way out of beta
I'd like to approve, but the ranking votes are all over the place. I have no clue which kyu level to pick.
Haven't solved but it is at least 5 if I am not overlooking anything here. Whoever voted 7...
I don't know how well this translates to other languages, but this kind of thing really should have been a generator function that accepts values back in, in my opinion.
Regarding rank, while I did end up finding it easier than first expected, I think its a hard 6 at best but much more likely a 5.
@Madjosz The votes initially were 7 - 6, but the kata changed and got made more difficult
Thanks for the help. I hope it has not become more difficult, but more complex and has an unusual structure.
Some other Java caveats:
Class should be structured in a way to hide all internals from a user and prevent hacking (example - https://www.codewars.com/kata/reviews/63a0887b1e15f60001a25cc8/groups/63d47f8a65436000010be67e). This can be achieved through class composition, instead of inheritance.
As the problem states
code consists of four unique digits (from 0 to 9)
. In general, this requires more strict input validation (codes like3333
should be denied to check). Example - https://www.goobix.com/games/guess-the-number/Lastly, the algorithm currently implemented gives the wrong answer
1239
when the guessed number was1237
, or answer9410
for7014
.I pushed an update addressing #1 and #3.
You are so beau! Regarding the second question, if we add stricter input validation, in some rare cases the solution will require much more than 15 attempts
Yes, the max attempts will jump up to 21. But, I found the current approach more sophisticated. In the end, fewer steps add this extra "efficient" smell to the kata. 😄
I completely reworked the kata for JS translation, you might want to take a look and give some feedback.
Did you change all translations? I mean, is there a noticeable difference in difficulty across languages? I'm also afraid all current ranking votes are from the initial draft version, when it was still an easy kata.
I'm not sure how to do better. I plan get feedback for JS version, and if it will be good, change another languages. As for me, JS variant is more intresting than just going over the numbers in current C# and Java versions
ok leave my issue open for now then, at some point all languages need to be aligned before closing that one
With your updates in JS, you should make sure to also run multiple tests shuffled at the same time, in order to avoid users keeping track of state.
Could you explain about run multiple tests shuffled at the same time? In JS we have 50 non-repeatable random tests every time. And each test own const digits (with special secret name for avoiding cheats). Or you talking make it private?
In your new model, are you calling back and forth between user code and test code in a loop until the user has guessed right / has no more guesses?
Yep. Top border is 111 guesses for being cool in perfomance
well, my point is that users might keep track of state between these calls, because you are running each such test (multiple times back and forth) sequentially. If you run multiple such tests in order of breadth, you will deny users the advantage of keeping track of external state. I don't know how to explain this better. sorry :/
I think I got your point. There is no such problem, because all input is number of matches, output is single answer, no more interaction between tests and solution blocks.
var log = [];
does not uses in tests, it's a little tip (maybe not the best one) to use fields outside main functionWith the current JS setup, you can't even run multiple tests shuffled. You'd have to use a
class
instance to do that - there has to be state in the current ( or any ) setup ( unless you pass the complete history every time ). Passing-1
to reinitialise the game works well IMO, it makes for simpler programming than having to wrap the function in a class.In Java, it's a bad practice to mix the main code with the test branch. As most of the time, test libraries (like JUnit) are scoped to the test level, and the main code won't compile.
A better approach would be to have a separate
Helper
class in the main branch to give match hints. An instance of the Helper class will be initiated in tests and passed as an argument totryToGuess
method.Here is a reference to how it's done on a similar challenge - Guess the number!
Thank you a lot! Now I have all for making some awful translations
I find the kata unnecessarily focused on being adversarial to the AI rather than being optimal in our guesser:
myDigits
andTryToGuess
should be instance, not static. Static would mean that we can modifymyDigits
whileTryToGuess
is being active, which doesn't lead to cheese because of howCheckAI
is implemented (it breaks after ~40 attempts), but is still a red herringmyDigits
shouldn't even be a instance field at all, because it can then be turned into a property, and stops being a constant, again, another massive red herringThanks for the great feedback, it held me up for a couple of weeks to think about how to fix it.
I reworked all the kata and removed the adversarial element, like you said. Now the task is clearer. About the static fields, I agree that it's an opportunity for cheating, and it still here, but I've made some fixes with that.
Setting any of the values in
myDigit
outside0 - 9
will break the actual tests (because of how AI guesser is implemented), even though it is already checked inInputCheck
and should not break thereafter.Also, some solutions are taking the assumption that you can passing in invalid solutions to
PlayerTest.Check
(values outside0 - 9
, or non-unique values). This is not specified and should be mentioned in the description because it will affect the behaviour of the guesser.Updated description. We can use any combination of values from 0 to 9 in the input, the answer always consists of unique values. Not sure about the broken tests, hopefully everything will be okay now.
This comment has been hidden.
That kata gives hints at every position, yours gives a hint across the entire solution set. I'd say these kata's differ enough! I do think you need a JS or Python translation, or this kata will remain in beta forever.