6 kyu

Hamiltonian cycle: create one !

Description
Loading description...
Puzzles
Graph Theory
  • Please sign in or sign up to leave a comment.
  • ahmet_popaj Avatar

    Funny kata.

  • saudiGuy Avatar

    image is broken in the description.

  • sid114 Avatar

    python fork which solves @elephantcastle2 's issue below

    please review carefully

  • mdandre Avatar

    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.

  • Sazonove Avatar

    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?

  • Kees de Vreugd Avatar

    This comment has been hidden.

  • benjaminzwhite Avatar

    This comment has been hidden.

  • SPDene Avatar

    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:

    • The kata's description doesn't tell me that the path is supposed to pass through every point (although the Wiki does)
    • The Wiki has vertices with links between them; the kata has a grid. I guessed that the squares of the grid correspond to vertices, but there was no indication of what links are allowed (can I move diagonally? can I skip over squares? is a "knight's move" allowed?). Based purely on the mention of "the snake game", I guessed (correctly, I think) that you should only be able to move to orthogonally adjacent squares, but I think this should be specified in the description.
    • The Wiki mentions that "the Hamiltonian path problem... is NP-complete", and has a link to another Wiki page which talks about big-O notation. This looks SCARY. It was not obvious that the kata is a far simpler problem. At one point, I was wondering how many mathematical papers on graph theory I would need to read to even understand the problem! I think this will discourage people from attempting this kata.
  • Unnamed Avatar

    The sample tests fail because the preloaded check is incorrect.

  • Voile Avatar

    Needs edge cases for 1 and a even number in the fixed tests.

  • Voile Avatar

    There are some obvious problems with the check function ;-)