Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let amount = Number(input.shift())
- let coins = 0
- while (amount > 0) {
- if (amount >= 2) {
- amount = amount - 2
- coins++
- }
- if (amount >= 1 && amount < 2) {
- amount = amount - 1
- coins++
- }
- if (amount >= 0.5 && amount < 1) {
- amount = amount - 0.5
- coins++
- }
- if (amount >= 0.2 && amount < 0.5) {
- amount = amount - 0.2
- coins++
- }
- if (amount >= 0.1 && amount < 0.2) {
- amount = amount - 0.1
- coins++
- }
- if (amount >= 0.05 && amount < 0.1) {
- amount = amount - 0.05
- coins++
- }
- if (amount >= 0.02 && amount < 0.05) {
- amount = amount - 0.02
- coins++
- }
- if (amount >= 0.01 && amount < 0.02) {
- amount = amount - 0.01
- coins++
- }
- }
- console.log(coins)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement