8 kyu

Simple Change Machine

2,699 of 3,389Peter Rhodes

Description:

Your task is to create a change machine.

The machine accepts a single coins or notes, and returns change in 20p and 10p coins. The machine will try to avoid returning its exact input, but will otherwise return as few coins as possible. For example, a 50p piece should become two 20p pieces and one 10p piece, but a 20p piece should become two 10p pieces.

The machine can exclusively process these coins and notes: £5, £2, £1, 50p, 20p. Any coins and notes which are not accepted by the machine will be returned unprocessed. For example, if you were to put a £20 note into the machine, it would be returned to you and not broken into change. (Note that £1 is worth 100p.)

This change machine is programmed to accept and distribute strings rather than numbers. The input will be a string containing the coin or note to be processed, and the change should be returned as one string with the coin names separated by single spaces with no commas. The values of the string should be in descending order. For example, an input of "50p" should yield the exact string "20p 20p 10p".

Fundamentals
Strings

Stats:

CreatedApr 29, 2016
PublishedMay 3, 2016
Warriors Trained9054
Total Skips205
Total Code Submissions19826
Total Times Completed3389
JavaScript Completions2699
Python Completions729
Total Stars106
% of votes with a positive feedback rating80% of 596
Total "Very Satisfied" Votes413
Total "Somewhat Satisfied" Votes123
Total "Not Satisfied" Votes60
Ad
Contributors
  • Peter Rhodes Avatar
  • donaldsebleung Avatar
  • Madjosz Avatar
  • albertogcmr Avatar
  • Just4FunCoder Avatar
  • Invariance Avatar
Ad