Greedy algorithm for Egyptian fractions: Difference between revisions
Content added Content deleted
m (→{{header|zkl}}: fiddle about) |
(Restored visibility of task description formulae - lost to most browsers in under-tested cosmetic edits of 02:50, 16 August 2016) |
||
Line 1: | Line 1: | ||
{{draft task}} |
{{draft task}} |
||
An |
An [[wp:Egyptian fraction|Egyptian fraction]] is the sum of distinct unit fractions such as: |
||
<math> \tfrac{1}{2} + \tfrac{1}{3} + \tfrac{1}{16} \,(= \tfrac{43}{48})</math>. |
|||
Each fraction in the expression has a numerator equal to |
Each fraction in the expression has a numerator equal to <math>1</math> and a denominator that is a positive integer, and all the denominators are distinct (i.e., no repetitions). |
||
Fibonacci's |
Fibonacci's [[wp:Greedy algorithm for Egyptian fractions|Greedy algorithm for Egyptian fractions]] expands the fraction <math> \tfrac{x}{y} </math> to be represented by repeatedly performing the replacement |
||
: <math> \frac{x}{y} = \frac{1}{\lceil y/x\rceil} + \frac{(-y)\!\!\!\!\mod x}{y\lceil y/x\rceil} </math> |
|||
⚫ | |||
⚫ | |||
<!-- |
<!-- |
||
This Rosetta Code task will be using the Fibonacci greedy algorithm for computing Egyptian fractions; however, if different method is used instead, please note which method is being employed. Having all the programming examples use the Fibonacci greedy algorithm will make for easier comparison and compatible results. |
This Rosetta Code task will be using the Fibonacci greedy algorithm for computing Egyptian fractions; however, if different method is used instead, please note which method is being employed. Having all the programming examples use the Fibonacci greedy algorithm will make for easier comparison and compatible results. |
||
--> |
--> |
||
[[wp:Fraction (mathematics)#Simple.2C_common.2C_or_vulgar_fractions|Proper and improper fractions]] |
[[wp:Fraction (mathematics)#Simple.2C_common.2C_or_vulgar_fractions|Proper and improper fractions]] must be able to be expressed. |
||
Proper fractions are of the form |
Proper fractions are of the form <math>\tfrac{a}{b}</math> where <math>a</math> and <math>b</math> are positive integers, such that <math>a < b</math>, and |
||
<br>improper fractions are of the form |
<br>improper fractions are of the form <math>\tfrac{a}{b}</math> where <math>a</math> and <math>b</math> are positive integers, such that <span style="font-family:times">''a'' ≥ ''b''</span>. |
||
(See the |
(See the [[#REXX|REXX programming example]] to view one method of expressing the whole number part of an improper fraction.) |
||
For improper fractions, the integer part of any improper fraction should be first isolated and shown preceding the Egyptian unit fractions, and be surrounded by square brackets |
For improper fractions, the integer part of any improper fraction should be first isolated and shown preceding the Egyptian unit fractions, and be surrounded by square brackets <tt>[''n'']</tt>. |
||
;Task requirements: |
;Task requirements: |
||
* |
* show the Egyptian fractions for: <math> \tfrac{43}{48} </math> and <math> \tfrac{5}{121} </math> and <math> \tfrac{2014}{59} </math> |
||
* |
* for all proper fractions, <math>\tfrac{a}{b}</math> where <math>a</math> and <math>b</math> are positive one-or two-digit (decimal) integers, find and show an Egyptian fraction that has: |
||
:* the largest number of terms, |
|||
:* the largest denominator. |
|||
* |
* for all one-, two-, and three-digit integers (extra credit), find and show (as above). |
||
;Also see: |
;Also see: |
||
* |
* Wolfram MathWorld™ entry: [http://mathworld.wolfram.com/EgyptianFraction.html Egyptian fraction] |
||
<br><br> |
<br><br> |
||