A greedy algorithm seems to be successful with the graphs in this game. Pick the node with the highest degree, connect it to the other nodes with the highest degrees, repeat.
I just tried this and several times the highest degree was already connected with the lowest degree, so I either had to pick another highest degree node (if there was a tie), pick the next highest degree and connect it with the lowest degree, or pick the next lowest degree and connect it with the highest degree. They all seemed to work out okay.
I find it interesting that yours appears simpler on the face of it, but has more edge cases. Seems like mine would be simpler if you were actually writing out the steps properly.
A naive greedy algorithm will eventually find a situation where the two nodes with the highest degrees are already connected. Another place where a simple greedy algorithm falls down is a field of many nodes with the same degree, where the greedy algorithm doesn't give information about which two to connect. I think the problem is a bit deeper than it seems in the first few iterations.
Pick the node with the highest unassigned degree, connect it to the other unconnected nodes with the highest unassigned degrees (where unassigned degree is the difference between the target degree and the degree of edges we've assigned in previous iterations)
I don't fully understand your second point. If there isn't a requirement to create a connected graph it can pick arbitrarily between nodes of equal unassigned degrees.
[1] My brain is too tired to come up with a better term than unassigned
This is nice! I got stuck and gave up when there got to be nodes with 6s on them, but that's just because I'm in class.
Given that the only reason to select an edge right now is to delete it, perhaps the delete action could be mapped to a click, rather than a click plus a backspace. Also, a reset level button would be nice.
If you want to reach people in the wide wide world, explain what a degree sequence is in the first paragraph! This is your chance for a bit of mathevangelism!
I have not looked over the Havel-Hakimi algorithm yet, but here's the best way I've found to solve these (with 100% success rate so far)
1. Pick the node with the highest degree
2. Make all the connections for that node until it has a value of zero by connecting it with the highest-value node that it isn't already connected to
The way that I see it is that since the highest-degree node needs to make X number of connections, ensure it can make all of those connections before worrying about anything else. In this case, that means start by connecting the 4 to the next highest value node - the 3, then the 2, then the other 2, then the 1.
My intuition on this was similar - Pick the highest degree node and connect it to a node of the same degree if available or to one with the next-highest degree, preferring nodes with less connections over those with more. Repeat.
Worked for me so far, and I'm about 6 levels in with the largest node being 8.
It reminds me of the 'bridges' game from Simon Tatham's Portable Puzzle Collection. It has the additional restriction that edges cannot cross each other.
This should keep a completed level on the screen until you click to advance.
Also, deleting links needs some work: I think the hit detection is too small. Also, a mouse-only way to delete would be nice -- how about right clicking? Double clicking would be another possibility (and I assume more touch friendly).
Pretty fun game. I thought that greedy algorithm would not work with this problem, so I wrote a basic genetic algorithm to find a solution, refining it as I went.
27 comments
[ 5.3 ms ] story [ 57.5 ms ] threadI find it interesting that yours appears simpler on the face of it, but has more edge cases. Seems like mine would be simpler if you were actually writing out the steps properly.
Pick the node with the highest unassigned degree, connect it to the other unconnected nodes with the highest unassigned degrees (where unassigned degree is the difference between the target degree and the degree of edges we've assigned in previous iterations)
I don't fully understand your second point. If there isn't a requirement to create a connected graph it can pick arbitrarily between nodes of equal unassigned degrees.
[1] My brain is too tired to come up with a better term than unassigned
Given that the only reason to select an edge right now is to delete it, perhaps the delete action could be mapped to a click, rather than a click plus a backspace. Also, a reset level button would be nice.
1. Pick the node with the highest degree 2. Make all the connections for that node until it has a value of zero by connecting it with the highest-value node that it isn't already connected to
For example, in this scenario: http://i.imgur.com/O8MlWzz.png
The way that I see it is that since the highest-degree node needs to make X number of connections, ensure it can make all of those connections before worrying about anything else. In this case, that means start by connecting the 4 to the next highest value node - the 3, then the 2, then the other 2, then the 1.
This leaves the following situation: http://i.imgur.com/9vZjafr.png
It's kind of easy to see where it goes from there. Sure this is a simple example, but as I said it's worked 100% of the time I've tried it.
http://en.wikipedia.org/wiki/V._J._Havel
is not the better known Czech politician of the same name
http://en.wikipedia.org/wiki/V%C3%A1clav_Havel
Worked for me so far, and I'm about 6 levels in with the largest node being 8.
http://en.wikipedia.org/wiki/Hashiwokakero
http://www.chiark.greenend.org.uk/~sgtatham/puzzles/
(Say goodbye to your productivity if you like puzzles).
reward my success!
Also, deleting links needs some work: I think the hit detection is too small. Also, a mouse-only way to delete would be nice -- how about right clicking? Double clicking would be another possibility (and I assume more touch friendly).
Bit of overkill, but fun game overall !