souvikdutta1
BAN USER389112
Consider the Android grid as a matrix -
0 1 2
3 4 5
6 7 8
any valid move is one which has length greater than 4 and does not have any illegal jumps (like going from 1 to 3 without visiting 2).
The solution basically checks all possible patterns for illegal jumps and eliminates the illegal patters.
Java Code for Solution -
package PracticeStuff;
import java.util.HashMap;
public class AndroidLockScreen {
static boolean [] visited={false,false,false,false,false,false,false,false,false};
static HashMap<String, String> illegal=new HashMap<String,String>();
static int count;
public static void main(String [] args){
illegal.put("02", "1");
illegal.put("06", "3");
illegal.put("08", "4");
illegal.put("17", "4");
illegal.put("26", "4");
illegal.put("28", "5");
illegal.put("35", "4");
illegal.put("68", "7");
illegal.put("20", "1");
illegal.put("60", "3");
illegal.put("80", "4");
illegal.put("71", "4");
illegal.put("62", "4");
illegal.put("82", "5");
illegal.put("53", "4");
illegal.put("86", "7");
for(int i=0;i<9;i++)
getMoves(i);
System.out.println(count);
}
static void getMoves(int i){
int length=0;
visited[i]=true;
for(int j=0;j<9;j++){
if ((visited[j]!=true)&&(validmove(i,j))){
getMoves(j);
}
}
for(int k =0;k<9;k++){
if (visited[k]==true)
length++;
}
if (length>=4)
count++;
visited[i]=false;
}
static boolean validmove(int i, int j){
String y = i + "" +j;
//System.out.println(y);
String x =illegal.get(y);
if (x==null)
return true;
return visited[Integer.parseInt(x)];
}
}
Consider the Android grid as a matrix -
- souvikdutta1 January 19, 20160 1 2
3 4 5
6 7 8
any valid move is one which has length greater than 4 and does not have any illegal jumps (like going from 1 to 3 without visiting 2).
The solution basically checks all possible patterns for illegal jumps and eliminates the illegal patters.