aboutsummaryrefslogtreecommitdiff
path: root/challenge-174/conor-hoekstra/cpp/ch-1.cpp
blob: 0ec197732b0d9afbdfe967f8f483c5679acd7d70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
}