How to resolve the algorithm Solve a Hopido puzzle step by step in the Ruby programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Solve a Hopido puzzle step by step in the Ruby programming language

Table of Contents

Problem Statement

Hopido puzzles are similar to Hidato. The most important difference is that the only moves allowed are: hop over one tile diagonally; and over two tiles horizontally and vertically. It should be possible to start anywhere in the path, the end point isn't indicated and there are no intermediate clues. Hopido Design Post Mortem contains the following: "Big puzzles represented another problem. Up until quite late in the project our puzzle solver was painfully slow with most puzzles above 7×7 tiles. Testing the solution from each starting point could take hours. If the tile layout was changed even a little, the whole puzzle had to be tested again. We were just about to give up the biggest puzzles entirely when our programmer suddenly came up with a magical algorithm that cut the testing process down to only minutes. Hooray!" Knowing the kindness in the heart of every contributor to Rosetta Code, I know that we shall feel that as an act of humanity we must solve these puzzles for them in let's say milliseconds. Example: Extra credits are available for other interesting designs.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Solve a Hopido puzzle step by step in the Ruby programming language

The code is developed in Ruby programming language and uses the class HLPsolver to solve a puzzle. It uses the constant ADJACENT to represent the adjacent cells to a given cell. The variable board1 is a string that contains a puzzle to be solved. The line t0 = Time.now gets the current time, and the line HLPsolver.new(board1).solve creates a new instance of the class HLPsolver and calls the method solve to solve the puzzle. The line puts " #{Time.now - t0} sec" prints the time it took to solve the puzzle.

Source code in the ruby programming language

require 'HLPsolver'

ADJACENT = [[-3, 0], [0, -3], [0, 3], [3, 0], [-2, -2], [-2, 2], [2, -2], [2, 2]]

board1 = <<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 0 . .
. . . 1 . . .
EOS
t0 = Time.now
HLPsolver.new(board1).solve
puts " #{Time.now - t0} sec"


  

You may also check:How to resolve the algorithm FASTA format step by step in the Factor programming language
You may also check:How to resolve the algorithm Inheritance/Single step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Variables step by step in the Ruby programming language
You may also check:How to resolve the algorithm Ethiopian multiplication step by step in the Tcl programming language
You may also check:How to resolve the algorithm Metronome step by step in the C programming language