User talk:Purple24: Difference between revisions

no edit summary
 
No edit summary
Line 3:
 
I am '''not''' a Ruby programmer and so don't know what your community would like to show as idiomatic code on RC, but thought that you might at least discuss it amongst your community. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 11:34, 4 January 2014 (UTC)
 
==Solve a Hidato puzzle==
Thank you for your interest in this task and the Ruby solution I proposed.
 
I notice that you have introduced ADJUST, I think you may have changed this from adj which I used as an abbreviation for adjacency. I have changed this and taken it out of the class.
 
I see these problems as a graph consisting of nodes connected by edges. Two nodes connected by an edge are adjacent, and the problem is to find a spanning tree for the graph which is usually further constrained to pass through a node in some order. So it is possible to use the same code (now a class called HLPsolver) to solve this and the knight's tour by simply changing the meaning of adjacency.
 
The changes you have made work for Hidato and Numbrix where the nodes are physically adjacent in the grid but fail for Hopido and Knights tour where the adjacent nodes are not physically next to each other.
 
For Knights' tour I would like to write:
<lang ruby>
require 'HLPsolver'
 
ADJACENT = [[-1,-2],[-2,-1],[-2,1],[-1,2],[1,2],[2,1],[2,-1],[1,-2]]
 
boardx = <<EOS
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
EOS
HLPsolver.new(boardx).solve
</lang>
 
Do you have any ideas, before I attempt to fix it? Thanks in advance--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 13:47, 30 May 2014 (UTC)
2,172

edits