Narcissistic decimal number: Difference between revisions

Content added Content deleted
(Updated D version 1 and 2)
Line 341: Line 341:
548834 1741725 4210818 9800817 9926315
548834 1741725 4210818 9800817 9926315
</pre>
</pre>
===or===
<lang csharp>
//Narcissistic numbers: Nigel Galloway: February 17th., 2015
using System;
using System.Collections.Generic;
using System.Linq;

namespace RC {
public static class NumberEx {
public static IEnumerable<int> Digits(this int n) {
List<int> digits = new List<int>();
while (n > 0) {
digits.Add(n % 10);
n /= 10;
}
return digits.AsEnumerable();
}
}

class Program {
static void Main(string[] args) {
foreach (int N in Enumerable.Range(0, Int32.MaxValue).Where(k => {
var digits = k.Digits();
return digits.Sum(x => Math.Pow(x, digits.Count())) == k;
}).Take(25)) {
System.Console.WriteLine(N);
}
}
}
}
</lang>
{{out}}
<pre>
0
1
2
3
4
5
6
7
8
9
153
370
371
407
1634
8208
9474
54748
92727
93084
548834
1741725
4210818
9800817
9926315
</pre>

=={{header|Common Lisp}}==
=={{header|Common Lisp}}==
<lang lisp>
<lang lisp>