Skip to content

Instantly share code, notes, and snippets.

@ryangraham
Created May 20, 2020 06:51
Show Gist options
  • Save ryangraham/e3d9d5e2f543a620a123b0e4304d6112 to your computer and use it in GitHub Desktop.
Save ryangraham/e3d9d5e2f543a620a123b0e4304d6112 to your computer and use it in GitHub Desktop.
rtn checksum in c++
bool rtn_checksum(const std::string& routing_number) {
std::vector<int> const multipliers{3, 7, 1, 3, 7, 1, 3, 7, 1};
auto to_int = [](char c) { return std::stoul(&c, nullptr, 10); };
auto const routing_digits = routing_number | views::transform(to_int);
auto multiply = [](auto a, auto b) { return a * b; };
auto sum =
accumulate(views::zip_with(multiply, routing_digits, multipliers), 0);
return sum % 10 == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment