13
Reducing fractions the wrong way
In this code-golf challenge you have to find fractions that can be reduced the wrong way but still end up in the same number.
Note: reducing fractions the wrong way does here have an exact definition, see details.
Example:
64/16 = 64/16=4/1 = 4
Of course you cannot just strike both 6es but here you still end up with the correct value. In this challenge you have to find examples like this.
Details
You have to write a function/program that accepts one positive integer n
as input and outputs/returns a list/array of the fractions in format
numerator1,denominator1,numerator2,denominator2,...
The program has to find out for each fraction a/b
with a+b=n
and a,b>0
whether it can be reduced the wrong way. (It does not matter whether if it can be reduced in the conventional way or whether there are many possibilities of reductions, it just has to be possible to reduce it the wrong way in at least one way.)
Definition of the wrong way: A fraction can be reduced the wrong way if and only if the same sequence of successive digits appears in a and b and if the value of the fraction stays the same if you remove the substring.
Example: 1536/353 can be 'reduced' to 16/3 but those two values are not equal so you cannot reduce this fraction the wrong way.
Note that this definition of reducing the wrong way can also include fractions that are reduced the right way: 110/10 = 11/1
is within the definition of reducing the wrong way even though it is a valid step.
Scoring
The least number of bytes wins. You can write a function or program that accepts an integer and returns an array or a program that uses stdin/stdout or you can consider n saved in a variable and in the end of the program the list must be saved in an other variable.
Test cases
Please include following testcases (Tell me which ones I should add, I have no idea how many of those fractions there are / how many examples to expect)
n=80 (64/16 should be in this list)
n=147 (98/49 should be in this list)
n=500 (294/196 should be in this list) WRONG since 294+196 != 500 Thanks Falko
I'm guessing
a
andb
are constrained to positive integers? – Ingo Bürk – 2014-09-14T12:01:46.363Or if we had two negative numbers, crossing out the '-' would be another great way to reduce the right and wrong way. – feersum – 2014-09-14T12:05:25.567
3Consider defining a term for "the wrong way", such as "goofy" or "freaky". I think the post would be easier to understand, because readers immediately grok that there must be a definition for the term. – Michael Easter – 2014-09-14T12:06:42.143
3What if there are multiple ways to reduce a fraction and only some of them are wrong?
1010/10 = 101/1 && 1010/10 /= 110/1
– John Dvorak – 2014-09-14T12:07:04.8671
Variant of https://projecteuler.net/problem=33 ?
– user80551 – 2014-09-14T12:57:56.083@ JanDvorak you just have to determine whether a fraction can be reduced the wrong way. @ MichaelEaster: Ok I will think abou this. (Thats why I wrote it in italic but perhaps that is not enough.) @ user80551: I did not remember this problem, I just got this example from my algebra teacher=) – flawr – 2014-09-14T13:52:28.887
1Your second test case (
n=147
) is incorrect:49/89 != 4/8
. – Beta Decay – 2014-09-14T16:42:54.9671If there's more than one way to reduce a fraction, may we include it multiple times in the result set? – John Dvorak – 2014-09-14T17:58:26.460
1does it matter if the digits are not in the same order in the numerator and denominator, or if the digits aren't close together? you used the word 'sequence' when defining "reducing the wrong way" which implies that it does matter, but to me it doesn;t seem to be less "reducing the wrong way". – proud haskeller – 2014-09-14T19:20:20.033
@proudhaskeller If in doubt, follow the definition rather than intuition. That's what definitions are for. I have followed the definition in my answer. – John Dvorak – 2014-09-14T19:23:40.653
@proudhaskeller You could of cours make different definitions but you guessed correctly: according to mine the order matters! – flawr – 2014-09-14T20:07:26.317
1Am I wrong or is your third test case invalid, since 500!=294+196? – Falko – 2014-09-14T21:47:50.830
@Wrzlprmft Yes. @ Falko: you aren't wrowng, this is a mistake. (I think Beta Decay added this one). – flawr – 2014-09-15T13:07:44.443
@flawr: You seem to have missed Jan Dvorak’s question regarding your challenge.
– Wrzlprmft – 2014-09-15T14:12:03.007