Created
May 20, 2020 06:51
-
-
Save ryangraham/e3d9d5e2f543a620a123b0e4304d6112 to your computer and use it in GitHub Desktop.
rtn checksum in c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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