(The \$\mathbb{Q}\$ in the title means rational numbers.)
Background
Conway base 13 function is an example of a strongly Darboux function, a function that takes every real number on any open interval \$(a,b)\$. In other words, for any given real numbers \$a, b, y\$, you can find a value \$x\$ between \$a\$ and \$b\$ such that \$f(x) = y\$.
The function is defined as follows:
- Write the input value
x
in base 13 using thirteen symbols0 .. 9, A, B, C
, without any trailing infinite stream ofC
s. (It is related to the fact0.9999... = 1
in base 10, or0.CCC... = 1
in base 13.) - Delete the sign and decimal point, if present.
- Replace
A
s with+
,B
s with-
,C
s with.
. - Check if some (possibly infinite) suffix of the sequence starts with a sign (
+
or-
) and contains exactly one.
and no extra signs. If such a suffix exists, interpret it as a decimal number; it is the value of \$f(x)\$. Otherwise, \$f(x) = 0\$.
Some examples:
- \$f(123B45.A3C14159\dots _{13}) = f(0.A3C14159\dots _{13}) = 3.14159\dots \$
- \$f(B1C234 _{13}) = -1.234\$
- \$f(1C234A567 _{13}) = 0\$
Task
Given three rational numbers \$a = \frac{a_n}{a_d}, b = \frac{b_n}{b_d}, y = \frac{y_n}{y_d}\$ given as integer fractions, find a value of \$x = \frac{x_n}{x_d}\$ between \$a\$ and \$b\$ (exclusive) such that \$f(x) = y\$ (where \$f\$ is the Conway base 13 function). There are infinitely many values of \$x\$ that satisfy the condition for any input; just output one of them.
You can assume \$a < b\$, \$a_d, b_d, y_d > 0\$, \$y \ne 0\$, and the fractions are given in the reduced form. Negative input numbers are represented using negative numerators. You don't need to reduce the output fraction.
Standard code-golf rules apply. The shortest code in bytes wins.
Examples
a = 0/1, b = 1/1, y = 1/3
Decimal representation of \$y\$ is \$0.\overline{3}\$ (where the overline is the notation for repeating decimal). To get this value, the minimal base-13 suffix of \$x\$ is \$+.\overline{3}\$ or \$AC\overline{3}\$. An example of such an \$x\$ would be \$0.AC\overline{3}_{13} = 569/676\$. Proof by Wolfram|Alpha.
a = 2017/2197, b = 2018/2197, y = -1/5
The minimal base-13 suffix of \$x\$ is \$-.2 = BC2_{13}\$. But the value of a
is exactly \$0.BC2_{13}\$, so we can't use that. And the value of b
is \$0.BC3_{13}\$, so we're forced to begin with \$0.BC2\$. One possible value of \$x\$ is \$0.BC2BC2_{13} = 4433366 \; / \; 4826809\$.
a = 123/10 = c.3b913b91..., b = 27011/2196 = c.3b93b9..., y = 987/1
One possible answer is \$x = c.3b92a987c_{13} = 130435909031 \; / \; 10604499373\$.
a = -3/2, b = -4/3, y = -1/7
One possible answer is \$x = -1.5bc\overline{142857}_{13} = -28108919 \; / \; 19316024\$.