Instructions :
Set number A and B in the constant combinators on the left sidePlace 1 thing in any of the chest and rotate the inserter so that it transfer the thing.
Read result on the power pole as "B", it is in fact the GCD of the original A and B.
you can change A or B in the constant and rotate the inserter again to update the GCD of the new A and B.
How it works :
The setup with the inserter triggers a pulse for the initial A and B to go into a circuit which is a loop that will yield new A and B every cycle past the initial one. Such circuit is easier to understand when it is not made into a loop, but rather linear, where each "step" of the algorithm is located right next to the other instead of following each other in time. It look like this :The additionnal operation to make it into the first setup was to add a memory cell at the end, that is reset everytime the circuit output a new value, this way it keep the last one before 0, which was the GCD. The memory cell was also made to be reset by the initial pulse from the inserter that feed the initial A and B for ease of use.
The actual code i tried to follow was :
Code: Select all
{
a = 252;
b = 105;
while(b != 0) {
t = b;
b = a % b;
a = t;
}
gcd = a;
}
because there was no blueprint attached to the video : https://www.youtube.com/watch?v=2Oe_N8yAynY