Skip to content

Instantly share code, notes, and snippets.

@jonataa
Created May 21, 2014 02:55
Show Gist options
  • Select an option

  • Save jonataa/fc014629d4bc419bb1d4 to your computer and use it in GitHub Desktop.

Select an option

Save jonataa/fc014629d4bc419bb1d4 to your computer and use it in GitHub Desktop.
Números Bonitos
<?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