Am I under Budget?
Every 2 weeks when I get my cheque, I allocate a certain amount to last me until my next cheque, and bank the rest. To figure out how much I can spend per day and still remain under/on budget, I just need to divide the allocated amount by the number of days it needs to last me.
On Day 1 if the budget period is 14 days and I start with $400, I can spend ($400 / 14 =) $28.57 a day.
If I go over budget on any days though, I have less to spend during the rest of the budget period.
Say I spend $50 on Day 1. I now have $350 starting Day 2, and can only spend ($350 / 13 =) $26.92 a day instead of $28.57 for the remainder of the period.
Problem
Write a program/function that when given a starting allocation and a list of daily expenditures, returns a list of how much I could spend on each day to stay on budget, and a symbol indicating whether or not I was over/under/on budget that day.
Example
Pretend for this example the budget period is only 5 days.
- Period Allocation = $100
- Daily Expenditures = [20, 20, 30, 0, 0]
This should return (output variations are allowed. See Output section):
["= 20", "= 20", "^ 20", "V 15", "V 30"]
On Day 1, I can spend (100 / 5 =) $20. I spent the entire daily budget, so I was on budget (
=
). The first entry of the result is "= 20" to show this.On Day 2, I can spend (80 / 4 =) $20. Again, I spent the entire amount, so the second result entry is the same as the first.
On Day 3, I can again spend (60 / 3 =) $20, but I went over budget by spending $30! I was allowed to spend $20, but went over, so the third result entry is "^ 20"; "^" meaning "over-budget.
On Day 4, I can spend (30 / 2 =) $15. I spent nothing however, so I was under budget. The fourth result entry will be "V 15"; "V" meaning "under-budget".
On Day 5, I can spend (30 / 1 =) $30. I again spent nothing and was under budget, so the fifth and final result entry is "V 30".
Input
Input will be:
- A number representing the total money allocated for the period.
- A sequence representing how much was spent on each day during the period
The number of days in a period is = to the length of the daily expenditure list.
Input Rules:
- Your program must handle decimal allocation amounts.
- The allocation amount can be taken as a number or string. A dollar sign is allowed for string representations (but optional).
- You can assume the budget period will be at least a day long (daily expenditure list will contain at least 1 entry).
- You can assume I won't spend more money than I allocated.
- A delimited string would also be a acceptable form of input
Output
Output will be a sequence of symbols and numbers showing how much I was allowed to spend on that day, and whether or not I went over.
Output can be returned or printed to the stdout.
Output Rules:
Any non-numeric symbols can be used to indicate on/under/over budget, as long as you chose a different symbol for on, under and over. If you don't use "="/"V"/"^", make sure to specify in your answer what symbols you're using.
The symbol can appear before or after the number
Output can be any form of sequence where it's clear what parts belong to what day. The examples here use a sequence of strings, but a sequence of pairs/lists would be fine as well.
Output must be accurate to at least 2 decimal places (but more is fine). It must be properly rounded using 4/5 rounding if only accurate to 2 places.
A long string instead of a sequence of strings is fine too, as long as there's some delimiter separating output for each day so it's readable.
Test Cases
10, [1, 2, 3, 4, 0]
["V 2", "V 2.25", "^ 2.33", "^ 2", "= 0"]
25, [20, 2, 3]
["^ 8.3", "V 2.5", "= 3"]
1000, [123, 456, 400]
["V 333", "^ 438.5", "V 421"]
500, [10, 200, 0, 0, 100, 50, 50]
["V 71.43", "^ 81.67", "V 58", "V 72.5", "^ 96.67", "V 70", "V 140"]
This is code golf, so the smallest number of bytes wins.