6 kyu
Hamiltonian cycle: create one !
80tortar
Loading description...
Puzzles
Graph Theory
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.
Funny kata.
image is broken in the description.
can you check again ? looks like it was just a temporary downtime from the hosting website
Right. Now ok.
python fork which solves @elephantcastle2 's issue below
please review carefully
cheers
approved by someone
Are test working? (Python)
Traceback (most recent call last): File "/workspace/default/tests.py", line 3, in <module> from preloaded import is_hamiltonian_cycle ImportError: cannot import name 'is_hamiltonian_cycle' from 'preloaded' (/workspace/default/preloaded.py)
I think it should be renamed to is_cycle.
this error happens only in sample tests, random tests are working fine
k, but ones wastes times for nothing anyway because of wrong setup. thanks for the fork
Accepted fork by Siddharth114!
My code is ok for most of the cases, but in some cases it gives output like this: Traceback (most recent call last): File "/workspace/default/.venv/lib/python3.10/site-packages/codewars_test/test_framework.py", line 112, in wrapper func() File "/workspace/default/tests.py", line 30, in _ test.assert_equals(is_cycle(find_cycle(a,b),a,b), exp,msg) File "/workspace/default/tests.py", line 10, in is_cycle return path[0] == path[-1] and len(set(path)) == a*b and all((abs(pos_2[0]-pos_1[0]),abs(pos_2[1]-pos_1[1])) in moves and TypeError: 'NoneType' object is not subscriptable Isn`t it a mistake in the checking?
If you Google (other search engines are available, this is not an endorsement) the exact phrase: "TypeError: 'NoneType' object is not subscriptable" you will find the answer to your question.
Basically you are trying to are trying to access the index of something that has a
None
value; check the first few Google results to see how this can happen.If you want to troubleshoot you can add a print statement
print(my_variable)
for the different steps of your code to see where aNone
value is getting returned.ofc i googled error before leaving comment and ofc i tried to debug it. The None variable is placed somewhere in checking function. I just dont have variables with names that are in the error output.
most likely means that your function is returning None in some cases (when it shouldn't), and that the testing function should be updated to handle that more gracefully.
updated. Should be good now.
Don't forget to copy your code and then reset the trainer.
This comment has been hidden.
Never mind... reversed the x and y coordinates and now it works. Would be helpfull if we know beforehand what is a and what is b (x or y-axis)
It does define x and y in the description.
This comment has been hidden.
done while approving, except for the indices names.
a and b are just grid dimensions. It's completely arbitrary which one might represent the number of rows and which one for columns.
Well, no ... I mixed them up in my first try and the tests didn't accept my mirrored coordinates.
After a LOT of guesswork, I've now completed "Hamiltonian cycle : check function" and "Hamiltonian cycle : create one !". I'm not a mathematician; until today, I'd not heard of Hamiltonian paths/cycles.
Here are some of the things that made this MUCH more difficult that it should be:
Thank you very much for all the suggestions! I updated the description , Do you think it's ok now? I thought the description was clear because I 'invented' the problem and it made sense to me in the way it was implicitly , but (now) I see that it's much better with what you suggested.
That's much less scary! :)
minor typo: adiacjent
Can you consider to change your feedback? If you think that now it's worth to complete the kata :) Edit : Thanks!
Well done for giving the kata a fair crack. I've just come across it and felt the current description is really easy to understand—will have a go shortly as this looks like a fun one!
The sample tests fail because the preloaded
check
is incorrect.I thought that i had fixed it , thanks!
Needs edge cases for
1
and a even number in the fixed tests.Fixed
There are some obvious problems with the
check
function ;-)I didn't think about that!
Is it ok now?
It's not, as my solution demonstrates (:
It's strange because in the fork your code doesn't pass :&
It should be fixed!