## Coin Change: Minimum number of coins

Problem: You are given n types of coin denominations of values v(1)<v(2)<…<v(n) (all integers). Assume v(1)=1, so you can always make change for any amount of money C. Give an algorithm which makes change for an amount of money C with as few coins as possible. #include <stdio.h> #include <stdlib.h> int main() { int i,n,den[20],temp[20],min,min_idx, … Read more

## Calculate change denominations 3

I am trying to refactor a large application to use more DDD principles as and when I get chance. I am concentrating on the very simple areas first. The app currently has a very simple Domain Service (one of many) as it stands (see option 1). Please see the code below: Option 1 – Live … Read more

## CS50 Pset1 Greedy, change algorithm

The purpose of the code is to calculate the least amount of coins needed to produce correct amount of change given a dollar or cent user input. I’m just starting out and appreciate any pointers in how this code could/should be optimized. The code works but I feel there is some redundancy with all those … Read more

## Dividing an arbitrary dollar amount into the fewest bills and coins

I am taking a class in mobile application development this fall. I have finished my first assignment of creating a class to divide an arbitrary dollar amount into the minimum number of bills and coins. I have completed the assignment and everything works as intended (outside of an occasional error I’m having with computing pennies, … Read more

## Converting money into change

I am trying to figure out a more efficient way of converting money into change. The code below is what i have written so far. It works perfectly but i know the code can be improved. Is there a more efficient way of writing this code? public class Problem2 { public static int quarters(int total) … Read more

## Vending machine change function

Write a function that takes an amount of money M, a price P and returns the change given in the smallest number of coins. The following coins are available: 1c, 5c, 10c, 25c, 50c, and \$1. Time: 20min. I’m looking for all sorts of reviews considering the time limit and environment. Here’s my code: #include … Read more

## Creating change with the smallest number of coins

This is a basic algorithm that creates change with the smallest number of coins. How can this be better written? It works perfectly, but I just imagine there is a cleaner and shorter version of this. const generateCoinChange = cents => { let quarter = 0; let dime = 0; let nickel = 0; let … Read more

## More optimal “Making Change” Problem: Knapsack challenge

The problem description is: You are given n types of coin denominations of values v(1) < v(2) < … < v(n) (all integers). Assume v(1) = 1, so you can always make change for any amount of money C. Give an algorithm which makes change for an amount of money C with as few coins … Read more

## Bills dispenser machine

I have just started out learning C++ and I am trying to write out a simple bills’ dispenser machine as an exercise. Upon user input, the system is to check if it can pay out the amount but only in 20 and 50 bills, and it should return with the minimum number of bills. I … Read more

## Calculating change in Ada

I have written a change calculator using Ada. when the user inputs an amount of money it returns a list of the coins and bills needed to create that total. It starts off by trying to use the largest money types then tries smaller ones. I am still learning how to use Ada and would … Read more