aboutsummaryrefslogtreecommitdiff
path: root/challenge-174/conor-hoekstra/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-174/conor-hoekstra/cpp/ch-1.cpp')
-rw-r--r--challenge-174/conor-hoekstra/cpp/ch-1.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-174/conor-hoekstra/cpp/ch-1.cpp b/challenge-174/conor-hoekstra/cpp/ch-1.cpp
new file mode 100644
index 0000000000..0ec197732b
--- /dev/null
+++ b/challenge-174/conor-hoekstra/cpp/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;
+}