There are 14998 palindromic numbers in [1, 50000000).
I want to define a function that finds them out at compile-time, populates an std::array<int, 14998> and returns it.
I have an idea but cannot compile it. What am I doing wrong ?
#include <array>
bool is_valid(int src)noexcept {
auto ret{ 0 }, cpy{ src };
do {
ret = ret * 10 + src % 10;
} while ((src /= 10) != 0);
return ret == cpy;
}
std::array<int, 14998> constexpr build()noexcept {
std::array<int, 14998> ret{};
for (auto i{ 1 }, j{ -1 }; i != 50000000; ++i) {
if (is_valid(i)) {
ret[++j] = i;
}
}
return ret;
}
int main() {
auto constexpr lut{ build() };
return 0;
}