Hi, I've been trying to make a circuit that would get each digit of a base 10 number and I'm running into the problem that I can't seem to make a loop to do it. Each extra digit on the original number adds 4 more arithmetic combinators to my circuit. This is very inconvenient given that the numbers I want to use here will keep increasing essentially forever and I'll keep having to expand the circuit, eventually running out of space. The attached picture shows my current setup:
First column is input/n where n is 10^(row number).
Second column is input*n where n is 10^(row number).
Third column is input*(-1)
Fourth column is set to input/n where n is (-1)*10^(row number).
Each row outputs the given position of a digit (symbol 1, symbol 2, etc..) and the count is the actual corresponding digit. Now the question is whether anyone has any better circuits that would loop the mod operand to have the size of the circuit stay constant no matter what the size of the input number is.
Dividing a number into digits. (Modulus 10 circuit)
Dividing a number into digits. (Modulus 10 circuit)
- Attachments
-
- Circuit with the inputs/outputs marked
- factorioModCircuit2.png (5.44 MiB) Viewed 3715 times
-
- factorioModCircuit.png (4.72 MiB) Viewed 3715 times
Last edited by pofigismo on Sun Oct 23, 2016 1:14 pm, edited 1 time in total.
Re: Dividing a number into digits. (Modulus 10 circuit)
There is a way, but it involves black magic. Install a Blueprint String mod and copy the blueprint, but don't try to understand how it works.
viewtopic.php?p=150806#p150806
viewtopic.php?p=150806#p150806
Re: Dividing a number into digits. (Modulus 10 circuit)
Well. I dont do black magic. Kinda sad to see people on factorio forums telling to not try to understand how things work.DaveMcW wrote:There is a way, but it involves black magic. Install a Blueprint String mod and copy the blueprint, but don't try to understand how it works.
viewtopic.php?p=150806#p150806
This also only gives blueprints for up to 9 digits. Which doesn't qualify for "any amount of digits" part. Of course it might work once i figure out the logic there.
edit:
The point of having a loop with less combinators was to reduce the amount of entities performing the exact same calculation, reducing overall lag. This blueprint of yours uses variables that are in like billions, switching all the time and dropping me from 60 straight down to 14 frames while just constantly displaying one number :/
Re: Dividing a number into digits. (Modulus 10 circuit)
First of all your description seems to be faulty since you say that in your first colum you do "*", while your pictures show "/".
If I understand you correctly you want to make a fix sized circuit that gives all the digits seperatly. Whenever you reach a new number of digits you'll need to at least add a new combinator that presents this to the outside world, so this seems inherently impossible.
Also, those numbers can't grow endlessly, I think the limit of the internal data type is around 2 billion, go bigger than that and you are negative again. So you just need 10 digits
If I understand you correctly you want to make a fix sized circuit that gives all the digits seperatly. Whenever you reach a new number of digits you'll need to at least add a new combinator that presents this to the outside world, so this seems inherently impossible.
Also, those numbers can't grow endlessly, I think the limit of the internal data type is around 2 billion, go bigger than that and you are negative again. So you just need 10 digits
Re: Dividing a number into digits. (Modulus 10 circuit)
My bad, mixed it up in the description. first column is "/" second is "*". The rest is correct.mergele wrote:First of all your description seems to be faulty since you say that in your first colum you do "*", while your pictures show "/".
If I understand you correctly you want to make a fix sized circuit that gives all the digits seperatly. Whenever you reach a new number of digits you'll need to at least add a new combinator that presents this to the outside world, so this seems inherently impossible.
Also, those numbers can't grow endlessly, I think the limit of the internal data type is around 2 billion, go bigger than that and you are negative again. So you just need 10 digits
You did understand the intention correctly. However - i only need the modulus circuit to be of fixed size. It can output signals in a row and they can be stored elsewhere, that is of no concern. In such a set up there would be no need to introduce the new value with an additional combinator.
You sure internal limit is 2 billion though? That seems a bit odd given that big ints are used quite often nowadays and are not limited to a specific bit amount.
Re: Dividing a number into digits. (Modulus 10 circuit)
I am not sure about the limit. I think I remember that the highest number had a 2 at highest value digit. If you do some searching for timer stuff I am sure you can somewhere find the correct value (or you just make a circuit that increases until the next increase is smaller than the current value and let it run for a bit).
Now for the fancy solution.
All in one circuit:
A -> P
P -> Q
A / 10 -> L
L * 10 -> M
Q - M -> C
A / 10 -> A
This will give you the digits from low-priority to high priority of the value initially loaded into A in signal C, each tick the next value. Three ticks between loading A and the first outputsignal.
P and Q are just buffer for A, M is A without the lowest value digit.
Put some Flipflops behind that, with timersignal T = the position of the digit they shall store as clock, put a T + 1 -> T in your network, and reload A with the current value and T with -4 or -3 (depending on if you want to start counting at 0 or 1) once T is bigger than ((the max amount of digits you want to extract) + 3).
Now for the fancy solution.
All in one circuit:
A -> P
P -> Q
A / 10 -> L
L * 10 -> M
Q - M -> C
A / 10 -> A
This will give you the digits from low-priority to high priority of the value initially loaded into A in signal C, each tick the next value. Three ticks between loading A and the first outputsignal.
P and Q are just buffer for A, M is A without the lowest value digit.
Put some Flipflops behind that, with timersignal T = the position of the digit they shall store as clock, put a T + 1 -> T in your network, and reload A with the current value and T with -4 or -3 (depending on if you want to start counting at 0 or 1) once T is bigger than ((the max amount of digits you want to extract) + 3).
Re: Dividing a number into digits. (Modulus 10 circuit)
Well, 2 billion would make sense if game uses 32bit ints, either way - I'll check that tomorrow, if it turns out to be true I could just go with 10 digits and be happy.mergele wrote:I am not sure about the limit. I think I remember that the highest number had a 2 at highest value digit. If you do some searching for timer stuff I am sure you can somewhere find the correct value (or you just make a circuit that increases until the next increase is smaller than the current value and let it run for a bit).
Now for the fancy solution.
All in one circuit:
A -> P
P -> Q
A / 10 -> L
L * 10 -> M
Q - M -> C
A / 10 -> A
This will give you the digits from low-priority to high priority of the value initially loaded into A in signal C, each tick the next value. Three ticks between loading A and the first outputsignal.
P and Q are just buffer for A, M is A without the lowest value digit.
Put some Flipflops behind that, with timersignal T = the position of the digit they shall store as clock, put a T + 1 -> T in your network, and reload A with the current value and T with -4 or -3 (depending on if you want to start counting at 0 or 1) once T is bigger than ((the max amount of digits you want to extract) + 3).
As for the actual solution - that sounds exactly like what I'd want, but I'm way too sleepy to test it right now, so it will have to wait until tomorrow as well. Thanks!