## Circuit Design - Implementing a X < Y Decider with no signal on X.

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Ickis
Manual Inserter
Posts: 3
Joined: Mon Nov 19, 2018 12:31 pm

### Circuit Design - Implementing a X < Y Decider with no signal on X.

Hello,

I'm trying to wrap my head around circuits. I feel I'm getting a decent handle, but I just can't work out how to achieve this.

1) I have a filter inserter moving goods from chest A to chest B.
2) It has its filter configured by a decider combinator.
3) It is set up currently such that if chest B has less than 10 of item X, then the combinator outputs 1 for EACH, and sets the filter of the inserter to this.
3) The inserter will then move the items from chest A to chest B.

This ensures that chest B always has 10 of every item contained within chest A. However, this method fails if chest B does not contain item X, as then item X has no signal, and is not considered within the EACH, so the filter is never set for item X.

I'm well aware I could specifically set the items to filter on the inserter and it would work fine, however I'm wanting to keep it generic so as to be able to transfer all items from one chest to another. How can I get around this limitation that X == 0, is actually X == NULL?

DaveMcW
Smart Inserter
Posts: 2540
Joined: Tue May 13, 2014 11:06 am

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Attach a constant combinator to the chest with every item you want equal to 1.

Trebor
Long Handed Inserter
Posts: 99
Joined: Sun Apr 30, 2017 1:39 pm

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

This is a little involved:

1) Connect a red wire from chest A to decider combiner 1, set condition to Each > 0 output 1 Each. Output will be 1 for every item in chest A.

2) Connect a red wire from decider combiner 1 to arithmetic combiner 2, set condition to Each * -10 output Each. Output will be -10 for every item in chest A.

3) Connect a red wire from arithmetic combiner 2 to decider combiner 3, connect a green wire from chest B to decider combiner 3, set condition to Each < 0 output Each. Output will be a negative number for every item in chest A that does not have 10 items in chest B.

4) Connect a red wire from decider combiner 3 to arithmetic combiner 4, set condition to Each * -1 output Each. Output will be the count of each item missing from chest B that is in chest A.

5) Connect a red wire from arithmetic combiner 4 to filter inserter. Filter will be set to the five items that are most needed in chest B.

As items are added/removed to/from chest A or B the filter on the filter inserter will be updated.

Ickis
Manual Inserter
Posts: 3
Joined: Mon Nov 19, 2018 12:31 pm

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

DaveMcW wrote:
Sat Nov 24, 2018 9:13 am
Attach a constant combinator to the chest with every item you want equal to 1.
Thanks that wouldn't keep it generic though.

Ickis
Manual Inserter
Posts: 3
Joined: Mon Nov 19, 2018 12:31 pm

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Trebor wrote:
Sat Nov 24, 2018 9:25 am
This is a little involved:

1) Connect a red wire from chest A to decider combiner 1, set condition to Each > 0 output 1 Each. Output will be 1 for every item in chest A.

2) Connect a red wire from decider combiner 1 to arithmetic combiner 2, set condition to Each * -10 output Each. Output will be -10 for every item in chest A.

3) Connect a red wire from arithmetic combiner 2 to decider combiner 3, connect a green wire from chest B to decider combiner 3, set condition to Each < 0 output Each. Output will be a negative number for every item in chest A that does not have 10 items in chest B.

4) Connect a red wire from decider combiner 3 to arithmetic combiner 4, set condition to Each * -1 output Each. Output will be the count of each item missing from chest B that is in chest A.

5) Connect a red wire from arithmetic combiner 4 to filter inserter. Filter will be set to the five items that are most needed in chest B.

As items are added/removed to/from chest A or B the filter on the filter inserter will be updated.
That's brilliant thanks! Although I found that arithmetic combiner 4 was messing things up, I removed it and simply connecting a red wire from decider combiner 3 to the filter is what worked.

Have you thought about doing some tutorials on circuit design? Seen many things on it, but your way of writing has been by far the clearest.

Optera
Smart Inserter
Posts: 1719
Joined: Sat Jun 11, 2016 6:41 am

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

You can do it much easier with integer overflow.

Specific:
One constant combinator set to 2147483647 - how much you want in chest B of whatever linked to both chest and filter inserter.

Generic:
1) decider combinator set to each != 0 each = 1 feed the output into
2) arithmetic combinator set to each * (2147483647 - desired amount) = each (sadly we cant directly set the decider output to any number or we could skip this arithmetic entirely)
and finally feed that to the filter inserter

Edit: just realized you want a generic way independent of chest B having an item so my generic way won't work.

Edit2:
Here's a generic way that will ensure anything in chest A will have > 10 in B.
2018-11-24-12-35-07-5331553.png (162.2 KiB) Viewed 166 times

Con:
It may lock the inserter if chest B contains enough things <10 that Chest A can't provide.
My Mods:

quyxkh
Filter Inserter
Posts: 598
Joined: Sun May 08, 2016 9:01 am

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Trebor wrote:
Sat Nov 24, 2018 9:25 am
This is a little involved:

1) Connect a red wire from chest A to decider combiner 1, set condition to Each > 0 output 1 Each. Output will be 1 for every item in chest A.

2) Connect a red wire from decider combiner 1 to arithmetic combiner 2, set condition to Each * -10 output Each. Output will be -10 for every item in chest A.

3) Connect a red wire from arithmetic combiner 2 to decider combiner 3, connect a green wire from chest B to decider combiner 3, set condition to Each < 0 output Each. Output will be a negative number for every item in chest A that does not have 10 items in chest B.

4) Connect a red wire from decider combiner 3 to arithmetic combiner 4, set condition to Each * -1 output Each. Output will be the count of each item missing from chest B that is in chest A.

5) Connect a red wire from arithmetic combiner 4 to filter inserter. Filter will be set to the five items that are most needed in chest B.

As items are added/removed to/from chest A or B the filter on the filter inserter will be updated.
This is the one, except you can do it with three combinators. I'd describe the setup as A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each redwired to Each*-1⇒Each, B greenwired to the Each*-1 negator greenwired to your filter. So the negator sees -10 X for each X in A, plus n X for every X in B, and negates the sum, giving -nX+(10 if X in A), positive only if X is in A and there's less than 10 of it in B.

Another wiring that gets the same result is to make the multiplier be *10 instead of *-10 and greenwire its output to the negator's output.

Trebor
Long Handed Inserter
Posts: 99
Joined: Sun Apr 30, 2017 1:39 pm

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

quyxkh wrote:
Sat Nov 24, 2018 12:53 pm
This is the one, except you can do it with three combinators. I'd describe the setup as A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each redwired to Each*-1⇒Each, B greenwired to the Each*-1 negator greenwired to your filter. So the negator sees -10 X for each X in A, plus n X for every X in B, and negates the sum, giving -nX+(10 if X in A), positive only if X is in A and there's less than 10 of it in B.

Another wiring that gets the same result is to make the multiplier be *10 instead of *-10 and greenwire its output to the negator's output.
I like that but my OCD would have wired it just a little differently:
A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each greenwired to Each*-1⇒Each, B redwired to the Each*-1 negator redwired to your filter.

That way A travels on the green wire and B travels on the red wire.

Trebor
Long Handed Inserter
Posts: 99
Joined: Sun Apr 30, 2017 1:39 pm

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Ickis wrote:
Sat Nov 24, 2018 10:23 am
Have you thought about doing some tutorials on circuit design? Seen many things on it, but your way of writing has been by far the clearest.
Thank you.

quyxkh
Filter Inserter
Posts: 598
Joined: Sun May 08, 2016 9:01 am

### Re: Circuit Design - Implementing a X < Y Decider with no signal on X.

Trebor wrote:
Sat Nov 24, 2018 4:00 pm
quyxkh wrote:
Sat Nov 24, 2018 12:53 pm
This is the one, except you can do it with three combinators. I'd describe the setup as A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each redwired to Each*-1⇒Each, B greenwired to the Each*-1 negator greenwired to your filter. So the negator sees -10 X for each X in A, plus n X for every X in B, and negates the sum, giving -nX+(10 if X in A), positive only if X is in A and there's less than 10 of it in B.

Another wiring that gets the same result is to make the multiplier be *10 instead of *-10 and greenwire its output to the negator's output.
I like that but my OCD would have wired it just a little differently:
A greenwired to Each>0⇒1 Each greenwired to Each*-10⇒Each greenwired to Each*-1⇒Each, B redwired to the Each*-1 negator redwired to your filter.

That way A travels on the green wire and B travels on the red wire.
Yup. Two mental models. I like using red for negative (want/take) values when I can, color by value source looks like it'd also work.