+ 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!
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
+ 12
Interesting! Just wonder, is it always possible to break down a fraction into sum of unit fraction(s)?
+ 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. 👍
+ 7
+ 6
@blackcat1111 😄🙌
+ 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
+ 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.
+ 2
@Zephyr Koo Thanks!
+ 2
@Yash Thatte If it were that easy, it wouldn't be a challenge, would it? 😉