Jump to content

Recommended Posts

Basically if I have the number 1234 I do not want to have anything like 1334 OR 2234, OR 1235 but if i have 1245 it is fine.

 

Here is what I currently have 0000-0099,1100-1199, 2200-2299 etc.

 

I'm not sure if I can add any other numbers otherwise there will be more than 2 numbers in the same place in common.

 

Does that make sense?

Yea I'm not sure I get it either but here's my guess at a (crude) stating point for you to check the numbers.

You should be able to do it with modulus checks also.

function numPlacesMatch($a, $b){
$matches = 0;
$a = zerofill($a, 4);
$b = zerofill($b, 4);
for($i = 0; $i < 4; $i++){
	if($a{$i} == $b{$i}){
		$matches++;
	}
}
return $matches;
}

function zerofill($num, $places){
$str = (string)$num;
while(strlen($str) < $places){
	$str = '0' . $str;
}
return $str;
}

my curiosity got the better of me, this one is way faster than messing with all the strings.

function numPlacesMatch2($a, $b){
$matches = 0;
if($a % 10 == $b % 10){
	$matches++;
}
if(floor($a/10) % 10 == floor($b/10) % 10){
	$matches++;
}
if(floor($a/100) % 10 == floor($b/100) % 10){
	$matches++;
}
if(floor($a/1000) % 10 == floor($b/1000) % 10){
	$matches++;
}
return $matches;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.