Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Munchausen-numbers/D/munchausen-numbers.d
Normal file
21
Task/Munchausen-numbers/D/munchausen-numbers.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
for (int i=1; i<5000; i++) {
|
||||
// loop through each digit in i
|
||||
// e.g. for 1000 we get 0, 0, 0, 1.
|
||||
int sum = 0;
|
||||
for (int number=i; number>0; number/=10) {
|
||||
int digit = number % 10;
|
||||
// find the sum of the digits
|
||||
// raised to themselves
|
||||
sum += digit ^^ digit;
|
||||
}
|
||||
if (sum == i) {
|
||||
// the sum is equal to the number
|
||||
// itself; thus it is a
|
||||
// munchausen number
|
||||
writeln(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue