Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 621 Bytes

README.md

File metadata and controls

27 lines (18 loc) · 621 Bytes

constexpr-Change

What is this?

This code calculates at compile time the least number of coins needed to pay change. It's not very fast and might not work for every single case, but it gave the same result as this website for every reasonable value I tested. Also doubles as a compiler torturer.

This requires C++20 and was tested with clang and g++ using -Wpedantic.

Example

Input

constexpr int        value_as_cents{239};
constexpr std::array coins{1, 5, 10, 25};

std::cout << Change<value_as_cents, coins>() << std::endl;

Output

14