5 kyu
Cargo-Bot Interpreter
57 of 59scarecrw
Loading description...
Interpreters
Games
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.
Haskell translation
The description has been updated only to distinguish language-specific information.
Approved. This looks great! Thanks for your work on this.
In Haskell, the
Crate
s add frustration only.Please can the
Show
instance make them transparent? The current instance maximises visual clutter, with the uselesscolor
accessor.I changed the
Show
instance in preloaded, let me know if that works better.Lots better, thanks.
Crate
from final tests is not the same asCrate
from sample tests.This prints
Crate(color='YELLOW') is a Crate.
while testing, butCrate(color='YELLOW') is NOT a Crate.
while attempting.Unfortunately,
Crate
needs to be redefined in the testing code to be inaccessable to the solver, so you only have access to the definition from preloaded. namedtuples can still be compared with__eq__
from two definitions, but I'm not sure if there's a way to compare them withis
or withmatch
statements.It's an unfortunate effect from a poor choice made early on to use namedtuples, but I'm not sure what difference it makes when solving. There are no invalid inputs and you can still match on
crate.color
perfectly fine.the test code could likewise read out the data and compare that instead of insisting on its own separate definition. could also get fancy and render the states like the drawings in the instuctions. or, only show the preloaded one to the user and then compare with a separately defined type for the expected value. codewars_test does do actual == expected though which is arguably wrong and it should instead do expected == actual
Alright, swapped to pass
preloaded.Crate
objects and then compare with a test-suite defined version. The example provided now works as expected.I think my code works fine. I logged every action and found it working as expected. I think the solutions may be wrong..?
It doesn't look like you're handling conditional flags on program commands correctly.
In the future, please only raise issues if you have a specific example that you can show isn't working according the description.
Thanks. Other than that, great kata.
I'm not sure if this kata is not forcing timeout too quick, i think my answer was not too bad
There're no performance requirements in this kata, and your solution passes the tests in
~100 ms
. What are you talking about?im pretty sure there is 12k ms and deep recursion test is over 10k moves
same issue
All kata have a timeout (for python this is 12 seconds) but this kata does not include tests intended to restrict solutions based on execution time. Most submitted solutions can solve all the tests (including the deep recursion test) in well under a second. If your code is timing out, I would look for unintended infinite loops or similar. You can check out these troubleshooting tips for more info.
10k is a very small number of operations - a reasonable solution can pass the "deep recursion" test in
~10 ms
. If your solution times out, either you aren't using themax_steps
limiter, or your code is genuinely 1200+ times slower than what other people have written which is unacceptably bad.Crate
andCommand
should not be regular classes at all.provide information or just close this issue. Thx
Provide info about what? How to choose a meaningful data representation? Which representation is fitting in this particular case? How to get rid of the delusion that "OOP is used to model real-life objects"?
that would be enough
With the current setup
Crate
is astr
(ornamedtuple
if the author really wants it to imitate a separate class) andCommand
is clearly atuple
/namedtuple
.I'll be honest, I'm not very familiar with
namedtuple
s, but from reading, it does seem like a better choice. I originally went with an OOP aproach before deciding exactly how the Kata would work, and looking back see why it may not be a good choice.I have some time today, so I'll give a shot to using them.
Thanks for the feedback!
Alright, I've replaced the Crates and Commands with
namedtuple
objects. Let me know if there are any errors in my attempt or any other issues.Thanks!
And why are you inheriting from the namedtuple-classes instead of using them directly? This is pointless, and you're overriding
__repr__
incorrectly anyway.I was inheriting from them in order to override
__repr__
. Is there a better way to do this? Or would it be best to just leave the default__repr__
as is?That was a rhetorical question... And you don't need to inherit from a class to change its
__repr__
method.Do you know how
__repr__
(and__str__
) should be used at all? As I see, you don't, so you really should read the documentation.Alright, I've removed the unnecessary inheritance. Let me know if there's anything else I should change. Thanks!
Damn, I clicked on
edit
instead oftranslate
to check the current setup... It looks fine now, and if all the issues are resolved, I can approve the kata since I'm (probably) a contributor anyway.Awesome, thanks for the feedback.
Hi,
__eq__
method in the Crate classother
not being a Crate instance), meaning the user can end up with weird error messages about a missing color attribute out of the blue.It's not totally clear by reading the description only if what is defined in preloaded is 4 "constants", or just the class.
That wording suggests that we are dealing with 4 constants, while only the class is in preloaded. => Needs a rewording.
that info could be provided when you describe the moves (makes more sense to have everything in the same place, imo. But that's a suggestion only)
the info just below about the length of the programs could be suppressed, imo
it
block)Cheers
Thanks for all the helpful feedback!
I've implemented your latter three points. As for the first one, I fixed the
__eq__
method to account for non-crate objects, but I had a couple questions as to the rest:__eq__
and__repr__
) My concern was overcomplicating the description, but I can see how leaving it out could lead to confusion.Crate
andCommand
classes in the test suite, am I correct that this would invalidate any solution that attempted to construct its own crates? I wouldn't expect this to be a common approach, but I do see one current solution (here line 30) that makes use of this.About documentation, you can just say what methods are defined for each class without giving the code (as long as it's working in all situations ;o ).
About redefining the classes: the users will use the classes in preloaded, that will have the exact same interface, hence behaviors, than those you'll copy/paste in the tests. So that shouldn't cause troubles as long as the users don't try to add methods on the fly or stuff like that (might be worth of adding a note about that, tho / about that solution, as far as I can see, they didn't touch to your classes and built a State class that is only relying on the data held by your classes, and not their "implementation").
Alright, I've updated the description and copied the classes to the test suite.
Let me know if there's anything else amiss. Thanks again for your help!
your
__eq__
implementation still isn't correct. Use this instead:Oh, and you need to add the
__hash__
method, since you provide__eq__
(that shouldn't be useful, but just so that the objects behaves properly if an user tries to build sets of dicts):Other than that, the kata looks ok.
That's the implementation I had for
__eq__
at first, but it was causing a problem with a solution which constructed its own Crate object using the class in preloaded and compared it to a Crate object constructed in the test suite.I took FArekkusu's note and switched to
namedtuple
objects. Am I correct in assuming that, as tuples, they should be hashable and comparable by default?yes, namedtuples should resolve all the problems at once. But as FArekkusu pointed out, you're currently using them the wrong way ;)
Well, learned something new! Looks like it's resolved now. Thanks again for the help!
Ambigious description of "directly below":
To me directly below means that there can't be a vertical gap between the claw and crate. But your example shows it means any crate anywhere vertically below the claw.
If the claw is empty and there are no crates directly below, nothing happens.
I suggest to make the description more clear.
Good point.
I've changed it to:
Hope that's clearer!
Please add a proper
__repr__
method toCommand
as well so commands are displayed as something readable and not something like<preloaded.Command object at 0x7fdbb97e8970>
.Done. Thanks for the suggestion!
Still new to authoring, so don't hold back with feedback! Thanks!
It's a fun kata, and you've put alot of effort in the description and test cases. Well done :)