Background
The greatest common divisor (gcd for short) is a convenient mathematical function, since it has many useful properties.
One of them is Bézout's identity: if d = gcd(a, b)
, then there exist integers x
and y
such that d = x*a + y*b
.
In this challenge, your task is to visualize this property with simple ASCII art.
Input
Your inputs are two positive integers a
and b
, given in any reasonable format.
You may also take unary inputs (repetitions of a single printable ASCII character of your choice), but you must be consistent and use the same format for both inputs.
The inputs may be in any order, and they may be equal.
Output
Your output is a string s
of length lcm(a, b) + 1
(lcm stands for lowest common multiple).
The characters of s
represent integers from 0
to lcm(a, b)
.
The character s[i]
is a lowercase o
if i
is a multiple of a
or b
, and a period .
otherwise.
Note that zero is a multiple of every number.
Now, because of Bézout's identity, there will be at least one pair of characters o
in s
whose distance is exactly gcd(a, b)
.
The leftmost such pair is to be replaced by uppercase O
s; this is the final output.
Example
Consider the inputs a = 4
and b = 6
.
Then we have gcd(a, b) = 2
and lcm(a, b) = 12
, so the length of s
will be 13
.
The multiples of a
and b
are highlighted as follows:
0 1 2 3 4 5 6 7 8 9 10 11 12
o . . . o . o . o . . . o
There are two pairs of o
s with distance two, but we will only replace the leftmost ones with O
s, so the final output is
o...O.O.o...o
Rules and scoring
You can write a full program or a function. The lowest byte count wins, and standard loopholes are disallowed.
Test cases
1 1 -> OO
2 2 -> O.O
1 3 -> OOoo
4 1 -> OOooo
2 6 -> O.O.o.o
2 3 -> o.OOo.o
10 2 -> O.O.o.o.o.o
4 5 -> o...OO..o.o.o..oo...o
8 6 -> o.....O.O...o...o.o.....o
12 15 -> o...........O..O........o.....o.....o........o..o...........o
19 15 -> o..............o...o..........o.......o......o...........o..o..............OO.............o....o.........o........o.....o............o.o..............o.o............o.....o........o.........o....o.............oo..............o..o...........o......o.......o..........o...o..............o
.
,o
orO
.) Or does it have to be1
? Or0
? \$\endgroup\$