Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * Description of Ovni
  5. *
  6. * @author Gabriel Machado
  7. */
  8. class Ovni {
  9.  
  10. protected $cometaGrupo = [];
  11.  
  12. public function __construct($cometaGrupo) {
  13. $this->cometaGrupo = $cometaGrupo;
  14. }
  15.  
  16. public function analisarGrupos() {
  17. foreach ($this->cometaGrupo as $cometa => $grupo) {
  18. if ($this->restoDiv45($cometa) === $this->restoDiv45($grupo)){
  19. echo "Grupo $grupo, all aboard!!" . PHP_EOL;
  20. } else {
  21. echo "Grupo $grupo nao sera levado" . PHP_EOL;
  22. }
  23. }
  24. }
  25.  
  26. private function restoDiv45($palavra) {
  27. return $this->calcularProduto($palavra) % 45;
  28. }
  29.  
  30. private function calcularProduto($palavra) {
  31. $produto = 1;
  32.  
  33. $letras = str_split($palavra);
  34.  
  35. foreach ($letras as $letra){
  36. $produto *= $this->ascii2number($letra);
  37. }
  38.  
  39. return $produto;
  40. }
  41.  
  42. private function ascii2number($letra) {
  43. return ord(strtoupper($letra)) - 64;
  44. }
  45.  
  46. }
  47.  
  48. $lista = [
  49. 'Halley' => 'Amarelo',
  50. 'Encke' => 'Vermelho',
  51. 'Wolf' => 'Preto',
  52. 'Kushida' => 'Azul'
  53. ];
  54.  
  55. $ovni = new Ovni($lista);
  56.  
  57. $ovni->analisarGrupos();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement