(I'm sure this has come up before. If someone can find a previous answer then please duplicate... )
From the Yellow Paper, Appendix G, you'll see the following line:
Gsset - 20000 - Paid for an SSTORE operation when the storage value is set to
non-zero from zero.
Meaning the first time you write a variable to storage, it's more expensive by 20,000 gas....
No. It would be expensive and it would not scale.
The name of the game is to economize on writes and avoid loops. It's so important that your approach to problems like this may seem counter-intuitive, at first.
You have to work out what the value would be if the data was updated in place. For that, you would just need to know the original number and the ...