Created
July 8, 2012 14:06
-
-
Save pocari/3071046 to your computer and use it in GitHub Desktop.
android pattern auth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#android pattern auth | |
#0 1 2 | |
#3 4 5 | |
#6 7 8 | |
$constraints = [ | |
{2 => 1, 8 => 4, 6 => 3}, #0 | |
{7 => 4}, #1 | |
{0 => 1, 6 => 4, 8 => 5}, #2 | |
{5 => 4}, #3 | |
{}, #4 | |
{3 => 4}, #5 | |
{0 => 3, 2 => 4, 8 => 7}, #6 | |
{1 => 4}, #7 | |
{0 => 4, 2 => 5, 6 => 7} #8 | |
] | |
def search_helper(list, current, max_step) | |
if list.size == max_step | |
p list | |
else | |
(0 .. 8).each do |pos| | |
unless list.include? pos | |
if (not $constraints[current][pos]) or | |
($constraints[current][pos] && list.include?($constraints[current][pos])) | |
list.push(pos) | |
search_helper(list, pos, max_step) | |
list.pop | |
end | |
end | |
end | |
end | |
end | |
def search(max_step) | |
(0 .. 8).each do |start| | |
search_helper([start], start, max_step) | |
end | |
end | |
def search_all | |
(4 .. 9).each do |max_step| | |
search(max_step) | |
end | |
end | |
search_all |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment