+ 7

[ASSIGNMENT] Safe Fractions for an inexperienced mathematician

Fraction 26/65 is a Safe Fraction, because trying to simplify it unxperiencied mathematician will just remove 6 (digit presented in numerator and denominator) and will get 2/5, which is exactly equal to 26/65 (both are equal to 0.4). For example, fraction 12/32 is not a safe fraction because 12/32 != 1/3. There are plenty intresting tasks that can be formulated around it! So, please, find some of them as well as clarification notes in my comment below...

18th May 2018, 1:46 AM
Nevfy
11 Answers
+ 4
= = = = = = = = = = This comment contains Tasks for the assignment. If you like the challenge, please, also like this comment to have it always at top. = = = = = = = = = = NOTES: 1. Only proper fractions (numerator < denominator) can be named safe. 2. Ignore trivial cases like 10/20 (both ends to zero). 3. See some notes in examples for TASK 3... TASKS: I offer for everybody to write a code solving 3 following tasks: TASK 1: For the input "a/b" your code should return True or False, checking if fraction a/b is Safe or not. Demonstration of such fact would be a great idea, but is not obligatory. Input: 26/65 Accepted output: True Prefered output: 26/65 = 2/5 Input: 12/32 Output: False TASK 2: For the input "/b" your code should return all Safe Fractions with this denominator or False if there is no any. Input: /65 Accepted output: 26/65 Prefered output: 26/65 = 2/5 Input: /32 Output: False TASK 3: For the input "a b" your code should return amount of Safe Fractions such that numerator has 'a' digits and denominator has 'b' digits. Input: 2 2 Output: 4 Comment: There are only 4 non-trivial (see NOTES) Safe Fractions such that numerator and denominator both has 2 digits. Input: 1 3 Output: 0 Comment: Trere is no any Safe Fractions with single digit numerator (nothing to cut off). Input: 3 2 Output: 0 Comment: Trere is no any Safe Fractions such that numerator is higher than denominator (see NOTES). (!!!) As soon as you have done these tasks, feel free to offer to everyone your own task around this topic!
18th May 2018, 1:48 AM
Nevfy
+ 17
Nevfy I tried something (dropLast(1) in line 23) .. and I forgot to delete it 😁 That's why it was a strange result for 12/32. Sorry 😉
20th May 2018, 7:55 PM
LukArToDo
LukArToDo - avatar
+ 11
Here's my try. Works properly for two-digits numbers. I will try to find an optimal solution for numbers larger than 2-digits (correctly and without memory limit exceed) https://code.sololearn.com/cO2cmrNgY4Wq/?ref=app
20th May 2018, 7:38 AM
LukArToDo
LukArToDo - avatar
+ 5
@Sebastian Keßler Are you serious? O_o It is marked as the best answer to be attached to the top, so any potential participant doesn't need to spend time looking for clarification details within the scope of comments. And I cannot put all this in a main body of challenge, because it is limited by 512 symbols. Moreover, as soon as I will conclude results of the challenge I will mark my other comment, which contains all accepted solutions, as the best one, because I don't offer any competition to be able to distinguish 'the best' solution within all solutions provided by participants. Check out, how it is done, for example, in my previous ones: https://www.sololearn.com/discuss/1262566/?ref=app https://www.sololearn.com/discuss/1254367/?ref=app https://www.sololearn.com/discuss/1250521/?ref=app https://www.sololearn.com/discuss/1239541/?ref=app etc... If you still think that it is a bad practice, I am open to hear any other ideas, how it can be done better?
20th May 2018, 2:00 AM
Nevfy
19th May 2018, 8:25 AM
VcC
VcC - avatar
+ 2
@VcC Generally works. Check out following notes to make it correct for all test cases: 1. Only proper fractions (numerator < denominator) can be named safe. 2. Ignore trivial cases like 10/20 (both ends to zero).
20th May 2018, 2:07 AM
Nevfy
+ 2
@LukArToDo 1. I don't understand why it tells that there's nothing to cut for 12/32, however there is common 2, so 12/32 -> 1/3, which are not equal to each other, so it is not a Safe Fraction. It works correctly for 12/23, returning False. 2. Your code is generally good and finds all Safe Fractions with 2 digits. Now you can try to extend it to any number of digits... ;-)
20th May 2018, 7:39 PM
Nevfy
+ 1
@VcC It should be False for: 1. (65,26), because numerator > denominator (Note 1). 2. (10,20), because both ends to 0 (Note 2).
20th May 2018, 8:16 PM
Nevfy
+ 1
@VcC 1. Fraction (10,20) still returns True. Should be False. 2. List of results for "als(998)" should not contain fractions (a,b), where a>b, because ther are not Safe by definition.
21st May 2018, 12:08 AM
Nevfy
0
Nevfy fixed
20th May 2018, 8:11 PM
VcC
VcC - avatar
0
Refixed
20th May 2018, 10:20 PM
VcC
VcC - avatar