Advertisement
Guest User

Android graphical password combinations

a guest
Mar 30th, 2013
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. import java.awt.Point;
  2. import java.util.ArrayList;
  3.  
  4. public class Main {
  5.     public static Point[][][] restricted = new Point[][][]{{{new Point(0, 2), new Point(2, 0), new Point(2, 2)}, {new Point(1, 2)}, {new Point(0, 2), new Point(0, 0), new Point(2, 2)}},
  6.                                                            {{new Point(2, 1)}, {}, {new Point(0, 1)}},
  7.                                                            {{new Point(0, 0), new Point(2, 0), new Point(2, 2)}, {new Point(1, 0)}, {new Point(0, 2), new Point(2, 0), new Point(0, 0)}}};
  8.    
  9.     public static void main(String[] args) {
  10.         System.out.println(step(null));
  11.     }
  12.    
  13.     public static int step(ArrayList<Point> path) {
  14.         int stepCount = 0;
  15.        
  16.         if (path == null) {
  17.             for (int i = 0; i < 3; i++) {
  18.                 for (int j = 0; j < 3; j++) {
  19.                     ArrayList<Point> currPath = new ArrayList<Point>();
  20.                     currPath.add(new Point(i, j));
  21.                     stepCount += step(currPath);
  22.                 }
  23.             }
  24.         } else {
  25.             if (path.size() >= 4) {
  26.                 stepCount++;
  27.             }
  28.            
  29.             int id = path.size() - 1;
  30.            
  31.             for (int i = 0; i < 3; i++) {
  32.                 for (int j = 0; j < 3; j++) {
  33.                     // точка уже пройдена
  34.                     boolean can = true;
  35.                     for (int k = 0; k < path.size(); k++) {
  36.                         if (path.get(k).x == i && path.get(k).y == j) {
  37.                             can = false;
  38.                         }
  39.                     }
  40.                    
  41.                     if (!can) {
  42.                         continue;
  43.                     }
  44.                    
  45.                     // можно ли перейти
  46.                     Point[] currRestr = restricted[i][j];
  47.                     can = true;
  48.                     for (int k = 0; k < currRestr.length; k++) {
  49.                         // нельзя
  50.                         if (currRestr[k].equals(path.get(id))) {
  51.                             can = false;
  52.                         }
  53.                     }
  54.                    
  55.                     if (can) {
  56.                         ArrayList<Point> newPath = new ArrayList<Point>(path);
  57.                         newPath.add(new Point(i, j));
  58.                         stepCount += step(newPath);
  59.                     }
  60.                 }
  61.             }
  62.         }      
  63.        
  64.         return stepCount;
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement