Even split of remainder

This board is to show, discuss and archive useful combinator- and logic-creations.
Smart triggering, counters and sensors, useful circuitry, switching as an art :), computers.
Please provide if possible always a blueprint of your creation.
Post Reply
User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Even split of remainder

Post by Impatient »

I have 4 train unloading stations (S1, ... S4). Equally named to unload the same things. And depending on demand I calculate how many supply trains (T) should go there. As I want to optimize throughput, I am distributing the supply trains to the 4 stations as equal as possible, using the train limit feature and a combinator setup.

First I do

Code: Select all

S1..S4 = T / 4
to get a rough equal split.

After that I only need to split the remainder evenly to some of the stations. I do

Code: Select all

R4 = T % 4
Split3 = R4 / 3
S1..S3 += Split3
Because if R4 was 3 then the Split3 is 1 and the remainder will be split evenly among S1 ... S3. If it was lower than 3 then the result is 0 and there is no threeway split.

In a next iteration I do

Code: Select all

R3 = R4 % 3
Split2 = R3 / 2 
S1..S2 += Split2
If R3 was 2, these 2 will be split to S1 and S2, if it was 1 then there is no twoway split.

In the last iteration I just do

Code: Select all

R2 = R3 % 2
S1 += R2
This way I take care of all possible remainder cases of 1,2 and 3.

This is how it looks:
remainder of 4.jpg
remainder of 4.jpg (90.64 KiB) Viewed 2490 times
And this is the blueprint:






Do you have any ideas/knowledge if this can be done with less combinators? Thanks!
Last edited by Impatient on Mon May 24, 2021 11:04 am, edited 1 time in total.

SoShootMe
Filter Inserter
Filter Inserter
Posts: 475
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

Re: Even split of remainder

Post by SoShootMe »

Impatient wrote:
Mon May 24, 2021 4:14 am
Do you have any ideas/knowledge if this can be done with less combinators? Thanks!
There's probably a better way, but a simple approach is to use decider combinators to add one to some of output signals, according to the remainder:


User avatar
disentius
Filter Inserter
Filter Inserter
Posts: 694
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: Even split of remainder

Post by disentius »

Hmm... It seems you assume consumption of the materials is always equal for each unload station.
Why not look at the # of items in each station to determine where the next rain has to go?
i am building a trainbase where all load and unload stations have the same name per material shipped, and use trainlimit 0/1 for each. For the unload stations I calculated (roughly) how much time the trains need to get to their destination, and set the minimum buffer needed to bridge that gap based on full throughput accordingly.

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Even split of remainder

Post by Impatient »

Ah, yes of course. Logic instead of arithmetic. This simplifies the combinator setup considerably:
evenSplitRemainderOf4.2.jpg
evenSplitRemainderOf4.2.jpg (45.35 KiB) Viewed 2428 times
Last edited by Impatient on Mon May 24, 2021 2:49 pm, edited 1 time in total.

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Even split of remainder

Post by Impatient »

disentius wrote:
Mon May 24, 2021 11:50 am
That is off topic, but since I failed to hide the context good enough to not make readers curious :D :
Context

User avatar
disentius
Filter Inserter
Filter Inserter
Posts: 694
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: Even split of remainder

Post by disentius »

Aha, context is king:)

So each station has to have a guaranteed throughput of 3K/s -> 1 train every 16.6 seconds. Correct?

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Even split of remainder

Post by Impatient »

More off topic

User avatar
disentius
Filter Inserter
Filter Inserter
Posts: 694
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: Even split of remainder

Post by disentius »

Wandering mind.... :lol: Something along the lines of trainlimits adjusted per time passed.


If you have enough trains and an oversupply of steam, you could also use a constant limit of 2. with 1-2 trains you can get each train its own stacker for the second one if you have room.
2021-05-24 18_53_23-Factorio 1.1.34.png
2021-05-24 18_53_23-Factorio 1.1.34.png (397.51 KiB) Viewed 2404 times

User avatar
Impatient
Filter Inserter
Filter Inserter
Posts: 883
Joined: Sun Mar 20, 2016 2:51 am
Contact:

Re: Even split of remainder

Post by Impatient »

even more off topic

User avatar
disentius
Filter Inserter
Filter Inserter
Posts: 694
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: Even split of remainder

Post by disentius »

You are right. As I said, wandering mind....
We ll discuss NxN stations in another topic.

Post Reply

Return to “Combinator Creations”