Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,23 @@
public class Narc{
public static boolean isNarc(long x){
if(x < 0) return false;
String xStr = Long.toString(x);
int m = xStr.length();
long sum = 0;
for(char c : xStr.toCharArray()){
sum += Math.pow(Character.digit(c, 10), m);
}
return sum == x;
}
public static void main(String[] args){
for(long x = 0, count = 0; count < 25; x++){
if(isNarc(x)){
System.out.print(x + " ");
count++;
}
}
}
}

View file

@ -0,0 +1,26 @@
import java.util.stream.IntStream;
public class NarcissisticNumbers {
static int numbersToCalculate = 25;
static int numbersCalculated = 0;
public static void main(String[] args) {
IntStream.iterate(0, n -> n + 1).limit(Integer.MAX_VALUE).boxed().forEach(i -> {
int length = i.toString().length();
int addedDigits = 0;
for (int count = 0; count < length; count++) {
int value = Integer.parseInt(String.valueOf(i.toString().charAt(count)));
addedDigits += Math.pow(value, length);
}
if (i == addedDigits) {
numbersCalculated++;
System.out.print(addedDigits + " ");
}
if (numbersCalculated == numbersToCalculate) {
System.exit(0);
}
});
}
}