Stock Redistribution

A forum for good logic/math puzzles.

Moderators: jestingrabbit, Moderators General, Prelates

Micklebring
Posts: 8
Joined: Mon Aug 03, 2009 1:51 am UTC

Stock Redistribution

Postby Micklebring » Fri Dec 02, 2016 5:35 pm UTC

A small village of industrious people wish to buid a school.

Schools need 4 things to be built, Wood, Clay, Iron and Wheat.

The villagers make 2188 units of Wood per hour
The villagers make 2625 units of Clay per hour
The villagers make 2188 units of Iron per hour
The villagers make 35493 units of Wheat per hour

They have 176236 Wood in stock
They have 248865 Clay in stock
They have 176236 Iron in stock
They have 86879 Wheat in stock

The school is going to cost 256190 Wood, 329385 Clay, 256190 Iron, 73195 Wheat

This means it will take them 1 day, 12 hours 32 minutes before they can enlarge their school as they'll be short of Wood and Iron.

A friendly wizard walks into the village and says "I can transform your stock, 1 for 1 from and to any other type of stock but you must tell me what you want changing to what. This will allow you to build you school sooner."

The villagers are amazed but none of them is very good at maths as they don't have a school yet. They all look confused.

Can you tell them the ideal redistribution of their stock to minimise the time before they can build their school? I can't.

And assume a day is a very long time where they are. :)

And bonus point if anyone knows what game I'm playing that lead to this.

ThemePark
Posts: 450
Joined: Fri Jun 27, 2008 5:42 pm UTC
Location: Århus, Denmark

Re: Stock Redistribution

Postby ThemePark » Fri Dec 02, 2016 6:05 pm UTC

Okay, I'll bite.

Spoiler:
The answer is 6 hours and it sounds like Settlers of Catan to me
I have traveled from 1979 to be a member of the unofficial board Council of Elders. Phear M3

Xias
Posts: 361
Joined: Mon Jul 23, 2007 3:08 am UTC
Location: California
Contact:

Re: Stock Redistribution

Postby Xias » Fri Dec 02, 2016 6:22 pm UTC

ThemePark wrote:Okay, I'll bite.

Spoiler:
The answer is 6 hours and it sounds like Settlers of Catan to me


My solution gives

Spoiler:
21 hours, 55 minutes, 58 seconds.


I think one of us has misunderstood the question.

EDIT: I suppose I could include my distribution:

Spoiler:
208202 Wood
271812 Clay
208202 Iron
0 Wheat
Last edited by Xias on Fri Dec 02, 2016 7:36 pm UTC, edited 1 time in total.

User avatar
Gwydion
Posts: 330
Joined: Sat Jun 02, 2007 7:31 pm UTC
Location: Chicago, IL

Re: Stock Redistribution

Postby Gwydion » Fri Dec 02, 2016 6:40 pm UTC

The answer depends on one significant factor:
Spoiler:
Whether the wizard is willing or able to hang around for about 5.5 hours before making the switch. If so, the rapid wheat production between now and then can be used to make whatever else they're short on. If the wizard has to make the change right now and then disappears, I think Xias is correct or very close.

ThemePark
Posts: 450
Joined: Fri Jun 27, 2008 5:42 pm UTC
Location: Århus, Denmark

Re: Stock Redistribution

Postby ThemePark » Fri Dec 02, 2016 6:48 pm UTC

Spoiler:
Gwydion has noticed what I did too, that the redistribution doesn't matter, it's the total number of items needed that matters. I made the assumption that the wizard either does wait or comes at the necessary time, when production is done.

Also, I didn't take minutes into account, but to be specific it would take 5 hours, 20 minutes and 10 seconds. By that time 914968,7 items would have been produced, and 914960 are needed for production.
I have traveled from 1979 to be a member of the unofficial board Council of Elders. Phear M3

User avatar
PeteP
What the peck?
Posts: 1451
Joined: Tue Aug 23, 2011 4:51 pm UTC

Re: Stock Redistribution

Postby PeteP » Fri Dec 02, 2016 6:57 pm UTC

So only the current stock and not what they get later? And can you do only one change or multiple ones?

Assuming as many changes as you want:
Spoiler:
Since Wheat fills in about 2 hours from zero we can distribute all of it among the rest, and forget about it.

