eniallator

CodeGolf: Converting a number to British currency

Jul 26th, 2018 (edited)
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. **New Challenge:** Converting a number to British currency.
  2.  
  3. **Description:** To write a function that will take in 1 argument. This argument is the number to convert to British currency. The output will be a string with comma separated numbers corresponding to the index (more on this below) of the coin/note that goes into the original number. You are expected to use the highest valued notes/coins that make up the original number so you can't just dump a series of 1p coins in the output.
  4.  
  5. **More on the notes/coins indexes:** This is a list of all possible notes/coins in descending order with index `0` being the £50 note all the way down to index `11` being the 1p coin (£0.01). Full list below:
  6. ```text
  7. 0: £50
  8. 1: £20
  9. 2: £10
  10. 3: £5
  11. 4: £2
  12. 5: £1
  13. 6: £0.5
  14. 7: £0.2
  15. 8: £0.1
  16. 9: £0.05
  17. 10: £0.02
  18. 11: £0.01
  19. ```
  20.  
  21. **Technical stuff:** You can expect the number given to this function to have at max 2 decimal places and will always be > 0. In your output, you may have a trailing/leading comma.
  22.  
  23. **Examples:**
  24. ```text
  25. Input -> output
  26.  
  27. 27 -> '1,3,4'
  28. 5.76 -> '3,6,7,9,11'
  29. 12.62 -> '2,4,6,8,10'
  30. 88.88 -> '0,1,2,3,4,5,6,7,8,9,10,11'
  31. 1005.23 -> '0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,7,10,11'
  32. ```
Add Comment
Please, Sign In to add comment