Skip to content

Latest commit

 

History

46 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minimum Sterling Coins and Pennies Evaluator

The minimum coin problem (with a twist!)

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 / (_| | | |_| | (_| | || (_) | |  |_|
|_____| \_/ \__,_|_|\__,_|\__,_|\__\___/|_|  (_)

How it works

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.

How to Run

  • The program utilizes the following dependencies (all obtaininable via pip) for Terminal rich text design:

  • With the dependencies installed, from the Terminal directory, execute the main_routine.py file.

  • 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 Received Amount Received Coin(s) Processed
      Tue Nov 9 17:58:56 2021 £14.83 12
    • 7 £2 Coins 1 50p Coin 1 20p Coin 1 10p Coin 1 2p Coin 1 1p Coin

Test Data

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

About

The minimum coin problem... with a slight twist. The solution is programmed in Python, and runs as a console application.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages