I have to answer this question that seems a riddle ... I don't know if there's a real solution or it's impossible...
Questions : Having two double values, one is the total amount of money in the safe, the other is threshold of maximum money recommended in the safe
For example: recommended value of money (threshold) : $1,500
Total amount is a variable that is calculated every 5 seconds by a timer, in this timer tick event i have the value of the recommended value of money and the value of the total amount of money in the safe.
At the timer tick event, I need to check if the value of total money is greater than recommended value, and show a notification to the user UI. But since the timer tick event happen every 5 seconds, I need to show a notification the first time that the total amount is greater than recommended amount, and every 50$ step of difference above the threshold.
An example (every row of this example is a timer tick event) :
- Total : 1200$ − Recommended : 1500$ → No Notification
- Total : 1505$ − Recommended : 1500$ → Notification (first overcoming of threshold)
- Total : 1520$ − Recommended : 1500$ → No Notification
- Total : 1537$ − Recommended : 1500$ → No Notification
- Total : 1558$ − Recommended : 1500$ → Notification (first overcoming of 50$ step)
- Total : 1574$ − Recommended : 1500$ → No Notification
- Total : 1586$ − Recommended : 1500$ → No Notification
- Total : 1598$ − Recommended : 1500$ → No Notification
- Total : 1612$ − Recommended : 1500$ → Notification (second overcoming of 50$ step)
- Total : 1623$ − Recommended : 1500$ → No Notification
And so on. Is there a way (math calculation or algorithm) to show this notification knowing only this two value, without storing any other variable in memory ?
I Can't store the "total amount" previous value in a variable.
I don't know if there's a solution but someone have passed to me this question as a riddle.
Do you have any idea if is there a solution to this question ?