From 5f4256ca997b897e4fa0dfab6d0d9da69ee7e686 Mon Sep 17 00:00:00 2001 From: Conor Hoekstra Date: Thu, 21 Jul 2022 21:22:35 -0400 Subject: Week 174 in APL & C++ --- challenge-174/conor-hoekstra/ch-1.apl | 3 +++ challenge-174/conor-hoekstra/ch-1.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 challenge-174/conor-hoekstra/ch-1.apl create mode 100644 challenge-174/conor-hoekstra/ch-1.cpp (limited to 'challenge-174') 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 +#include +#include +#include +#include + +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; +} -- cgit