+ 2

[Challenge] Unit Fractions

Unit fractions are fractions with a numerator of 1. They were used by ancient Egyptians for their usefulness in Egyptian sums. Your task: Given any fraction, create a program that splits a fraction into a unit fraction. Example 1: User enters 2/7 Output: 1/4 + 1/28 Example 2: User enters 1/2 Output: 1/2 Example 3: User enters 3/179 Output: 1/60 + 1/10740 Good luck, and have fun!

5th Oct 2017, 11:05 AM
blackcat1111
blackcat1111 - avatar
10 Antworten
+ 6
Sorry for being late to the party! Here's my C# implementation ✌ I believe there's a better algorithm compared to mine right now and there's still room of improvement. Anyway thanks for the challenge and insights! ❤ https://code.sololearn.com/cWHR944dD1k0/?ref=app
9th Oct 2017, 5:27 AM
Zephyr Koo
Zephyr Koo - avatar
+ 12
Interesting! Just wonder, is it always possible to break down a fraction into sum of unit fraction(s)?
5th Oct 2017, 1:28 PM
Zephyr Koo
Zephyr Koo - avatar
+ 8
Wonderful insights! Thanks @blackcat1111 I'll study more about it. 😄 Glad to see some nice folks @ SoloLearn with strong Mathematical sense like you all. 👍
5th Oct 2017, 11:50 PM
Zephyr Koo
Zephyr Koo - avatar
5th Oct 2017, 1:20 PM
m abrate
m abrate - avatar
+ 6
@blackcat1111 😄🙌
9th Oct 2017, 12:40 PM
Zephyr Koo
Zephyr Koo - avatar
+ 3
@Zephyr Koo Glad you could make it! :) I don't know if it is a coincidence, but your algorithm works similarly to mine. Good job! I agree that it may not be the most efficient, but it is the only one that I can come up with. Here's my algorithm, if anybody wants to take a look at it. https://code.sololearn.com/ceZjV9s2sERY/?ref=app
9th Oct 2017, 10:52 AM
blackcat1111
blackcat1111 - avatar
+ 2
@Zephyr Koo Yes. Any positive rational fraction can be expressed as the sum of unit fractions. You can probably see why from this example: 2/3 = 1/2 + 1/6 Multiplying by 6 will give us: 4 = 3 + 1 We end up with a sum of positive integers. There are infinite such sums that can be written, and infinitely many ways which they can be divided (6 in this example), hence any positive rational fraction can be expressed as the sum of unit fractions.
5th Oct 2017, 10:50 PM
blackcat1111
blackcat1111 - avatar
+ 2
@Zephyr Koo Thanks!
6th Oct 2017, 12:20 AM
blackcat1111
blackcat1111 - avatar
+ 2
@Yash Thatte If it were that easy, it wouldn't be a challenge, would it? 😉
10th Oct 2017, 2:29 AM
blackcat1111
blackcat1111 - avatar