4 kyu
Determining if a graph has a solution
1,176 of 1,599damned3
Loading description...
Algorithms
Data Structures
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.
JS function name should be
camelCase
, backward compatability fix is adviced !In Python version, reference solution sometimes expects false, when path exists
should be fixed, please reset trainer and verify.
It was not actually a problem with the reference solution (since no reference solution is used) but I found and fixed a bug where randomly generated nodes were not guaranteed to be unique, which may have been the problem.
.
Python Fork
Python:
should be fixed
While its now an adjacency list, the tests never actually produce a case where multiple edges leading from a node matter (ie. simply directly casting the input to a dict still works).
Now looking at the tests, I see there aren't even random tests? I think this translation should not have been approved.
Does any language have random tests? Your fork is approved.
I've made a fork implementing random tests. I think they should be reasonably balanced. Performance requirements could potentially be scaled up further. If the tests work alright then they could be a basis for random tests in other langs.
Haskell (maybe Purescript too?) has random tests but they are very weak, at best. But issues with existing languages should not impact the quality of new translations.
awtsh, you got me there
Description should be language-agnostic.
"Should reach all nodes in a loop" What does this error mean?
It's not an error, it's simply the title of a particular test group. What you're looking for is what is shown inside it.
Thank you, there was a problem with my code.
Ruby Translation (author inactive)
Elm translation written, please approve!
Python translation written, please approve!
updated to 3.11 and approved
This comment has been hidden.
This comment has been hidden.
PureScript Translation Kumited - please accept :D
This comment has been hidden.
This comment has been hidden.
To clarify, this is "only" a problem in JavaScript but the random tests in Haskell are next to useless as well, considering the way in which they are currently generated.
Scala translation
Error:
As of 10/02/2019, I solved the Kata in Haskell without having to edit the module name so I assume this Kata issue is fixed.
Haskell
That was fun.
what does "Should reach all nodes in a loop" mean? Is there an error in the last test code?
The arcs in the Haskell version are actually directional. Please either change the description or modify the test cases.
As of 10/02/2019, the Kata Description makes it very clear that each edge in the given graph is unidirectional.
I really like this kata! Nice link with mathematics. However, you could make it a bit harder by requiring the user (in at least one test case) to actually jump to an earlier node, as in start > end. I was able to pass this kata by just ignoring all the loops.
This comment has been hidden.
Nice Kata.
Is there an error in the test code? I am only asking because I get all examples correct except for 'a to a' in the simple arcs section. But the arcs array looks to be missing something (either {start:b,end:a} or {start:a, end: a}) see below.
describe("Simple graph with 1 arc", function() { var arcs = [ { start: "a", end: "b" }, ]
There aren't any issues in either the Sample or Submit tests. For the directed graph with a single edge
graph = {a -> b}
,solve_graph('a', 'a', graph)
should evaluate totrue
since you have already reached vertexa
by starting at vertexa
- there is no need to traverse any directed edge to reach the desired destination.This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I don't really understand why one would do such a thing, because these are tests, and we're in javascript. In Java the variable would have been final. Anyway, I added a notice not to modify the list. Does that corresponds to what you wanted ?
By the way, thanks for completing this kata. It has been stuck in the 'Waiting for moderator approval' phase for many months, and I fear it would have been forgotten otherwise.
I was a tad confused what you were going for when I first scanned through the description. Some background on the data structure and the concept would greatly improve this kata IMO.
Also, fun kata!
You sure ? I thought I said the strict necessary to understand the kata, without giving a lecture on graphs. But, you're right, I could put a link to the Wikipedia concepts
EDIT : Finally, I added a sentence to explain the format of arcs. Is that what you meant ?
EDIT 2 : I also added the two suggested links
I guess I'm more accustomed to a scientific writing style (background, procedure, results, discussion). I translate that in my writing style to some background, some clarifications of procedure (in particular an explanation of inputs), and expected results. Discussion, meanwhile, typically would occur on this page.
Thank you for your comment,
As this is the first kata I make, I didn't know thesingle quote trick, I'll correct it.
I've checked for similar katas on Codewars before creating mine, to avoid duplicating an existing one, and indeed there are similar ones, but they do not work quite the same. For example, there's a kata about finding the shortest path on a graph. But there was none about finding if a graph has a solution or not.
As for the Solution Setup part, I thought it was only for setting up variables and stuff needed for both the correct solution and the user's solution. Now I know what it is about. I'll check it out
Looks great! Good job with your first kata!
You need to include the basic function signature in the Solution Setup part of the kata creator, like existing katas.
You also should wrap code inline snippets in single backticks (
`solve_graph(start, end, arc)`
), so they stand out in the text, like this:solve_graph(start, end, arc)
. I recommend using it on values such as0
,true
andfalse
as well. It makes them stand out much better.I also recommend changing the last sentence to:
I think it's a lot clearer, since you are specifying that a list of nodes isn't provided, that the list of arcs is not a conclusive list of nodes.
(As a side note: I feel like I've already solved this on Codewars, but that doesn't mean anything. I couldn't find anything searching for graph, vertex, path, or edge, so maybe it's just similar to others. If anyone else can chime in, that would be great.)