Created
May 21, 2014 02:55
-
-
Save jonataa/fc014629d4bc419bb1d4 to your computer and use it in GitHub Desktop.
Números Bonitos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Exercício – Números bonitos: | |
| * | |
| * Números são bonitos se contiverem um dígito 4 | |
| * e não contiverem um dígito 9. Quais números entre 14063 and 24779, | |
| * são bonitos? | |
| **/ | |
| class Numeros | |
| { | |
| private $numeros = array(); | |
| public function __construct(Array $numeros) | |
| { $this->numeros = $numeros; | |
| } | |
| public function getBonitos() | |
| { return array_filter($this->numeros, 'Numeros::isBonito'); | |
| } | |
| public function isBonito($numero) | |
| { return !strpos((string) $numero, '9') && strpos((string) $numero, '4'); | |
| } | |
| } | |
| $numeros = new Numeros(range(14063, 24779)); | |
| $bonitos = $numeros->getBonitos(); | |
| echo count($bonitos); // Output: 3047 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment