Валидатор не принимает решение. Где я ошибся?
package com.javarush.task.task20.task2025;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
/*
Алгоритмы-числа
*/
public class Solution {
public static long[] getNumbers(long N) {
long[] result = null;
if (N > 0) {
ArrayList<Long> thatList = createThatList(N);
ArrayList<Long> onlyArmstrongsList = new ArrayList<>();
for (long l : thatList) {
if (l == returnArmstrong(l) && (!onlyArmstrongsList.contains(l)))
onlyArmstrongsList.add(l);
}
result = new long[onlyArmstrongsList.size()];
Collections.sort(onlyArmstrongsList);
for (int i = 0; i < onlyArmstrongsList.size(); i++)
if (onlyArmstrongsList.get(i) < N)
result[i] = onlyArmstrongsList.get(i);
return result;
}
else
return new long[] {};
}
public static ArrayList<Long> createThatList(long boundary) {
ArrayList<Long> thatList = new ArrayList<>();
long currentValue = 1;
while (currentValue < boundary) {
//
//if (doesItEvenLookLikeIt(currentValue)) {
long armed = returnArmstrong(currentValue);
if (armed < boundary)
thatList.add(armed);
//}
//
if ((currentValue % 10) != 0)
currentValue++;
else {
long valueToDisassemble = currentValue;
long nonZeroDigitInTheValue = valueToDisassemble % 10;
int zeroToTheLeftCounter = -2;
while (nonZeroDigitInTheValue == 0) {
nonZeroDigitInTheValue = valueToDisassemble % 10;
if (nonZeroDigitInTheValue == 0)
valueToDisassemble /= 10;
zeroToTheLeftCounter++;
}
long valueToAdd = nonZeroDigitInTheValue * (long) Math.pow(10, zeroToTheLeftCounter);
currentValue += valueToAdd;
}
}
return thatList;
}
public static boolean doesItEvenLookLikeIt(long value) {
return (isEven(value) == isEven(sumOfDigits(value)));
}
public static boolean isEven(long value) {
return (value % 2 == 0);
}
public static long sumOfDigits(long value) {
long result = 0;
while (value > 0) {
result += value % 10;
value /= 10;
}
return result;
}
public static long returnArmstrong(long value) {
long result = 0;
long temp = value;
int valueLength = 0;
while (temp > 0) {
temp /= 10;
valueLength++;
}
while (value > 0) {
long currentDigit = value % 10;
long currentDigitPowered = 1;
for (int i = 0; i < valueLength; i++)
currentDigitPowered *= currentDigit;
result += currentDigitPowered;
value /= 10;
}
return result;
}
public static void main(String[] args) {
long start = System.currentTimeMillis();
long [] res = getNumbers(999999999);
long end = System.currentTimeMillis() - start;
System.out.println(Arrays.toString(res));
long memory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
SimpleDateFormat sdf = new SimpleDateFormat("ss.SSS");
System.out.println("Time = " + sdf.format(new Date(end)));
System.out.println("Memory = " + memory / 1048576);
}
}