Anomalous Cancellation (from Wolfram Alpha):
Anomalous cancellation is a "canceling" of digits of a and b in the numerator and denominator of a fraction a/b which results in a fraction equal to the original. Note that if there are multiple but differering counts of one or more digits in the numerator and denominator there is ambiguity about which digits to cancel, so it is simplest to exclude such cases from consideration. Link
In simple terms, say you have a fraction a / b
. If you can cancel out the digits in the fraction to create another fraction c / d
which is equal to the original (a / b = c / d
), anomalous cancellation can be used to simplify the fraction.
Your challenge is to make a program or function that inputs a fraction string in the form a/b
and outputs or returns a truthy value if the fraction can be simplified using anomalous cancellation, and a falsy value otherwise. a
and b
will always be non-zero positive integers. a
and b
will always have two or more digits. Also, all of the digits from either a
or b
will not be cancelled out (You wont get the input 12/21
), at least one digit from a
and b
will be cancelled each time (You wont get the input 43/21
), and the end result will never be 0
for either a
or b
. Your program must cancel out all common digits between a
and b
(ie. in 1231/1234
, you must cancel out a 1
, a 2
, and a 3
). If there is multiple possibilities for cancellation, choose the leftmost digit first (515/25 becomes 15/2 not 51/2).
Examples:
Input Output Why
1019/5095 true Remove the 0 and the 9 from both sides of the fraction to get 11/55, which is equivalent.
16/64 true Remove the 6 from both sides, and get 1/4.
14/456 false Remove the 4s. 14/456 is not equal to 1/56.
1234/4329 false Remove the 2s, 3s, and 4s. 1234/4329 is not equal to 1/9.
515/25 false Remove the first 5 from each side. 15/2 is not equal to 515/25.
This is code-golf, so shortest code in bytes wins!