Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The protagonist didn't build them a space station - they have effectively shown understanding of the problem by reducing it to the problem it really is (cycle detection) showing them he understood the idea and not just how to solve it while using modern tools and correct abstractions (sequences, really).

It's especially "provoking" since the author mentioned it was a Python shop and Python is _full_ of these - a lot of lazy sequences and generators all around and a community that understands them well too.



Except that it's not about cycles detection in a linked list. It's about thing as simple as 'if I am where I have aleady been then I'm screwed'. You just need to remember stuff and recall it as quickly as possible, so hashmap. It's finite because size of the board is finite. End of story.

His solution is just worse. His solution is slower because he picked inadequate data structures and he used algorithm for finding cycles that's only interesting because it can operate in fixed space but it's use is totally stupid because he constructs the linked list himself and that takes in worst case amount of memory proportional to number of fields on the board.

It's a task you can figure out just by thinking few minutes about the problem without any prior knowledge so a good test question for checking your ability to think.

The only reason you might come up with the solution OP presented is if you were told to 'do it as if js was haskell or something'


Where does the solution given use On space?


Sorry. My mistake. It doesn't. It cheats its way out of it by running game twice instead. That's why it needed to turn Game into iterable or at least generator function not just a generator intance.


Not to worry. I have it on good authority that the author thinks all three fictional parties are at fault.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: