A simple repo for a program such that given a number of pennies, will calculate the minimum number of Sterling coins equivalent to that amount.
__ __ _ _
\ \ / /__| | ___ ___ _ __ ___ ___ | |_ ___
\ \ /\ / / _ \ |/ __/ _ \| '_ ` _ \ / _ \ | __/ _ \
\ V V / __/ | (_| (_) | | | | | | __/ | || (_) |
\_/\_/ \___|_|\___\___/|_| |_| |_|\___| \__\___/
__ __ _ _
| \/ (_)_ __ (_)_ __ ___ _ _ _ __ ___
| |\/| | | '_ \| | '_ ` _ \| | | | '_ ` _ \
| | | | | | | | | | | | | | |_| | | | | | |
|_| |_|_|_| |_|_|_| |_| |_|\__,_|_| |_| |_|
____ _ _ _ ____ _
/ ___|| |_ ___ _ __| (_)_ __ __ _ / ___|___ (_)_ __
\___ \| __/ _ \ '__| | | '_ \ / _` | | | / _ \| | '_ \
___) | || __/ | | | | | | | (_| | | |__| (_) | | | | |
|____/ \__\___|_| |_|_|_| |_|\__, | \____\___/|_|_| |_|
|___/
_____ _ _ _
| ____|_ ____ _| |_ _ __ _| |_ ___ _ __| |
| _| \ \ / / _` | | | | |/ _` | __/ _ \| '__| |
| |___ \ V / (_| | | |_| | (_| | || (_) | | |_|
|_____| \_/ \__,_|_|\__,_|\__,_|\__\___/|_| (_)
This version of the minimum coin problem processes the following Sterling coins and Pennies:
| £2 | £1 | 50p | 20p |
| 10p | 5p | 2p | 1p |
The evaluation process begins with basic filtering to account for input validation. This is subsequently followed by a bit of dynamic programming where the input is parsed through a top-down divisional minimization, starting with the highest coin.
The result is returned in a string (iterated and concatenated from a dictionary counter) describing the minimum number of coins used, based on the given input.
-
The program utilizes the following dependencies (all obtaininable via
pip) for Terminal rich text design: -
With the dependencies installed, from the
Terminaldirectory, execute themain_routine.pyfile. -
The program should display the following (after the intial welcome message ASCII banner) in a console/terminal:
-
ENTER PENNIES (e.g. £2, £1, 50p, 20p, 10p, 5p, 2p and 1p):
-
-
Given the following input (£14.83), the corresponding output is produced:
-
ENTER PENNIES (e.g. £2, £1, 50p, 20p, 10p, 5p, 2p and 1p): £14.83 >>> £14.83 = 7 x £2, 1 x 50p, 1 x 20p, 1 x 10p, 1 x 2p, 1 x 1p
-
-
Subsequent tabluation within the console is also added to mimic the feel and look of a web app:
-
Date & Time ReceivedAmount ReceivedCoin(s) ProcessedTue Nov 9 17:58:56 2021£14.8312 -
7 £2 Coins1 50p Coin1 20p Coin1 10p Coin1 2p Coin1 1p Coin
-
In the first column is a string of user input, and in the second the desired integer expressed as pence.
| Input | Pence Description |
|---|---|
| 6 | 6 Single digit |
| 75 | 75 Double digit |
| 167p | 167 Pence symbol |
| 4p | 4 Pence symbol single digit |
| 1.97 | 197 Pounds decimal |
| £1.33 | 133 Pound symbol decimal |
| £2 | 200 Single digit pound symbol |
| £20 | 2000 Double digit pound symbol |
| £1.97p | 197 Pound & pence symbol |
| £1p | Decimal 100 missing pence |
| £1.p | 100 Missing pence, Decimal point present |
| 001.61p | 161 Buffered zeroes |
| 6.235p | 624 Rounding with pence symbol |
| £1.256532677p | 126 Rounding with pound and pence symbols. |
Likewise, the application should not accept the following inputs
| Input | Pence | Description |
|---|---|---|
| 0 | Empty string | |
| 1x | 0 | Non-numeric, non-symbol character |
| £1x.0p | 0 | Non-numeric, non-symbol character along with valid symbols |
| £p | 0 | Missing digits |