Advertisement
Guest User

Untitled

a guest
Jun 10th, 2019
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let amount = Number(input.shift())
  3.     let coins = 0
  4.  
  5.     while (amount > 0) {
  6.         if (amount >= 2) {
  7.             amount = amount - 2
  8.             coins++
  9.  
  10.         }
  11.         if (amount >= 1 && amount < 2) {
  12.             amount = amount - 1
  13.             coins++
  14.         }
  15.         if (amount >= 0.5 && amount < 1) {
  16.             amount = amount - 0.5
  17.             coins++
  18.         }
  19.         if (amount >= 0.2 && amount < 0.5) {
  20.             amount = amount - 0.2
  21.             coins++
  22.         }
  23.         if (amount >= 0.1 && amount < 0.2) {
  24.             amount = amount - 0.1
  25.             coins++
  26.         }
  27.         if (amount >= 0.05 && amount < 0.1) {
  28.             amount = amount - 0.05
  29.             coins++
  30.         }
  31.         if (amount >= 0.02 && amount < 0.05) {
  32.             amount = amount - 0.02
  33.             coins++
  34.         }
  35.         if (amount >= 0.01 && amount < 0.02) {
  36.             amount = amount - 0.01
  37.             coins++
  38.         }
  39.     }
  40.     console.log(coins)
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement