Rabbinatix
Sign inGet started
Store

Greatest common divisor

FreeLogic
@rabbinatix/greatest-common-divisor by Rabbinatixupdated Oct 4, 2026

The largest number that divides both: gcd(48, 18) = 6.

Sign in to add

Euclid's algorithm with a While loop: replace (x, y) by (y, x mod y) until y is 0. Use it to simplify fractions or ratios. Three variables hold the state; Set Variable nodes run in the order of their exec wires.

Shows: While, Not Equals, Modulo, Absolute, Get / Set Variable.

How to use it

Add it to your logic, then add a Call Function step in any logic and pick GCD. It belongs to no system, so every system can use it. Or download the TypeScript and call it from your own code.

Inputs
a: Whole number
b: Whole number
Outputs
gcd: Whole number
Previewdrag the steps around; scroll to zoom
Function Entry, Input / output. 0 inputs, 3 outputs. step 1 of 15
GCD
a
b
Absolute, Math. 1 input, 1 output. step 2 of 15
Absolute
value
result
Absolute, Math. 1 input, 1 output. step 4 of 15
Absolute
value
result
Set Variable, Data. 2 inputs, 2 outputs. step 3 of 15
Set x
value
value
Set Variable, Data. 2 inputs, 2 outputs. step 5 of 15
Set y
value
value
Get Variable, Data. 0 inputs, 1 output. step 9 of 15
Get x
value
Get Variable, Data. 0 inputs, 1 output. step 6 of 15
Get y
value
Get Variable, Data. 0 inputs, 1 output. step 13 of 15
Get t
value
Not Equals, Operators. 2 inputs, 1 output. step 7 of 15
!=
A
B
result
While, Flow control. 2 inputs, 3 outputs. step 8 of 15
While
condition
Loop Body
iteration
Completed
Modulo, Operators. 2 inputs, 1 output. step 10 of 15
%
A
B
result
Set Variable, Data. 2 inputs, 2 outputs. step 11 of 15
Set t
value
value
Set Variable, Data. 2 inputs, 2 outputs. step 12 of 15
Set x
value
value
Set Variable, Data. 2 inputs, 2 outputs. step 14 of 15
Set y
value
value
Return, Input / output. 2 inputs, 0 outputs. step 15 of 15
Return
gcd

Arrow keys: next or previous step in flow order. Alt with arrows: nearest step in that direction. Enter: open. Shift F10: more actions.

100%
Examplesrun live against the logic · 2/2 pass
PassedExampleInputOutput
48 and 18{"a":48,"b":18}{"gcd":6}
Negative and zero{"a":-7,"b":0}{"gcd":7}
Try it
Versions
In this package
GCD (entry)