From the Inside July/August 2019
Do you think you are a good coder? Have you been practicing your coding, or have you just been doing your job?
If you haven't been practicing your coding, then you are likely getting rusty in your coding. When you are a musician or a sports star, you have talent and practical demonstrations of what you can do, but you also practice, practice, practice.
Most of us assume that our day to day software development is our practice. This is not the case. Let's use basketball as our example. Your day to day software development is much like an NBA Game. This is where players make their money, they spend most of their time reacting to the game and other players.
Players then spend time between games practicing their jump shots, layups, and passing in order to do better in the games. This is what you as developers need to do.
This is also where "Code Kata's" come into play. Code Kata was a term coined by Dave Thomas, co-author of the book The Pragmatic Programmer. A Code Kata is an exercise in programming which helps a programmer hone their skill.
I've talked about using Code Katas in the past, so I decided to introduce a new one.
Kata One — Cash Drawer Count Out
Many Retail locations have a drawer that cashiers have to count in and out every day. At the beginning of each day the drawer must have $200 bills and change.
At the end of the day, the cashier counts their drawer out and sends all the money that is over $200 to accounting, but they must have at least the minimum of each bill/coin listed below, and no more than the maximum of the following bills/coin listed in figure 1, totaling $200.00.
Bills |
Min |
Max |
$100 |
0 |
0 |
$50 |
0 |
0 |
$20 |
0 |
10 |
$10 |
3 |
6 |
$5 |
5 |
15 |
$1 |
27 |
45 |
.25 |
0 |
120 |
.10 |
0 |
150 |
.05 |
0 |
120 |
.01 |
0 |
200 |
Figure 1
Based on the information in figure 1, how would you code the program to generate the output to accounting using the information on the cashiers ending day Bill/coin count found in figure 2?
Bills |
Cashier 1 |
Cashier 2 |
Cashier 3 |
$100 |
1 |
0 |
0 |
$50 |
4 |
1 |
1 |
$20 |
27 |
130 |
11 |
$10 |
6 |
1 |
6 |
$5 |
17 |
7 |
8 |
$1 |
24 |
30 |
16 |
.25 |
41 |
10 |
69 |
.10 |
30 |
50 |
50 |
.05 |
63 |
59 |
60 |
.01 |
107 |
114 |
118 |
Figure 2