Egyptian division: Difference between revisions

add OCaml
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(add OCaml)
Line 1,999:
<pre>
580 divided by 34 is 17 with remainder 2
</pre>
 
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let egypt_div x y =
let rec table p d lst =
if d > x
then lst
else table (p + p) (d + d) ((p, d) :: lst)
in
let consider (q, a) (p, d) =
if a + d > x
then q, a
else q + p, a + d
in
List.fold_left consider (0, 0) (table 1 y [])</syntaxhighlight>
{{out}}
<pre>
# egypt_div 580 34 ;;
- : int * int = (17, 578)
</pre>
 
559

edits