38
1
Context
If a0
and b0
are two decimal numbers, with a
and b
representing the decimal expansion of all digits but the least significant one, then we know that
$$\frac{a0}{b0} = \frac{a{\not\mathrel0}}{b{\not\mathrel0}}= \frac{a}{b}$$
Phony fraction
A phony fraction is a fraction where the numerator and denominator share a digit (other than a 0 in the units place) and, when that digit is erased from both numerator and denominator, the simplified fraction happens to be equal to the original one.
Example
\$16/64\$ is a phony fraction because if we remove the \$6\$, we get \$16/64 = 1{\not\mathrel6}/{\not\mathrel6}4 = 1/4\$, even though the intermediate step of removing both sixes is wrong.
Task
Given a fraction, determine if it is phony or not.
Note
Notice that 10/20
is not a phony fraction. Even though 10/20 = 1/2
, the simplification here was mathematically sound, you divided numerator and denominator by 10
, which amounts to "crossing out a 0 on the num. and the den.".
On the other hand, 102/204 = 12/24
is a phony fraction, because supposedly we can't cross out the 0s.
Because of this, when the input fraction is such that crossing out 0 gives an equivalent fraction to the original, the behaviour is unspecified.
Input
The fraction we care about, with positive numerator and denominator, in any sensible format. Some examples of sensible formats include:
- a list
[num, den]
or[den, num]
- a string of the form
"num/den"
- the exact fraction, if your language supports it
- two different arguments to your function
Assume both are greater than 9. You can also assume the denominator is strictly larger than the numerator.
Output
A Truthy value if the fraction is phony and a Falsy value if it is not.
Test cases
(Please keep an eye out for the comments, as some people have really nice test case suggestions! I'll edit them in, but sometimes I don't do it immediately.)
Truthy
69/690 = 9/90
99/396 = 9/36
394/985 = 34/85
176/275 = 16/25
85/850 = 5/50
59/295 = 5/25
76/760 = 6/60
253/550 = 23/50
52/520 = 2/20
796/995 = 76/95
199/796 = 19/76
88/583 = 8/53
306/765 = 30/75
193/965 = 13/65
62/620 = 2/20
363/561 = 33/51
396/891 = 36/81
275/770 = 25/70
591/985 = 51/85
165/264 = 15/24
176/671 = 16/61
385/781 = 35/71
88/484 = 8/44
298/596 = 28/56
737/938 = 77/98
495/594 = 45/54
693/990 = 63/90
363/462 = 33/42
197/985 = 17/85
462/660 = 42/60
154/451 = 14/41
176/374 = 16/34
297/990 = 27/90
187/682 = 17/62
195/975 = 15/75
176/473 = 16/43
77/671 = 7/61
1130/4181 = 130/481
Falsy
478/674
333/531
309/461
162/882
122/763
536/616
132/570
397/509
579/689
809/912
160/387
190/388
117/980
245/246
54/991
749/892
70/311
344/735
584/790
123/809
227/913
107/295
225/325
345/614
506/994
161/323
530/994
589/863
171/480
74/89
251/732
55/80
439/864
278/293
514/838
47/771
378/627
561/671
43/946
1025/1312
You can check this reference implementation that I used to generate some phony fractions by brute-force.
This is code-golf so shortest submission in bytes, wins! If you liked this challenge, consider upvoting it... And happy golfing!
2Suggested falsy test case:
561/671
(which is the same as 51/61, but 2 different digits are removed). – Arnauld – 2020-02-19T09:44:41.983Suggested falsy test case:
43/946
(testing that $n'\times d/n$ is an integer for some updated numerator $n'$ is enough for all existing falsy test cases) – Arnauld – 2020-02-19T09:48:44.4002Suggested truthy test case:
1130/4181 = 130/481
(both the numerator and denominator contain the digit to remove twice). – Kevin Cruijssen – 2020-02-19T09:48:54.1972Suggested falsy test case:
1025/1312
(removing all 1's works, but that's invalid) – Arnauld – 2020-02-19T10:15:55.107Added all suggested test cases above this comment :) – RGS – 2020-02-19T10:23:08.473
Is it possible to have a phony fraction where you remove the first digit of one of the integers and the second digit is a zero? – Neil – 2020-02-19T11:25:11.610
@Neil "A phony fraction is a fraction where the numerator and denominator share a digit (other than a 0)", so I assume we only have to support the digits
[1,9]
if I understand correctly. – Kevin Cruijssen – 2020-02-19T11:47:47.9973
Possible duplicate of How NOT to reduce fractions
– pppery – 2020-02-19T14:06:48.3571Can you clarify the
other than a 0
rule? What's the expected output for input10/20
? – Grimmy – 2020-02-19T14:28:53.1072The linked challenge is about removing a common substring. This is about removing a common digit. I think the difference is significant enough to make it non-dupe – Luis Mendo – 2020-02-19T15:26:32.943
May we accept lists of digits? – Jonathan Allan – 2020-02-19T15:50:16.463
1Is
11/11
a phony fraction? – Jonathan Frech – 2020-02-19T18:10:32.207@JonathanFrech yes it is. Just not a very interesting one, I would say. – RGS – 2020-02-19T19:44:24.063
@JonathanAllan yes, you may accept lists of digits. – RGS – 2020-02-19T19:44:50.370
@Grimmy for 10/20, the expected output is Falsy. Even though
10/20 = 1/2
, the simplification here was mathematically sound, you divided numerator and denominator by10
, which amounts to "crossing out a 0 on the num. and the den.". The point here is to find fractions where (incorrectly) crossing out a digit gives a correct simplification :) – RGS – 2020-02-19T19:46:27.7501What about
103 / 206 = 13 / 26
? Is it “mathematically sound” to remove the 0 here? (Note that if10/20
is falsy but103/206
is truthy, all current answers are invalid). – Grimmy – 2020-02-19T20:18:52.357@Grimmy it wouldn't make for a mathematically sound simplification in the sense that I meant... So
102/204
should be phony... But that will break all answers... So I guess I'll just stick to the "ignore the 0s" because sometimes crossing a 0 gives a good simplification and sometimes it gives a bad one. What would you say? – RGS – 2020-02-19T20:38:02.940I agree that either
0
should be supported and10/20 = 1/2
and103/206 = 13/26
should both output truthy, or0
should not be supported, in which case both those test cases return falsey. Otherwise all current answers are incorrect, and it would also make it mostly about that0
edge case, transforming it into a do X without Y challenge, which are usually things to avoid when writing a challenge. I think it would be best to only support[1,9]
, and leave supporting the0
unspecified (so whether you do or don't support it is up to you). – Kevin Cruijssen – 2020-02-19T20:47:05.137Currently, only SQL, C, and Jelly 17 output falsy for 103/206 and 10/20. 05AB1E could easily go either way (same byte-count), and the 7 other answers output truthy. – Grimmy – 2020-02-19T20:54:02.463
@KevinCruijssen I don't think I understand what "only support [1-9] and leave supporting 0 unspecified [...]" means. Does it mean that, when checking if a fraction is phony or not, we only try to erase digits 1 through 9? – RGS – 2020-02-19T21:00:15.990
1@RGS Kinda. I meant it in a way that answers could only check to erase digits
[1,9]
OR[0,9]
, and both would be valid submissions. As long as it works for all inputs that require erasing a digit in the range[1,9]
it's fine. Whether you're program also tries to remove0
s or not is up to the people who answer themselves to decide, and is left unspecified for the challenge. This happens more often in challenges, where they say something along the lines of "You can assume X. If Y occurs/is input, feel free to do anything (i.e. output truthy or falsey, give an error, output nothing, etc.)" – Kevin Cruijssen – 2020-02-20T07:49:06.560@KevinCruijssen thanks for your feedback once more. The "Task" and "Note" sections have been slightly edited to make it clearer. If you have the time, take a look and let me know if you think it is clearer now. – RGS – 2020-02-20T09:54:10.167