At the start

Code: Select all

256190-176236=79954 79954/2188=36,5
329385-248865=80520 80520/2625=30.67

To catch up to clay:
79954/2188-80520/2625=5.87
(79954/2188-80520/2625)*2188=12839 (rounded up.)
So 79954-12839=67115 is the amount of wood/iron we still need
And 86879-2*12839=61201 wheat still left.
Distribute the rest of the wheat according to the per hour value to free up the same amount of hours so:
80520-61201*2625/(2188*2+2625)=57572 57572/2625=21.9
67115-61201*2188/(2188*2+2625)=47989 47989/2188=21.9


So same as Xias. I assume ThemePark converted the production too resulting in (79954*2+80520+73195-86879)/(2188*2+2625+35493)=5.34hours (ninja'd)

ThemePark
Posts: 450
Joined: Fri Jun 27, 2008 5:42 pm UTC
Location: Århus, Denmark

Re: Stock Redistribution

Postby ThemePark » Fri Dec 02, 2016 7:03 pm UTC

Well, at least now he has some answers to choose from. :D
I have traveled from 1979 to be a member of the unofficial board Council of Elders. Phear M3

Micklebring
Posts: 8
Joined: Mon Aug 03, 2009 1:51 am UTC

Re: Stock Redistribution

Postby Micklebring » Fri Dec 02, 2016 9:20 pm UTC

It's a flying one-off visit from the Wizard and he can't wait around for the shortfall as he has to go to bed.

The puzzle is derived from Travian. I have a big spreadsheet I use to help me play only I won't have access to that until Monday. In reality I'' the wizard who can adjust the stock before I go to bed to prevent the granary overflowing and get the "school" started while I''m asleep. What I am after is the working out.

User avatar
PeteP
What the peck?
Posts: 1451
Joined: Tue Aug 23, 2011 4:51 pm UTC

Re: Stock Redistribution

Postby PeteP » Fri Dec 02, 2016 9:54 pm UTC

Well if you want a general strategy to solve it:
Spoiler:
The result is optimal when all resources either need the same time X to reach the goal or have 0 stock and need less than X.

So add all stocks together lets call the value S. Then calculate for each resource how long it needs to reach the goal if it has 0 stock, lets call the 4 results T1,T2,T3 and T4 and lets say that we have ordered them so that T1 is the longest time and T4 the shortest. Then assign enough of S to T1 so that the new Tnew1=T2. Which is easy: T1-T2=k and if the T1 resource produces x per hour then you can reduce the time by k hours by adding x*k to the stock for the resource associated with T1.

If there is still stock left distribute it so that Tnew1=Tnew2=T3 and afterward the same with T4. If there is still stock left distribute it based on the production. (You want to reduce the time for each one by the same amount. So if one produces 5k per hour and the other 1k the first one needs 5 times as much stock for the same time reduction.)

There are other ways of course but this one should be easy to understand and execute.

Micklebring
Posts: 8
Joined: Mon Aug 03, 2009 1:51 am UTC

Re: Stock Redistribution

Postby Micklebring » Sun Dec 04, 2016 10:01 pm UTC

Xias has the correct answer. I ended up brute forcing it overnight with an i7 to prove to myself a) it was correct and b) as if I needed telling, my Excel skills are rubbish. I shall continue to infuse PeteP's answer and try and learn a few new things in Excel. Thank you all for your input.

Jeff_UK
Posts: 66
Joined: Sat Nov 03, 2007 10:38 pm UTC

Re: Stock Redistribution

Postby Jeff_UK » Tue Feb 14, 2017 1:24 pm UTC

Micklebring wrote:Xias has the correct answer. I ended up brute forcing it overnight with an i7 to prove to myself a) it was correct and b) as if I needed telling, my Excel skills are rubbish. I shall continue to infuse PeteP's answer and try and learn a few new things in Excel. Thank you all for your input.


The Free 'Solver' Add-in solves this in about 5 seconds.. it's a great tool.
"Please only print this post if you really need to"
...hmm....I wonder how much extra energy is required to generate that request...We need a cost/benefit analysis, STAT!


Return to “Logic Puzzles”

Who is online

Users browsing this forum: No registered users and 11 guests