-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def minimum_coins(number) | ||
minimum = 0 | ||
[100, 50, 25, 10, 5, 1].each do |denom| | ||
return minimum if number == 0 | ||
minimum += number / denom | ||
number %= denom | ||
end | ||
minimum | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Write a method `def minimum_coins(number)` which takes a number as an argument (ranging from 1 to 250) and returns the minimum number of coins needed to calculate `number`. Coins here represent the following values: 1, 5, 10, 25, 50 and 100. Consider the following examples: | ||
|
||
* The minimum number of coins to generate `35` would be 2: 10 and 25. | ||
* The minimum number of coins to generate `37` would be 4: 1, 1, 10, 25. | ||
* The minimum number of coins to generate `101` would be 2: 1 and 100. | ||
|
||
Notes: | ||
|
||
* Do the assignment with TDD if you want some TDD practice (you likely will need another file in addition to `code.rb` for your test suite if you choose to do this)! |
This file contains 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