Skip to content

Calculate at compile time the least number of coins needed to pay change.

License

Notifications You must be signed in to change notification settings

luizffgv/constexpr-Change

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Calculate at compile time the least number of coins needed to pay change.

Topics

Resources

License

Stars

Watchers

Forks

Languages