Approval isn't required "every time". You were supposed to have received two notifications that only the first three posts need to wait for approval. What specifically is made difficult, by waiting a while before you reply?
Impatience, mostly, seeing members post questions to things I've already answered but they have not yet been able to see. Making progress less and confusion greater.
Though, I've already posted more than three posts, and still see the moderation screen. Even this message was moderated.
https://gyazo.com/6025cc024af7ddb9af82889cda09ffb4
According to your original post, that last dollar amount above would be the unit price if four items were purchased, not five. Unless you mispoke.
The prices listed there were the prices that the five items were purchased at, the resulting price of the item after the five purchases was not included because it had not yet been purchased at that price. However, I've ran the simulation again to get the resulting price of the item after give purchases, and it would have been
261.67389624662684
What is your concern about running the loop? I ran it, until the unit price became too large for the software to display as a decimal number. It took less than a quarter second.
I did answer the bit about why I need to optimize in my previous message. I sent it right before you asked.
I shall quote it here:
My program is a little more complex than just a collection of numbers representing the prices of items.
The majority of items don't have a price, but instead derive their price from other items that make it up.
An example would be that a chair would depend on the price of the amount of wood it takes to build that chair, plus the price of all the screws used to build the chair, some glue if glue was used, and sometimes those items it depends on depends on the price of other items as well, for example, the glue would depend on the price of it's chemical makeup, and the plastic that went into making the bottle and it goes on and on. I've even got service worth toggleable in there.
So it's a bit slower than simply setting a single number. That's why the optimization is necessary.
However, as preferable as it would be if there was a way to simply factor in the amount of an item purchased when making the purchase, to come up with the total...
I have been working on a way to separate the items from the prices in terms of price adjustment, so that it can be, as a worst case, as slow as with your test.
Still, I'd not like to give up on simplifying this recursive algorithm process (as you described it) into a single expression, if there's any hope it can be done.
Unfortunately, I'm not that skilled with math and have always needed to push myself to the limits of my abilities in order to know how best to proceed.
Do you realize that, if the pre-purchase price starts at $1 and 2,500 items are purchased, these items would be priced at more than $1,091,782 each?
Yes, no worries, this growth is intentional for the default example use case which is not related to real life monetary values. I've made the change algorithm completely configurable for any future needs of its users.
In my example simulation, supply and demand happen simultaneously, it's not restricted by the time it takes to ship before usage or anything like that; so the price growth through purchases will be cancelled out by the price reduction as the change is applied inversely for every item that is supplied. Of course, even then, the example expression is still fast, which is also for the sake of demonstrating the simulation, and not necessarily the best rate of change for adjusting prices of every item in every use case.
Though, that's getting a bit more into specifics I never believed that his question necessarily needed.
Not that I'm trying to hide my project. I'm happy to share. Just don't see it leading to an answer to the question. Though, at this point, given what you said about it being recursive, which is completely true, it doesn't seem like the question will have the answer I'm looking for.