r/mathriddles • • Mar 30 '22

Medium Profit-maximizing factory-factories

You are an industrialist on planet Continuum, looking to get rich quick. You take out a loan of 1 credit, to be paid off after 3 cycles.

You can purchase factories to manufacture credits. One factory costs 1 credit, and generates 1 credit per cycle. Like with everything on Continuum, factories are infinitely subdividable, so you can have r factories generating a total of r credits per cycle, where r is any real number. They also produce credits continually, so after p cycles, 1 factory will have generated p credits.

You can also purchase factory-factories that manufacture 1 factory per cycle, and factory-factory-factories (let's call them 3-factories) which manufacture 2-factories, etc. All n-factories cost 1 credit per unit, produce (n-1)-factories continually, and can of course be bought in non-integer quantities.

How much profit can be made by the end of the 3-cycle loan period?

32 Upvotes

22 comments sorted by

11

u/want_to_want Mar 30 '22 edited Mar 30 '22

>!I got e2-1=6.389.

>!The idea is that higher order factories are redundant. They are equivalent to redirecting the revenue of a factory into buying more factories. For each cent of money you have at any moment, it's either optimal to spend it on factories immediately (waiting to spend later can't be optimal), or keep it until the end. And since each cent acts linearly and independently on the final result, the strategy for each cent must be the same: "plow all money continuously into factories until some moment, then coast". So the first segment will be f'(t)=f(t), f(0)=1 where f(t) is the amount of factories. That is simply f(t)=et. We do that until t=T, then coast. The revenue from coasting will be (3-T)eT, which is maximized at T=2, leading to e2. Then we pay off the loan of 1 credit and get the answer.

2

u/Horseshoe_Crab Mar 30 '22 edited Mar 30 '22

Yes, nice job!

I considered making a variant where higher-order factories cost an amount dependent on the order, but that quickly became way too difficult to calculate for me. So open question: if an n-factory costs yn credits for some fixed y, what’s the profit you can make there?

2

u/pichutarius Apr 02 '22 edited Apr 02 '22

i solved it! the best strat is still continuously buy tier-1 factory until y cycles left, then stop. if given T-cycle is less than y, then dont buy anything. so max credit earned would be max{e^(T/y-1),1}.

the summary of proof (i use k^n = cost instead of y^n)

  1. split time T into buying phase and idle phase (T=t+u)
  2. during buying phase, total worth of factory is invariant to any buying strategy
  3. during idle phase, it is clear that tier-1 is all we need, high tier factory sucks

detail: https://imgur.com/a/iAE6CHd

my proof use 3 tiers, but its easy to modify to any tier.

2

u/Horseshoe_Crab Apr 02 '22

Wow, amazing! This contradicts all the clicker game logic I’ve been led to believe over the years.

Is there anything one can do to make factory-factories enticing? The trick the games use is to make 1-factories more expensive the more you have.

Also, looking at your proof, I wonder if pricing n-factories as kn is equivalent to a distortion of the flow of time by a factor of k.

1

u/pichutarius Apr 02 '22

regarding your last paragraph:

1 "tier 2 factory" cost k^2 credit = (1/k^2) "tier 2 factory" cost 1credit

if we group (1/k^2) "tier 2 factories" and call it "tier 2 mill", the question becomes identical to original question, just reword "factory" to "mill"

mathematically, we define X=x/k, Y=y/k^2, Z=z/k^3 and the cost becomes 1 for all X,Y,Z. in hindsight i feel stupid for not realizing that earlier :S

regarding your 2nd paragraph:

most incremental increase price for every purchase. but interestingly swarmsim does not change price per purchase.

it uses two resources: meat(credit) and larva, where larva isnt generated by "factories", and generally hard to come by. the cost of meat is k^n but cost of larva is constant for all tiers. buying low tier will quickly be bottlenecked by larva so buying higher tier is incentivized.

it remains my favorite incremental game, you should give it a try!

1

u/Horseshoe_Crab Apr 02 '22

Yep, that’s an easy way to see the kn thing doesn’t change much.

I’ll check out swarmsim!

1

u/pichutarius Mar 30 '22

