Dan1
Member
Hello!
I'm trying to make code that will check a 4-digit numerical combination that you put in to a safe and give you a clue once you've entered the combination.
What I am trying to do is make the return show an "X" if you have one of the digits in the right place, then an "O" if you have a digit correct but in the wrong position
The code I have works if all 4 digits in the correct combination are different but...
The problem I'm having, if the right combination contains more than one of the same digit (Eg: "0141" then it doesn't return the right outcome when you use the a different quantity of digits (Using the example above, if I guess "1440", it'll give the outcome "XOOO", where it should return "XOO" as the second "4" is not in the first combination, so it's not correct and shouldn't return an "X" or "O")
Any thoughts on how to get this to return the correct response?
Much appreciated,
Dan
I'm trying to make code that will check a 4-digit numerical combination that you put in to a safe and give you a clue once you've entered the combination.
What I am trying to do is make the return show an "X" if you have one of the digits in the right place, then an "O" if you have a digit correct but in the wrong position
The code I have works if all 4 digits in the correct combination are different but...
The problem I'm having, if the right combination contains more than one of the same digit (Eg: "0141" then it doesn't return the right outcome when you use the a different quantity of digits (Using the example above, if I guess "1440", it'll give the outcome "XOOO", where it should return "XOO" as the second "4" is not in the first combination, so it's not correct and shouldn't return an "X" or "O")
Code:
global.gu = your guess
global.ra = right answer/combination
global.rp = response
global.rc = response counter
if global.gu[1] = global.ra[1] then
{
global.rp[global.rc] = "X"
global.gr[1]=1
global.rc+=1
}
if global.gu[2] = global.ra[2] then
{
global.rp[global.rc] = "X"
global.gr[2]=1
global.rc+=1
}
if global.gu[3] = global.ra[3] then
{
global.rp[global.rc] = "X"
global.gr[3]=1
global.rc+=1
}
if global.gu[4] = global.ra[4] then
{
global.rp[global.rc] = "X"
global.gr[4]=1
global.rc+=1
}
if global.gu[1] != global.ra[1] then
{
if global.gu[1] = global.ra[2] && global.gr[2] != 1 then global.gr[2] = 1
if global.gu[1] = global.ra[3] && global.gr[3] != 1 then global.gr[3] = 1
if global.gu[1] = global.ra[4] && global.gr[4] != 1 then global.gr[4] = 1
if global.gu[1] = global.ra[2] || global.gu[1] = global.ra[3] || global.gu[1] = global.ra[4] then
{
global.rp[global.rc] = "O"
global.rc+=1
}
}
if global.gu[2] != global.ra[2] then
{
if global.gu[2] = global.ra[1] && global.gr[1] != 1 then global.gr[1] = 1
if global.gu[2] = global.ra[3] && global.gr[3] != 1 then global.gr[3] = 1
if global.gu[2] = global.ra[4] && global.gr[4] != 1 then global.gr[4] = 1
if global.gu[2] = global.ra[1] || global.gu[2] = global.ra[3] || global.gu[2] = global.ra[4] then
{
global.rp[global.rc] = "O"
global.rc+=1
}
}
if global.gu[3] != global.ra[3] then
{
if global.gu[3] = global.ra[2] && global.gr[2] != 1 then global.gr[2] = 1
if global.gu[3] = global.ra[1] && global.gr[1] != 1 then global.gr[1] = 1
if global.gu[3] = global.ra[4] && global.gr[4] != 1 then global.gr[4] = 1
if global.gu[3] = global.ra[2] || global.gu[3] = global.ra[1] || global.gu[3] = global.ra[4] then
{
global.rp[global.rc] = "O"
global.rc+=1
}
}
if global.gu[4] != global.ra[4] then
{
if global.gu[4] = global.ra[2] && global.gr[2] != 1 then global.gr[2] = 1
if global.gu[4] = global.ra[3] && global.gr[3] != 1 then global.gr[3] = 1
if global.gu[4] = global.ra[1] && global.gr[1] != 1 then global.gr[1] = 1
if global.gu[4] = global.ra[2] || global.gu[4] = global.ra[3] || global.gu[4] = global.ra[1] then
{
global.rp[global.rc] = "O"
global.rc+=1
}
}
Any thoughts on how to get this to return the correct response?
Much appreciated,
Dan