Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class ExtractorDigitos
- {
- // Método de extensión para extraer los digitos de un número>
- public static IEnumerable<int> Digitos(this int numero)
- {
- List<char> caracteres = new List<char>() {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
- List<int> digitos = new List<int>();
- foreach(char caracter in numero.ToString())
- {
- digitos.Add(caracteres.IndexOf(caracter));
- }
- return digitos.AsEnumerable();
- }
- }
- void Main()
- {
- Enumerable.Range(0, 1000)
- .Where(k => k.Digitos().Select(x => x * x * x).Sum() == k)
- .Dump("Números de Armstrong entre 0 y 1000");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement