7 kyu
Red Knight
776 of 1,974CarbonStrings
Loading description...
Puzzles
Algorithms
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.
yes Log input: knight = 1 pawn = 7138274664000306176 expected:<Black, -4170194745708939264> but was:<White, 0>
It is good Kata! Thank you!
I would suggest the "Notes" section be "Rules." Notes are usually supplementary. Although, you do have a nice diagram anyways.
When testing Java, the input arguments are larger than stated in the conditions.
pawn = 7220222102556628992 expected distance = -4006299868596293632
Declared in the assignment.
P / p (Ruby) horizontal position of two pawns (between 2 and 1000000).
Java: expected solutions for the distance in the "huge_random_tests" overflow the
long
range and wrap around:knight = 1
pawn = 7220222102556628992
expected distance = -4006299868596293632
It seems there is mistake in expected results for values (1,5) should be ("White", 9) not ("White", 10) because ...
COBOL translation.
Approved!
It might seem hard at first, but the description is good and the test cases are really helpful. Well done!
Thank you!
Java
expected:<White, -7518593163422906368> why is it negative?
Some kind of integer overflow?
seems like it, guess i need to change my approach thanks
This comment has been hidden.
Your solution is too slow and uses too much memory.
This comment has been hidden.
Please avoid posting spoilers, or mark your posts as such.
This comment has been hidden.
Great Kata, good gotcha to make you think more!!
The Kata description says input args are named as:
But Java is using different arg names, not same as described.
Yay can't wait until someone renames arguments in java to
N
andP
instead of changingN
andP
to anything sane ;)Oh, maybe just change description to
N / n (Ruby) / knight (java)
, this will definitely fix things :DLOL. I hope not.
But if author is going to write something in description in the first place then the code at least ought to conform.
Anyway, markdown can be language sensitive. So no probs to keep language-specific meaningful names in both code/description, withtout all this (Ruby) (Java) nonsense.
Ruby translation kumited :) please review and approve ~~
Approved, thank you!
This comment has been hidden.
Try to look for more effective solution.
It's probably best to look for a pattern about when it's Black or White rather than try to just loop until you've caught the pawn. Though I would have assumed the loop would work as well - the kata may be written to make that kind of solution time out.
I'm sorry but either I'm unable to understand the description (likely as there are more than 800 solutions) or an input of
1, 5
should yield an output of"White", 9
instead of"White", 10
as it takes the same 4 moves as for an input of0, 4
which has the same initial horizontal distance. So what's wrong, can anyone explain, please?Remember, when K = 1 or 0, it is the same distance from the pawns at P= 5, for example.
Queen's Gambit hype :) Check out the new series from Netflix, interesting to watch, especially as a codewarrior!
One of the better Netflix shows. Although I started playing due to Covid - nice activity to pass the time.
I was thinking that the Knight would pause and stop turning direction when he had just caught a pawn.
The whole Knight movement is a jump, not a slide.
Wow this was fun :) nice Kata!
seems java is too fast
=> needs something like 15k or 20k random tests (or rather, go with 5k tests, but using longs instead of ints)
Please check if it's fixed, random tests are huge now
:+1:
note: would you care to add another batch of random tests with small inputs?
sure, but not now, I have school right now
no problem, you can do it later. ;)
zLuki, note you can use
LongStream.longs(long, long)
for easy generation of random numbers.This comment has been hidden.
Hi,
Your approach isn't working here because of the performances aspects. You cannot pass the tests as long as you use a loop (edit: because that will make your solution too slow, not because they are restricted somehow!).
=> Try to think about another approach.
cheers
PS: plz, use markdowns formatting when you post code.
Thanks, will do.
Output has to be a _tuple_ (python, haskell, Rust, prolog), an _array_ (javascript), an _object_ (java), or a _structure_ (C) with:
This should probably change to something like:
Output should be a container (see examples for language specific data types) that should have:
to prevent a continued developing mess in the description as new languages are added.
Duly noted for future Kata's. Thank you.
Sometimes it's difficult to make the description completely language neutral and avoid merge conflicts. But even then, resolving of merge conflicts can be easier when language conditional paragraphs are used. I think it's easier to resolve a merge conflict when a paragraph is added compared to when a line is modified.
This comment has been hidden.
Forked translation.
You should close all these suggestions once the translations are approved.
Approved and thank you!
Rust translation kumited.
Thank you - approved!
I'm confused, the max horizontal position is 1,000,000 but random tests exceed this and my runtime is too long for them?
Loop based solutions are expected to fail, so if you do a step by step simulation, it's not the right approach. Python tests (you solve it with Python, right?) do not exceed 1_000_000 on input, but mind that in a single test case, as the pawns move, their distance from the beginning of the booard will increase.
Awesome, thanks for the help :)
Haskell translation
Approved.
Thanks!
It is unspecified if the knight moves first, the pawns move first, or all movement occurs simultaneously. There is an example, but examples are not a substitute for specification, and it only rules out "knight moves first".
It is also unspecified what should be returned for
P = 0
orP = 1
. Depending on how literally you take the backstory, all sorts of mayhem can happen.Regarding who moves first - you mentioned that JavaScript does not work that. Is this an issue with JavaScript itself, solution or description?
I have added in the notes that Knight will always move first.
Regarding
P = 0
orP = 1
, in description it is stated thatP
will be at least 2.Description example and python tests works only if knight doesn't move first.
pawn move first and simultaneously are equivalent.
Python, C and javascript seem equivalent (pawn first).
The platform itself is based on chess. In order for a peace to capture another one, it has to be on a square already and not to appear there simultaniously.
It was my assumption that I took as implicitly known fact. Should I explicitly note it?
Ah sorry -
P >= 2
is there. I had missed that.The chess similarity only goes so far of course - there is no red in chess, and no ( two ) million wide boards either. So relying on implicitly known facts about how capturing works is a bit iffy.
Just specify pawns move first, and the whole problem goes away. Capturing will just work as in chess, no assumptions or specifications needed.
ETA: wrote this before I noticed "Knight moves first" was now specified. That really should be "Pawns move first", or the example is wrong ( and, presumably, all solutions and all tests ).
That is a bit embarassing - I should have payed closed attention. Yes, Pawn moves first.
I changed description and thank you for your patience and contribution.
And I missed
P >= 2
. We're all all too human.Thanks for fixing it. :]
Java Translation kumited. Before approving, approve C version of rowcased and merge the descriptions :)
Could someone please have a look -it gives me 2/2 tests passed. I'm not sure that's the way it should be.
It's counting
it
headers, which aggregate tests, not individual tests. It's expected. Haskell works the same way. ( If and when a test fails, the wholeit
block is stopped and failed and no further tests are run. )@CarbonStrings my java translation works fine now :)
I'm still having
Description cannot be approved, recent changes from related record must be merged first.
Not sure what to do about it.
Fork the translation and resolve the description merge conflicts.
Translation author should do that, though you can do it yourself.
Here's what I have so far:
Could you please advise how to take it from here. Also is there anything I could have done to prevent this from happening?
Can't prevent it from happening.
Unless you can write a description that will be exactly the same in every language ( and you never make mistakes that require changing it later ).
I'll wait till @zLuki fixes his translation, he was first after all :P
@B1ts how can I fix that? I already did a new fork and copied the whole description into my translation and added the java part. What is best practice here, how to fix it? I'll ask on gitter
OK guys - I don't know what to do at this point. I'm looking at the description and see things that I can't understand, like:
<<<<<<< older
||||||| mine
Do I need to edit here or should I wait for translator to do that? Without some guidance I won't be able to approve translations for Java and Prolog.
Just wait, I try to fix it
Ok java is approved now @CarbonStrings
Finally - thank you!
JavaScript - All OK C - All OK Java - All OK Haskell - All OK Rust - All OK Prolog - All OK
C Translation kumited. Cheers!
Thank you - approved!
Javascript Translation - please review and approve :)
Done! Thank you for taking your time!
No problem. An other question, for other languages example C where it is not possible to make a tuple/array with different datatypes, then how would you solve the problem?
For C, I'd suggest:
Good question @zLuki, thanks for the response @hobovsky. I had not seen this discussion when I began translating, but it turns out I went with option 2.
Approved for JavaScript, and thank you for translation!
The comment in the initial solution says "return the two oldest ages in the array of ages passed in".
Thank you - fixed :)
It might be worthwhile to add the upper limit of P to the description.
Thank you for the feedback. I have added 1000000 us upper limit.
Thank you - suggestion resolved.
Description should specify who moves first.
This comment has been hidden.
JavaScript does not work that way. It assumes the pawns move first.
I have added specification in description:
If knight moves first,
(0,4) => (Black,6)
and not(White,8)
.Am i missing something, or black and white should be inverted?
I'm not sure what you mean. Black pawn is on a white square and white is on a black.
Using example in description:
K2,1
-P5
-K4,0
-P6
-K6,1
and captures white pawn in 6P5
-K2,1
-P6
-K4,0
-P7
-K6,1
-P8
-K8,0
and captures black pawn in 8Well I did multiple tests on Excel and it seems right. Although I don't have an IQ of 160.
Maybe I miss something. What is the sequence of moves in the example?
This comment has been hidden.
And the whole sequence?
What is wrong in
0,0
->2,1
->4,0
->6,1
->8,0
?Fixed, thank you for pointing this one out.
Thank you - resolved!
wow, that was impressive, well done!