3 ms·
The usual coin-change-making algorithm for X cents in the US is... (1) pull ⌊X/25⌋ quarters; set X = X%25 (2) pull ⌊X/10⌋ dimes; set X = X%10 (3) pull ⌊X/5⌋
by gojomo 16y ago
The usual coin-change-making algorithm for X cents in the US is...
(1) pull ⌊X/25⌋ quarters; set X = X%25
(2) pull ⌊X/10⌋ dimes; set X = X%10
(3) pull ⌊X/5⌋ nickles; set X = X%5
(4) pull X pennies
No pennies means there's never a step 4 -- also the only step that might require pulling 4 coins. When dealing with a line of people during the morning coffee rush, fractions of a second count.