diff options
Diffstat (limited to 'challenge-174')
| -rw-r--r-- | challenge-174/conor-hoekstra/ch-1.apl | 3 | ||||
| -rw-r--r-- | challenge-174/conor-hoekstra/ch-1.cpp | 32 |
2 files changed, 35 insertions, 0 deletions
diff --git a/challenge-174/conor-hoekstra/ch-1.apl b/challenge-174/conor-hoekstra/ch-1.apl new file mode 100644 index 0000000000..83ce82cafb --- /dev/null +++ b/challenge-174/conor-hoekstra/ch-1.apl @@ -0,0 +1,3 @@ + isDisarium ← {⍵=+/(⊢*⍳∘≢)⍎¨⍕⍵} + 0,18↑{⍵/⍨isDisarium¨⍵}⍳10000000 +0 1 2 3 4 5 6 7 8 9 89 135 175 518 598 1306 1676 2427 2646798 diff --git a/challenge-174/conor-hoekstra/ch-1.cpp b/challenge-174/conor-hoekstra/ch-1.cpp new file mode 100644 index 0000000000..0ec197732b --- /dev/null +++ b/challenge-174/conor-hoekstra/ch-1.cpp @@ -0,0 +1,32 @@ + +#include <algorithm> +#include <cmath> +#include <iostream> +#include <numeric> +#include <string> + +namespace rv = std::views; + +auto is_disarium(int n) -> bool { + auto const s = std::to_string(n); + return n == std::transform_reduce( + s.cbegin(), s.cend(), rv::iota(1).begin(), 0, std::plus{}, + [](auto c, auto i) { return std::pow(c - 48, i); }); +} + +auto main() -> int { + + auto c = 0; + auto i = 0; + + while (c < 19) { + if (is_disarium(i)) { + ++c; + std::cout << i << ' '; + } + ++i; + } + std::cout << '\n'; + + return 0; +} |
