Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
22
Task/Egyptian-division/Mathematica/egyptian-division.math
Normal file
22
Task/Egyptian-division/Mathematica/egyptian-division.math
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
ClearAll[EgyptianDivide]
|
||||
EgyptianDivide[dividend_, divisor_] := Module[{table, i, answer, accumulator},
|
||||
table = {{1, divisor}};
|
||||
i = 1;
|
||||
While[Last[Last[table]] < dividend,
|
||||
AppendTo[table, 2^i {1, divisor}];
|
||||
i++
|
||||
];
|
||||
table //= Most;
|
||||
answer = 0;
|
||||
accumulator = 0;
|
||||
Do[
|
||||
If[accumulator + t[[2]] <= dividend,
|
||||
accumulator += t[[2]];
|
||||
answer += t[[1]]
|
||||
]
|
||||
,
|
||||
{t, Reverse@table}
|
||||
];
|
||||
{answer, dividend - accumulator}
|
||||
]
|
||||
EgyptianDivide[580, 34]
|
||||
Loading…
Add table
Add a link
Reference in a new issue