Skip to content

Instantly share code, notes, and snippets.

@pocari
Created July 8, 2012 14:06
Show Gist options
  • Save pocari/3071046 to your computer and use it in GitHub Desktop.
Save pocari/3071046 to your computer and use it in GitHub Desktop.
android pattern auth
#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