br Posted July 29, 2013 at 11:43 PM Report #520367 Posted July 29, 2013 at 11:43 PM Boas estou a resolver alguns problemas em PHP tenho a class ponto (public x, y;) tenho um array com varios pontos la dentro. agora quero saber se todos os pontos do array são distintos, ou seja, se nao ha entre eles que se encontram no mesmo lugar function distinct(array $arr){ for ($i=0; $i<max($arr)->x; $i++){ for ($j=0; $j<max($arr)->y; $j++){ if ($arr[$i]->x==$arr[$j]->y){ return false; } } } return true; } fiz assim, mas isto nao me parece correcto
HappyHippyHippo Posted July 30, 2013 at 12:16 AM Report #520368 Posted July 30, 2013 at 12:16 AM tens um número máximo para o X e o Y ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
KTachyon Posted July 30, 2013 at 07:59 AM Report #520384 Posted July 30, 2013 at 07:59 AM Tens que comparar x com x e y com y. Não x com y. E tens que percorrer o tamanho do array, que certamente não é aquela expressão que usas nos ciclos for. “There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.” -- Tony Hoare
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now