Dubz
01-22-2012, 08:25 PM
I have a giant array of 9 digit numbers (about 6300). I want to perform a check that takes each number and flips it and sees which still match (perfect mirror) and which are close to a perfect match (one digit is off by 1-2 increments)
so far this is a shortened down version of what i attempted but failed:
<?php
$numberArray = array(
123456789,
234567890,
123456543,
624352454,
123454322, //Should be a possible close match, only of by one incrememnt (first/last digit)
318454813, //Should be a perfect match
829034505
);
$count = 0;
foreach($numberArray as $number){
$number2 = strrev($number);//Flip the number
$newNumber1 = array(
$id+1,
$id+10,
$id+100,
$id+1000,
$id+10000,
$id+100000,
$id+1000000,
$id+10000000,
$id+100000000,
$id-1,
$id-10,
$id-100,
$id-1000,
$id-10000,
$id-100000,
$id-1000000,
$id-10000000,
$id-100000000
);
$newNumber2 = array(
$id+2,
$id+20,
$id+200,
$id+2000,
$id+20000,
$id+200000,
$id+2000000,
$id+20000000,
$id+200000000,
$id-2,
$id-20,
$id-200,
$id-2000,
$id-20000,
$id-200000,
$id-2000000,
$id-20000000,
$id-200000000
);
if($number==$number2 || in_array($id2,$newNumber1) || in_array($id2,$newNumber2)){
print $id."<br />\r\n";
$count++;
}
}
print $count." numbers's are closely mirrored";
I got the perfect mirror check to work but the 1-2 increment's off check wont work. Also if you have an easier way to check if its off by 1 or 2 increments that would be nice also.
so far this is a shortened down version of what i attempted but failed:
<?php
$numberArray = array(
123456789,
234567890,
123456543,
624352454,
123454322, //Should be a possible close match, only of by one incrememnt (first/last digit)
318454813, //Should be a perfect match
829034505
);
$count = 0;
foreach($numberArray as $number){
$number2 = strrev($number);//Flip the number
$newNumber1 = array(
$id+1,
$id+10,
$id+100,
$id+1000,
$id+10000,
$id+100000,
$id+1000000,
$id+10000000,
$id+100000000,
$id-1,
$id-10,
$id-100,
$id-1000,
$id-10000,
$id-100000,
$id-1000000,
$id-10000000,
$id-100000000
);
$newNumber2 = array(
$id+2,
$id+20,
$id+200,
$id+2000,
$id+20000,
$id+200000,
$id+2000000,
$id+20000000,
$id+200000000,
$id-2,
$id-20,
$id-200,
$id-2000,
$id-20000,
$id-200000,
$id-2000000,
$id-20000000,
$id-200000000
);
if($number==$number2 || in_array($id2,$newNumber1) || in_array($id2,$newNumber2)){
print $id."<br />\r\n";
$count++;
}
}
print $count." numbers's are closely mirrored";
I got the perfect mirror check to work but the 1-2 increment's off check wont work. Also if you have an easier way to check if its off by 1 or 2 increments that would be nice also.