aboutsummaryrefslogtreecommitdiff
path: root/challenge-174
diff options
context:
space:
mode:
authorConor Hoekstra <codereport@outlook.com>2022-07-21 21:22:35 -0400
committerConor Hoekstra <codereport@outlook.com>2022-07-21 21:22:35 -0400
commit5f4256ca997b897e4fa0dfab6d0d9da69ee7e686 (patch)
treeab7b028d6907e06b8887fe8f93a3fa59aa7ad5ba /challenge-174
parent492d38a462e1c494aadeb9b421f759d6d562cc1f (diff)
downloadperlweeklychallenge-club-5f4256ca997b897e4fa0dfab6d0d9da69ee7e686.tar.gz
perlweeklychallenge-club-5f4256ca997b897e4fa0dfab6d0d9da69ee7e686.tar.bz2
perlweeklychallenge-club-5f4256ca997b897e4fa0dfab6d0d9da69ee7e686.zip
Week 174 in APL & C++
Diffstat (limited to 'challenge-174')
-rw-r--r--challenge-174/conor-hoekstra/ch-1.apl3
-rw-r--r--challenge-174/conor-hoekstra/ch-1.cpp32
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;
+}