5 kyu
Knights
22 of 62Djacon
Loading description...
Algorithms
Logic
Puzzles
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.
For once, the backstory adds something to an excellent kata.
Dear Djacon, this took me dayyyysss to complete! haha Great Kata, thank you! I remembered something I learned in a previous kata about how to improve performance and was happy to be able to apply it here.
:)
From what I can see now - all sample tests passing, however there are tests with random data that fails. How can I fix this problem, can I get samples of those tests somehow?
Actually I just get 'got 7 expected 2' without description of the exact test idea, could you provide what this test is about for me to come up with solution for possible bug in algorithm?
You can print function arguments to console.
aaahhhh after three days I finally come with a solution that pass the sample tests, but times out on the other tests. I give up :)
Dude, your way is too long. Maybe you should find another way to solve this problem without changing the original array? :)
Hint: note that the ranks of adjacent knights are always different, and when Galahad comes, a same pattern happens
Hi! As far as i see, sometime random tests generate positions like:
[770, 768, 767, 766, 766, 768, 770], 3, 766)
As you can see, here is two pairs of knights with the same rank being the neighbors. So isnt it contradicts the condition?
Sorry for the long wait (I had about 1 a.m. at the time and had to put it off until tomorrow)
Now fixed
according to the logic u've put in the short explanation, when there were 3 knights of rank 8 and only one of them got ranked to 10, but in the 5th step there were also 3 knights with rank 10 which means that only one of them will be promoted to rank 12, so the remaining knights will only be 3!
no, those 10 aren't sitting next to each others.
Hi,
6 6 2 2 2 2 2 6 6
and so on (galahag being one of the 2, ofc).Cheers
Hi,
There are knights gathered at the round table, and they prudently arranged so that the rows of their neighbors are different
so there can be no knights with the same rank in this kata.
I realized that there are no situations in kata where 1 or more knights remain, but I'm still working on that.
2: oh ok. I missed that.
I added tests with cases where only 1 knight survives.
Regarding the first problem, python & JS solutions can't handle arrays where more than 30-40% of all knights are involved in combat. Maybe I can put the number of battles higher than now, but in that case the required kyu to that kata will become higher than 5-6 (although I'm counting on that range, with your permission)
what's the exact problem when increasing the "battle ranges"? execution time varying too much from one run to the other? input generation? on the solution side, those which aren't creating copies of the array shouldn't suffer that much.
@Djacon for test generation, you might be able to generate "more interesting" tests, by working backwards. Example
Another benefit of this (if done correctly), is you already know the result, so you don't have to run a reference solution over it. (But you might want slightly more sophisticated logic than that, to also include other edge cases.)
Anyway, just an idea :) (May not be necessary at all)
@Blind4Basics, the problem is that when you increase the "combat range", the pass time increases greatly.
I've tested this on several tests, using various solutions from other participants. So I don't know how else to solve this issue.
@Kacarott, your solution is very interesting, but difficult to implement.
In this kata, I already know the correct answer from the beginning and don't calculate it :)
maybe, just decrease a bit the input sizes, so that you can enforce some "long travelling" in some tests. Or use that kind of input specifically in some medium size inputs and keep the big numbers tests as they are?
Ah ok, my mistake. I saw
ans = knights(arr, p-b, x)
and thought it must have been a reference solution. In that case all good, but I'd suggest to import the user solution directly then. No point ofimport solution
if you arent going to usesolution
.Finally I managed to optimize the generation of arrays and now we can run tests with 300k knights :)
.
My solution that always passes JS sometimes fails Python. I'm positive it's because of some edge case you check in Python and not in JS. Could you verify both languages for edge case generation?
I examined your code and saw that it returns the wrong value in some cases.
For example:
Thanks for providing an example. Somehow, this scenario never happens at JS, but sometimes at Python. That's why I think you are generating differently in JS vs Python.
I think I found it, you have 0 as possible element entry in Python, and not in JS. Or maybe I just never got an example with a 0 in JS. Anyway, this is the edge case for me.
answered
Amazingly, I finally found the cause of the error :)
Everything should work now, thanks for your help.