User talk:Purple24

From Rosetta Code

Ruby and irb in examples[edit]

Hi Purple24; I saw your edits to Y combinator#Ruby, which which might well be fine. I just thought I would mention that for the Python language some examples are kept in the REPL format as it emphasises how one works in some cases. The language entry "Notes" section asks editors to not consider the showing of the command line as a necessary problem that needs fixing.

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. --Paddy3118 (talk) 11:34, 4 January 2014 (UTC)

Solve a Hidato puzzle[edit]

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:

 
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
 

Do you have any ideas, before I attempt to fix it? Thanks in advance--Nigel Galloway (talk) 13:47, 30 May 2014 (UTC)