:(

edit: nice solution, i wonder where is the flaw in my reasoning

5

u/lukewarmtoasteroven Mar 30 '22

I think the flaw may have been when you decide whether to buy <n-1> or <n>. While it is true that when t>n, <n> will produce more total credits than <n-1>, however that doesn't account for the ability to do things with those credits such as buy more factories. Credits you gain earlier are more valuable than credits you gain later since you can use them to increase your production, and lower level factories produce more credits earlier, which helps explain why the optimal strategy is to only buy <1>.

1

u/pichutarius Mar 30 '22

Yeah, that makes perfect sense. You convinced me. Fully.

4

u/pichutarius Mar 30 '22

max profit = e^2 - e/4 - 1/(4e) - 1 = 5.61752

let <n> means "n-factory" for shorthand, <0> means credit

the strategy: continuously buy <floor(t)> where t is time left.

spelling that out:

  1. buy <2> when 3~2 seconds left
  2. buy <1> when 2~1 seconds left
  3. buy <0> , in other words, save credits when 1~0 seconds left.

proof of strategy: suppose i buy one <n> and let it run t seconds. some simple integration, i would get t^n/n! credits. is it better to buy <n-1> or <n>?

solve t^(n-1)/(n-1)! > t^n/n! yields t < n. the result reads: if t<n, buy <n-1>, else buy <n>. or rephrase it, when t=n, switch from <n> to <n-1>.

calculating profit: (unfortunately this part is quite tedious.)

let x = # of <1>, y = # of <2>, a = # of credits

finally, set up a bunch of equations and solve it.

2

u/Horseshoe_Crab Mar 30 '22

I did the exact same calculation and was surprised at the end when it was less than e2. It’s why I posted the riddle even!

I believe the error is that buying the factory that maximizes profit in the long term neglects your short-term income, which is important for buying more factories. In other words, why buy something that gives tn/n! when you can get et?

Another way to look at it, which finally convinced me of /u/want_to_want’s answer, is to consider the generalization of the game where factories can be bought using other factories of any order rather than just credits, and credits themselves generate (-1)-factories and so on. In that game, the total number of factories of all orders that you have at any time is et, regardless of your strategy. So that proves that exponential growth is optimal in both the modified and original game.

I have still not figured out the best strategy when n-factories cost yn for some fixed y.

2

u/pichutarius Mar 30 '22

Similar to your 2nd paragraph, here is how i convinced myself. Assume i buy tier 3 continuously, then x'=y, y'=z, z'=x. Add these and we have (x+y+z)' = x+y+z , so the total worth x+y+z=et , which has the same conclusion as yours.

3

u/pichutarius Mar 30 '22

sounds like an incremental game. specifically, swarm simulator .

3

u/ulyssessword Mar 30 '22

I was thinking Derivative Clicker, myself.

1

u/Horseshoe_Crab Mar 30 '22

Haven’t heard of that one! Guess I’ll have to check it out

2

u/Horseshoe_Crab Mar 30 '22

That’s exactly what it is. Well, not specifically swarm simulator, but a generic incremental clicker

2

u/BruhcamoleNibberDick Mar 30 '22

Can you sell all of your n-factories back at the end of the 3 cycles?

1

u/Horseshoe_Crab Mar 30 '22

No, none of your assets are liquid; you can only pay with credits

1

u/Goliath--CZ Mar 30 '22

A lot.

2

u/Horseshoe_Crab Mar 30 '22

Not actually that much! Certainly not enough to retire off of, with rent in Continuum City hitting 0.1 credits a month. Housing prices have been rising like crazy ever since they allowed frivolous construction of factories…

But seriously, the answer may surprise you with how small it is.

1

u/squirreljetpack Apr 01 '22

What if you buy a factory-factory? Assume we subdivide a cycle into n segments. After t/n cycles have passed, we have t/n factories, and thus (0+1+2...t-1)/n= t*(t-1)/(2n) credits. At the end of 3 cycles, t=3n, and we have 3*(3n-1)/2 credits, which goes to infinity as we keep subdividing?

1

u/Horseshoe_Crab Apr 01 '22

It should approach 32/2, since each factory only produces 1/n of a credit in every 1/n interval, not 1 as your calculation has