In: Computer Science
You have a super-nature talent in stock prediction. You want to prove your talent to the entire world. You have predicted the next 10 days’ stock values. Each day after the market is closed, you plan to reveal that day’s prediction, so others can verify whether your prediction is correct or not. Obviously, you need to convince others that you know that day’s stock value beforehand. You don’t want to reveal your prediction before the market is closed, because you don’t want others to benefit from your predictions. At the beginning, you can publish some numbers in a popular newspaper, but you can only afford to publish 64 characters (the size of one hash value) in the newspaper. You reveal your prediction everyday and at the end of 10 days people can authenticate the 10 predications you have revealed over the last 10 days. Given these restrictions, describe the way you will design a system to prove your predictions.
The maximum characters/day without using the division logic is 64/10 = 6.4, which is pretty straightforward and not something we are looking for. So, how can we optimize?
We can use the concept of a Difference Array(because the difference in stock values on the next few days is close) as follows:
1. For the first day, we publish the predicted value as it is.
2. For the following days, we publish the difference between the predicted values of the previous day and current day.
For example, Say we need to publish values - 1000 , 1200 , 2500 , 4000 , 3600 , 900.
Then, we publish the following :-
100020013001500-400-2700
** Making it bold would help differentiate between the values.
What this means is take the first character, that's the first day's value. Add 200 to it to get the next day's value = 1200. Add 1300 to previous sum(i.e 1200) to we get 2500. Adding 1500 to 2500, we get 4000. Now, add -400 to 4000 to get 3600 and finally add -2700 to get 900.
This is pretty easy to decode and understand. To optimize this further, you can change the base of numbers to Hexadecimal or something else, if you want to save space but I'll omit this given the context that layman isn't good with hexadecimal calculation.