Epic Systems Interview Question
Software Engineer / DeveloperscheckDown (int y, int x, char u, char c)
Line1 of this function should be:
int down = y + 1;
(instead of x + 1)
Just a small typographical error.. otherwise does the job well.
private static boolean verify(String correctPasswor, String enteredPassword) {
char[] cor=correctPasswor.toCharArray();
char[] ent=enteredPassword.toCharArray();
for(int i=0;i<cor.length;i++)
{
if(!((Math.abs((int)cor[i]-(int)ent[i])==3) || (Math.abs((int)cor[i]-(int)ent[i])==1)||(Math.abs((int)cor[i]-(int)ent[i])==0)))
{
return false;
}
}
return true;
}
private static boolean verify(String correctPasswor, String enteredPassword) {
// TODO Auto-generated method stub
char[] cor=correctPasswor.toCharArray();
char[] ent=enteredPassword.toCharArray();
for(int i=0;i<cor.length;i++)
{
if(!((Math.abs((int)cor[i]-(int)ent[i])==3) || (Math.abs((int)cor[i]-(int)ent[i])==1)||(Math.abs((int)cor[i]-(int)ent[i])==0)))
{
return false;
}
}
return true;
}
HashMap is overkill and pointless, if you have to anyway go through the whole list of allowed digits for that particular key...
Just map digit to the row,colum.
bool CheckValidGuess(int securityDigit, int guess) {
int srow = securityDigit/3 + 1;
int scol = (securityDigit % 3);
if (scol == 0) { scol = 3;}
int grow, gcol = // similar to above
if ( (grow-srow)*(grow-srow) + (gcol-scol)*(gcol-scol) <= 1) {
return true;
}
return false;
}
Correction to the code :
public static boolean CheckValidGuess(int securityDigit, int guess) {
int srow ;
srow = securityDigit/3 + 1;
if(securityDigit%3==0)srow = srow-1;
int scol = (securityDigit % 3);
if (scol == 0) { scol = 3;}
System.out.println(srow);
System.out.println(scol);
int grow ;
grow = guess/3 + 1;
if(guess%3==0)grow = grow -1;
int gcol = (guess % 3);
if (gcol == 0) { gcol = 3;}
System.out.println(grow);
System.out.println(gcol);
if ( (grow-srow)*(grow-srow) + (gcol-scol)*(gcol-scol) <= 1) {
// System.out.println((grow-srow)*(grow-srow) + (gcol-scol)*(gcol-scol));
return true;
}
return false;
}
public boolean(int user_code,int enter_code)
{
int count=0;
boolean flag=true;
int temp1,temp2;
if(enter_code==user_code)
return true;
else
{
while(user_code!=0)
{
if(count<1)
{
temp1=user_code%10;
user_code = user_code/10;
temp2=enter_code%10;
user_code = enter_code/10;
if(temp2==0)
{
flag=false;
break;
}
if(temp1==temp2)
continue;
else
{
if(temp1==1 && (temp2 ==2 || temp2==4)///repeat for other digits
{
count++;
continue
}
}
else
{
flag = false;
break;
}
}
}
if(flag)
return true;
else
return false;
}
public boolean(int user_code,int enter_code)
{
int count=0;
boolean flag=true;
int temp1,temp2;
if(enter_code==user_code)
return true;
else
{
while(user_code!=0)
{
if(count<1)
{
temp1=user_code%10;
user_code = user_code/10;
temp2=enter_code%10;
user_code = enter_code/10;
if(temp2==0)
{
flag=false;
break;
}
if(temp1==temp2)
continue;
else
{
if(temp1==1 && (temp2 ==2 || temp2==4)///repeat for other digits
{
count++;
continue
}
}
else
{
flag = false;
break;
}
}
}
if(flag)
return true;
else
return false;
}
I guess the best and the fastest solution will be to check which one of the SecurityCode or EnteredCode is bigger and then get the modules result. This modules result can be checked against 5 values 0, -100, -300, 100 and 300. Value 0 to check if codes are same or else the modules result will always be one of -100, -300, 100 or 300, if there is a 1 digit error horizontal or vertical.
bool IsValidCode(int SecurityCode, int EnteredCode)
{
int ModResult = 0;
if (SecurityCode > EnteredCode)
ModResult = SecurityCode % EnteredCode;
else
ModResult = EnteredCode % SecurityCode;
if (ModResult == 0 || ModResult == -100 || ModResult == -300 ||
ModResult == 100 || ModResult == 300)
return true;
else
return false;
}
Oops sorry.. this solution will not work in all the cases. I think we will need to identify which digit is mismatching and repeat the same procedure for only that single digit. But in this case values to be checked against will be 0, -1, -3, 1 and 3. That should do the trick.
is it to
check difference=|SecurityCode - EnteredCode|
if difference=1000|| 2000|| 3000|| 6000 ||
100||200|| 300|| 600||
10|| 20||30|| 60||
1|| 2|| 3|| 6||
If yes, accept
otherwise, reject
// loop for each charater in the actual
// for that character, if the corresponding entered character does not match,
// check if they are opposite with respect to add/even
// if yes, increment error count.
// return false if error count is > 1
// return true at the end of all character check
// security code checker
static bool IsValidSecurityCode(int actual, int entered)
{
char[] actualChars = actual.ToString().ToCharArray();
char[] enteredChars = entered.ToString().ToCharArray();
int errCount = 0;
for (int i = 0; i < actualChars.Length; i++)
{
if (actualChars[i] != enteredChars[i])
{
int first = int.Parse(actualChars[i].ToString());
int second = int.Parse(enteredChars[i].ToString());
if ((first % 2 == 0 & second % 2 != 0)
|| first % 2 != 0 & second % 2 == 0)
{
errCount++;
if (errCount > 1)
{
return false;
}
}
}
}
return true;
// test
Console.WriteLine("Codes 1478, 1178 match: {0}", IsValidSecurityCode(1123, 1143).ToString());
public static boolean gird(int actual, int entered){
String s1 = Integer.toString(actual);
String s2 = Integer.toString(entered);
int errorCount = 0;
// check1: if both actual and entered length are not same
if(s1.length() != s2.length()){
return false;
}
// check2: If both the actual and entered are same
if(s1.equals(s2)){
return true;
}
for(int i=0; i< s1.length(); i++){
char c1 = s1.charAt(i);
char c2 = s2.charAt(i);
if(c1 != c2){
int mod = c1 % c2;
if(mod == -1 || mod == 1 || mod == 3 || mod == -3){
errorCount++;
}
else{
return false;
}
}
if(errorCount > 1){
return false;
}
}
return true;
}
public boolean validate(int valid,int entered){
int x,y,t1,t2,count=0,flag=0;
if(valid==entered){
System.out.println("Allow");
return true;
}
if(valid/entered >10 || valid/entered <1 ){
System.out.println("Do not Allow");
return false;
}
While(entered>0){
x=valid%10;
y=entered%10;
if(x!=y){
t1=x;t2=y;
count++;
}
if(count>1)
{
flag=1;
break;
}
entered=entered/10;
valid=valid/10;
}
if(flag==1)
{
System.out.println("Do not allow");
return false;
}
else if(((t1-3)>0 && (t1-3)==t2) ||((t1+3)==t2) ||((t1-1)>0 && (t1-1)==t2)||((t1+1)==t2)){
System.out.println("Allow");
return true;
}
else{
System.out.println("Do not allow");
return false;
}
}
public boolean validateEntry(String inserted,String realValue)
{
boolean valid = false;
if(inserted.equals(realValue))
{
valid = true;
}
else if(inserted.length() != realValue.length())
{
valid = false;
System.out.println("2");
}
else
{
int errorCounter = 0;
for (int i=0;i<realValue.length();i++)
{
System.out.println("3");
if(errorCounter>1)
{
i = realValue.length();
}
else
{
int c1 = Character.getNumericValue(realValue.charAt(i));
int c2 = Character.getNumericValue(inserted.charAt(i));
if(c1 != c2)
{
errorCounter++;
if(errorCounter == 1)
{
if( (c1/3) == (c2/3) || (c1%3) == (c2%3))
{
valid = true;
}
else
{
valid = false;
}
}else{
valid = false;
}
}
}
}
}
return valid;
}
/*
* There is a security keypad at the entrance of a building. It has 9 numbers 1
* - 9 in a 3x3 matrix format. 1 2 3 4 5 6 7 8 9
*
* The security has decided to allow one digit error for a person but that digit
* should be horizontal or vertical. Example: for 5 the user is allowed to enter
* 2, 4, 6, 8 or for 4 the user is allowed to enter 1, 5, 7.
*
* IF the security code to enter is 1478 and if the user enters 1178 he should
* be allowed.
*
* Write a function to take security code from the user and print out if he
* should be allowed or not
*/
public class SecurityKeypad {
public final static char[][] matrix = {
{ '1', '2', '3' },
{ '4', '5', '6' },
{ '7', '8', '9' }
};
public static boolean authenticate(String code, String userCode) {
boolean errorFound = false;
boolean valid = false;
if(code.equals(userCode)){
valid = true;
}else if(code.length() != userCode.length()){
valid = false;
}
else{
int codeLength = userCode.length();
for(int i=0; i<codeLength;i++){
if(code.charAt(i) != userCode.charAt(i)){
if(errorFound){
return false;
}
for(int m = 0; m<3;m++){
for(int n=0;n<3;n++){
if(matrix[m][n] == code.charAt(i)){
errorFound = true;
if(checkPrev(m,n,userCode.charAt(i), code.charAt(i))){
valid = true;
}
else if(checkNext(m,n,userCode.charAt(i), code.charAt(i))){
valid = true;
}
else if(checkUp(m,n,userCode.charAt(i), code.charAt(i))){
valid = true;
}
else if(checkDown(m,n,userCode.charAt(i), code.charAt(i))){
valid = true;
}
}
}
}
}
}
}
return valid;
}
private static boolean checkPrev(int y, int x, char u, char c){
int prev = x - 1;
if(prev >= 0
&& matrix[y][prev] == u){
return true;
}
return false;
}
private static boolean checkUp(int y, int x, char u, char c){
int up = y - 1;
if(up >= 0
&& matrix[up][x] == u){
return true;
}
return false;
}
private static boolean checkDown(int y, int x, char u, char c){
int down = x + 1;
if(down >= 0
&& matrix[down][x] == u){
return true;
}
return false;
}
private static boolean checkNext(int y, int x, char u, char c){
int next = x + 1;
if(next <=2
&& matrix[y][next] == u){
return true;
}
return false;
}
public static void main(String[] args) {
if(authenticate("1478", "1178")){
System.out.println("Success!");
}
else{
System.out.println("Failure!");
}
}
}
public class General {
static int width = 3;
static int height = 3;
static int securityCode[][] = new int[width][height];
static String code = "1478";
static String user_entered_code = "1278";
static int diff = 0;
public static void main(String[] args) {
int local = 1;
for(int i=0;i<width;i++){
for(int j=0;j<height;j++){
securityCode[i][j] = local;
local++;
}
}
for(int i=0;i<code.length();i++){
if(diff == 2){
System.out.println("Error");
break;
}
neighbours(code.charAt(i),user_entered_code.charAt(i));
}
if(diff < 2){
System.out.println("Success");
}
}
public static void neighbours(int or,int ur){
if(Math.abs(or - ur) == 1 || Math.abs(or - ur) == 3){
diff++;
}
else if(or == ur){
}
else{
diff = 2;
}
}
#include <iostream>
#include <stdlib.h>
using namespace std;
bool valid(char c1, char c2)
{
int cInt1 = c1 - '0';
int cInt2 = c2 - '0';
switch(cInt1)
{
case 1:
if(cInt2 == 2 || cInt2 == 4)
return true;
else
return false;
break;
case 2:
if(cInt2 == 1 || cInt2 == 3 || cInt2 ==5)
return true;
else
return false;
break;
case 3:
if(cInt2 == 2 || cInt2 == 6)
return true;
else
return false;
break;
case 4:
if(cInt2 == 1 || cInt2 == 5 || cInt2 ==7)
return true;
else
return false;
break;
case 5:
if(cInt2 == 2 || cInt2 == 4 || cInt2 ==6 || cInt2 ==8)
return true;
else
return false;
break;
case 6:
if(cInt2 == 3 || cInt2 == 5 || cInt2 ==9)
return true;
else
return false;
break;
case 7:
if(cInt2 == 8 || cInt2 == 4)
return true;
else
return false;
break;
case 8:
if(cInt2 == 5 || cInt2 == 7 || cInt2 ==9)
return true;
else
return false;
break;
case 9:
if(cInt2 == 8 || cInt2 == 8)
return true;
else
return false;
break;
default:
return false;
}
}
bool isValidSecurityCode(string originalCode, string enteredCode)
{
if(originalCode.length() != enteredCode.length())
return false;
bool flag = true;
for(int i=0; i<originalCode.length(); i++)
{
if(originalCode.at(i) != enteredCode.at(i))
{
if(flag)
{
if(!valid(originalCode.at(i), enteredCode.at(i)))
return false;
flag = false;
}
else
return false;
}
}
return true;
}
int main(int argc, char** argv)
{
if(isValidSecurityCode("12345","12345"))
cout <<"Code is valid"<<endl;
else
cout <<"Code is not valid"<<endl;
return (EXIT_SUCCESS);
}
package b;
public class OneDigitErrorKeypad {
public static void main(String[] args){
String input = "12246";
if(checkPass(input)){
System.out.println("Correct");
}else{
System.out.println("INcorrect");
}
}
public static boolean checkPass(String pass){
String correctPass = "12345";
//check that both passwords are of same length
if(pass.length() != correctPass.length()){
return false;
}
for(int i=0; i< pass.length(); i++){
if(pass.charAt(i) != correctPass.charAt(i)){
if(!validate(pass.charAt(i), correctPass.charAt(i))){
return false;
}
}
}
return true;
}
public static boolean validate(char a, char c){
char[][] keypad = {{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
int indexX = 0, indexY = 0;
for(int i = 0 ; i < keypad.length; i++){
for(int j = 0 ; j < keypad[i].length; j++){
if(a == keypad[i][j]){
indexX = i;
indexY = j;
}
}
}
//check horizontally
if(indexX == 0){
if(c == keypad[indexX+1][indexY]){
return true;
}
}else if(indexX == 1){
if(c == keypad[indexX+1][indexY]|| c == keypad[indexX-1][indexY]){
return true;
}
}else{
if(c == keypad[indexX-1][indexY]){
return true;
}
}
//Check vertically
if(indexY == 0){
if(c == keypad[indexX][indexY+1]){
return true;
}
}else if(indexY == 1){
if(c == keypad[indexX][indexY+1]|| c == keypad[indexX][indexY-1]){
return true;
}
}else{
if(c == keypad[indexX][indexY-1]){
return true;
}
}
return false;
}
}
This is the best code EVER for this problem (Njoi n cheers!!!)
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
char code[10]={2,3,4,9};
char str[10];
int i=0;
int x=0,y=0;
int flag=0;
printf("\nEnter the code: ");
scanf("%s",str);
while(i<4)
{
if(int(str[i]-48)==int(code[i])) //if matches
i++;
else //if not
{
if(flag==1)
flag=2;
if(flag==0)
flag=1;
if(flag==2)
{
printf("\nCODE REJECTED!");
getch();
exit(0);
}
x=int(code[i]);
y=int(str[i]-48);
i++;
//For top
if(x-3>0 && y==x-3)
continue;
//For bottom
else if(x+3<10 && y==x+3)
continue;
//For right
else if(x+1!=4 && x+1!=7 && x+1!=10 && y==x+1)
continue;
//For left
else if(x-1!=6 && x-1!=3 && x-1!=0 && y==x-1)
continue;
else
{
printf("\nCODE REJECTED!");
getch();
exit(0);
}
}
}
if(flag==0 || flag==1)
printf("\nCODE ACCEPTED!");
getch();
}
<pre lang="" line="1" title="CodeMonkey66621" class="run-this">#include <stdio.h>
int main (void)
{
int number;
int code[5]={5,7,3,4,9};
int a[3][3]={0};
int i,j,digit=1;
for(i=0; i<3; i++)
{
for(j=0;j<3;j++)
{
a[i][j]=digit++;
printf("%d\n", a[i][j]);
}
}
printf("Enter Number");
scanf("%d", &number);
int k=0;
// printf("%d\n", code[k]);
int flag;
while(number!=0)
{
flag=0;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d", a[i][j]);
if(a[i][j]==code[k])
{
if(number==code[k])
{
k++;
flag=1;
break;
flag=1;
}
else if(number==a[i][j+1]||number==a[i][j-1]||number==a[i+1][j]||number==a[i-1][j])
{
k++;
flag=1;
break;
}
else
{
printf("code doesnt match");
flag=1;
break;
}
}
}
if(flag==1)
{
break;
}
}
scanf("%d", &number);
}
return 0;
}
</pre><pre title="CodeMonkey66621" input="yes">
4
8
2
1
6
</pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace EQ_15
{
class Program
{
static char[,] matrix = {
{'1','2','3'},
{'4','5','6'},
{ '7', '8', '9'}
};
public static bool authenticate(String code, String userCode)
{
bool valid = false;
if (code == userCode)
{
return true;
}
else if (code.Length != userCode.Length)
{
return false;
}
else
{
int codeLength = userCode.Length;
for (int i = 0; i < codeLength; i++)
{
for (int m = 0; m < 3; m++)
{
for (int n = 0; n < 3; n++)
{
if (matrix[m,n] == code[i])
{
if (checkPrev(m, n, userCode[i]))
{ valid = true; }
else if (checkNext(m, n, userCode[i]))
{ valid = true; }
else if(checkUp(m,n,userCode[i]))
{valid = true;}
else if (checkDown(m, n, userCode[i]))
{ valid = true; }
//in a single interration when we get failures from all the methods we have to say its not a right code
if (!valid)
{
return false;
}
}
}
}
}
}
return valid;
}
public static bool checkPrev(int y, int x, char u)
{
int prev;
if (x != 0) { prev = x - 1; }
else { prev = x; }
if (prev >= 0 && matrix[y, prev] == u)
{
return true;
}
return false;
}
public static bool checkNext(int y, int x, char u)
{
int next;
if (x == 2) { next = x;}
else { next = x + 1; }
if (next >= 0 && matrix[y, next] == u)
{
return true;
}
return false;
}
public static bool checkUp(int y, int x, char u)
{
int up;
if (y == 2)
{ up = y; }
else
{ up = y + 1;}
if (up >= 0 && matrix[up, x] == u)
{
return true;
}
return false;
}
public static bool checkDown(int y, int x, char u)
{
int down;
if (y != 0) { down = y - 1; }
else { down = y; }
if (down >= 0 && matrix[down, x] == u)
{
return true;
}
return false;
}
static void Main(string[] args)
{
if (authenticate("1478", "1178"))
{
Console.WriteLine("Success!");
}
else
{
Console.WriteLine("Failure!");
}
Console.Read();
}
}
}
Python:
def main():
print passw(12345,22345)
def passw(inp,pas):
dic = {1:[2,4], 2:[1,5,3], 3:[2,6], 4:[1,5,7], 5:[2,4,6,8], 6:[3,5,9], 7:[4,8], 8:[5,7,9], 9:[6,8]}
exception = -1
if len(str(inp))!=len(str(pas)):
return "Access Denied"
else:
for i in range(0,len(str(inp))):
if (str(inp)[i]!=str(pas)[i]):
if exception==-1:
if dic[int(str(pas)[i])].count(int(str(inp)[i])) > 0:
exception = 1
else:
return "Access Denied"
else:
return "Access Denied"
return "Access granted"
if __name__ == '__main__':
main()
import java.util.HashMap;
import java.util.Map;
public class SecurityKisok {
public static void main(String[] args) {
System.out.println(isAllowed("1478", "1178"));
}
static boolean isAllowed(String correctCode, String userCode) {
Map<String, String[]> allowedCodes = new HashMap<String, String[]>();
allowedCodes.put("1", new String[] { "2", "4" });
allowedCodes.put("2", new String[] { "1", "3", "5" });
allowedCodes.put("3", new String[] { "2", "6" });
allowedCodes.put("4", new String[] { "1", "5", "7" });
allowedCodes.put("5", new String[] { "2", "4", "6", "8" });
allowedCodes.put("6", new String[] { "3", "5", "9" });
allowedCodes.put("7", new String[] { "4", "8" });
allowedCodes.put("8", new String[] { "5", "7", "9" });
allowedCodes.put("9", new String[] { "6", "8" });
if (correctCode.equals(userCode)) {
return true;
} else if (correctCode.length() != userCode.length()) {
return false;
} else {
for (int i = 0; i < userCode.length(); i++) {
String c = correctCode.charAt(i) + "";
String u = userCode.charAt(i) + "";
if (!c.equals(u)) {
String[] allowedCode = allowedCodes.get(u);
boolean isOk = false;
for (String x : allowedCode) {
if (x.equalsIgnoreCase(c)) {
isOk = true;
}
}
if (!isOk) {
return false;
}
}
}
}
return true;
}
}
Output: true
#include <stdio.h>
#include <stdlib.h>
int security(int o, int n)
{
int temp_o, temp_n, flag = 0;
while(o > 0 && n > 0)
{
temp_o = o%10;
temp_n = n%10;
if(temp_o != temp_n)
{
if(((temp_o + 3 == temp_n)&&(temp_o + 3 < 10)) || ((temp_o - 3 == temp_n) && (temp_o - 3 > 0)) || ((temp_o +1 == temp_n)&&((temp_o + 1)%3!=1 )) || ((temp_o - 1 == temp_n)&&((temp_o-1)%3!=0)))
{
if(flag == 0)
flag =1;
else
return 0;
}
else
{
return 0;
}
}
o = o/10;
n = n/10;
}
if(n!=0 || o!=0)
return 0;
else
return 1;
}
int main()
{
int valid = security(1478, 1175);
if(valid)
printf("Authorized!!\n");
else
printf("Failed!!\n");
return 0;
}
Any comment pls
public class KeypadError {
static String[] errorMap = {"0","24","135","157","2468","359","48","579","68"};
public static void main(String[] args) {
String exp = "1478";
String actual = "1468";
System.out.println("Allowed: " + isMatch(exp,actual));
}
private static boolean isMatch(String exp, String actual) {
int errorCount = 0;
if(exp.length()!=actual.length()) return false;
for(int i = 0; i<exp.length();++i){
if(exp.charAt(i) != actual.charAt(i)){
if(errorCount < 1){
if(checkError(Integer.parseInt(String.valueOf(actual.charAt(i))), exp.charAt(i)))
errorCount++;
}
else
return false;
}
else
continue;
}
return true;
}
private static boolean checkError(int parseInt,char r) {
for(char c: errorMap[parseInt].toCharArray()){
if(r==c)
return true;
}
return false;
}
}
package practice;
public class valid_pass {
public static void main(String args[])
{
int[] pass={4,6,3,8};
int[] user_pass={4,5,6,5};
Boolean b=true;
b=is_Valid(pass,user_pass);
if(b)
System.out.println("valid pass");
else System.out.println("invalid pass");
}
public static boolean is_Valid(int[] pass,int[] user_pass){
int[][] keys={{1,2,3},{4,5,6},{7,8,9}};
int temp1 = 0,temp2=0,p,q;
if(pass.length !=user_pass.length)
return false;
else{
for(int i=0;i<pass.length;i++){
if(pass[i]!=user_pass[i]){
p=pass[i];
q=user_pass[i];
if(q<p){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
if (keys[j][k]==p){
if(j-1>=0){
temp1=keys[j-1][k];
}
if(k-1>=0){
temp2=keys[j][k-1];
}
if(temp1 != q && temp2 != q) return false;
}
}
}
}else if(q>p){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
if (keys[j][k]==p){
if(j+1<=2){
temp1=keys[j+1][k];
}
if(k+1<=2){
temp2=keys[j][k+1];
}
if(temp1 != q && temp2 != q) return false;
}
}
}
}
}
}
return true;
}
}
}
package practice;
public class valid_pass {
public static void main(String args[])
{
int[] pass={4,6,3,8};
int[] user_pass={4,5,6,5};
Boolean b=true;
b=is_Valid(pass,user_pass);
if(b)
System.out.println("valid pass");
else System.out.println("invalid pass");
}
public static boolean is_Valid(int[] pass,int[] user_pass){
int[][] keys={{1,2,3},{4,5,6},{7,8,9}};
int temp1 = 0,temp2=0,p,q;
if(pass.length !=user_pass.length)
return false;
else{
for(int i=0;i<pass.length;i++){
if(pass[i]!=user_pass[i]){
p=pass[i];
q=user_pass[i];
if(q<p){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
if (keys[j][k]==p){
if(j-1>=0){
temp1=keys[j-1][k];
}
if(k-1>=0){
temp2=keys[j][k-1];
}
if(temp1 != q && temp2 != q) return false;
}
}
}
}else if(q>p){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
if (keys[j][k]==p){
if(j+1<=2){
temp1=keys[j+1][k];
}
if(k+1<=2){
temp2=keys[j][k+1];
}
if(temp1 != q && temp2 != q) return false;
}
}
}
}
}
}
return true;
}
}
}
- tj May 27, 2009