Felix Xilef
Life's short, so I enjoy it the fullest
By Jorge Félix Banguera V
1. a complicated system of paths or passages that people try to find their way through for entertainment
2. an area in which you can get easily lost because there are so many similar streets or passages
https://dictionary.cambridge.org
A maze can be represented in different ways, one is a simple 2D image of it.
Another can be a set of coordinates related to other coordinates for possibilities of movements.
As a set of unique values randomly assigned to each position.
As a set of unique values assigned to positions with a purpose.
We will assign each position an index starting from 0, from left to right in columns and top to bottom in rows.
It can be compared at the end as a simple Array:
[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19]
The Maze defined as a Hash, with each key being the position, and the values being the next possible positions:
Maze = {
0 => [1, 5],
...
}
The START and FINISH points, in this case they will be:
START = 0
FINISH = 11
Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons a candidate ("backtracks") as soon as it determines that the candidate cannot possibly be completed to a valid solution
Wikipedia
For every possible choice, take it, if solution is found, return it, otherwise search for new possible choices. Repeat until no more possible choices found and go back. Repeat.
Use a recursive function to be called with initial params. Then it will call itself for every possible choice until it finds the solution or until there is no more choices to make.
the practice of describing numbers, expressions, etc. in terms of the numbers, expressions, etc. that come before them in a series.
https://dictionary.cambridge.org
A recursive procedure or routine is one that has the ability to call itself until it detects that some condition has been satisfied.
http://whatis.techtarget.com/
In a recursive algorithm, the computer "remembers" every previous state of the problem. This information is "held" by the computer on the "activation stack" (i.e., inside of each functions workspace).
Every function has its own workspace PER CALL of the function.
https://www.cs.utah.edu
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n.
Wiki
Codewars
let f = _ => _ < 2 ? 1 : _ * f(_ - 1)
def factorial(number)
return 1 if number < 2
return number * factorial(number - 1)
end
https://github.com/felixbanguera/ruby/blob/master/scripts_and_exercises/Backtracking/1_backtracking_with_arrays.rb
https://github.com/felixbanguera/ruby/blob/master/scripts_and_exercises/Backtracking/2_backtracking_with_list.rb
https://github.com/felixbanguera/ruby/blob/master/scripts_and_exercises/Backtracking/3_recursive_backtracking.rb
By Felix Xilef