I proposed this code golf on sandbox:
Integer Logarithm
Take \$a \in ℤ_{>1}\$ and \$b \in ℤ_+\$ as inputs. Write a function \$f\$ that:
$$ f(a,b) = \left\{ \begin{array}{ll} \text{Just} \space \log_ab & \quad \text{if} \space \log_ab \in ℚ \\ \text{Nothing} & \quad \text{otherwise} \end{array} \right. $$
Rules
Types and formats of the inputs doesn't matter, but they must be able to represent at least 2 bits. For example, in C++,
int
,unsigned
,std::vector<bool>
, or evenstd::string
containing ASCII digits are acceptable.Type and format of the output doesn't matter either, but the fraction must be irreducible. In C++,
std::optional<std::pair<int,unsigned>>
is an example.You must not use floating-point numbers because of their errors.
if \$a\$ and \$b\$ aren't in the sets as specified above, the challenge falls in don't care situation.
\$f\$ may be curried or uncurried.
As this is a code-golf, the shortest code in bytes wins.
But to think about it, I doubt that golfing languages natively support rational number arithmetic. Unlike this challenge, it actively requires arithmetics on rational numbers, in sake of, for example, Newton's method.
Do major golfing languages such as 05AB1E, Jelly, APL, and Charcoal natively support rational number arithmetic?
p,q
so thata^q = b^p
, and outputtingp/q
. Actually, even the ratio of their respective counts of prime factors in their factorizations should suffice. \$\endgroup\$