Egyptian division: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Tailspin}}: update to stricter typing)
m (syntax highlighting fixup automation)
Line 319:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F egyptian_divmod(dividend, divisor)
assert(divisor != 0)
V (pwrs, dbls) = ([1], [divisor])
Line 336:
V (i, j) = (580, 34)
V (d, m) = egyptian_divmod(i, j)
print(‘#. divided by #. using the Egyption method is #. remainder #.’.format(i, j, d, m))</langsyntaxhighlight>
 
{{out}}
Line 344:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">TYPE Answer=[CARD result,reminder]
 
PROC EgyptianDivision(CARD dividend,divisor Answer POINTER res)
Line 382:
EgyptianDivision(dividend,divisor,res)
PrintF("%U / %U = %U reminder %U",dividend,divisor,res.result,res.reminder)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Egyptian_division.png Screenshot from Atari 8-bit computer]
Line 391:
=={{header|Ada}}==
 
<syntaxhighlight lang="ada">
<lang Ada>
with Ada.Text_IO;
 
Line 422:
Ada.Text_IO.put_line ("Quotient="&q'Img & " Remainder="&r'img);
end Egyptian_Division;
</syntaxhighlight>
</lang>
{{Out}}
<pre>Quotient= 17 Remainder= 2</pre>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN
# performs Egyptian division of dividend by divisor, setting quotient and remainder #
# this uses 32 bit numbers, so a table of 32 powers of 2 should be sufficient #
Line 464:
egyptian division( 580, 34, quotient, remainder );
print( ( "580 divided by 34 is: ", whole( quotient, 0 ), " remainder: ", whole( remainder, 0 ), newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 473:
 
Unfold to derive successively doubled rows, fold to sum quotient and derive remainder
<langsyntaxhighlight AppleScriptlang="applescript">-- EGYPTIAN DIVISION ------------------------------------
 
-- eqyptianQuotRem :: Int -> Int -> (Int, Int)
Line 565:
end tell
return xs
end unfoldr</langsyntaxhighlight>
{{Out}}
<pre>{17, 2}</pre>
Line 571:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">egyptianDiv: function [dividend, divisor][
ensure -> and? dividend >= 0
divisor > 0
Line 607:
[quotient, remainder]: egyptianDiv dividend divisor
 
print [dividend "divided by" divisor "is" quotient "with remainder" remainder]</langsyntaxhighlight>
 
{{out}}
Line 614:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">divident := 580
divisor := 34
 
Line 635:
obj.pop() ; remove current row
}
MsgBox % divident "/" divisor " = " answer ( divident-accumulator > 0 ? " r" divident-accumulator : "")</langsyntaxhighlight>
Outputs:<pre>580/34 = 17 r2</pre>
 
=={{header|BaCon}}==
<syntaxhighlight lang="c">
<lang c>
 
'---Ported from the c code example to BaCon by bigbass
Line 705:
 
 
</syntaxhighlight>
</lang>
 
=={{header|C}}==
<syntaxhighlight lang="c">
<lang c>
#include <stdio.h>
#include <stdlib.h>
Line 757:
go(580, 32);
}
</syntaxhighlight>
</lang>
 
=={{header|C sharp|C#}}==
<langsyntaxhighlight lang="csharp">
using System;
using System.Collections;
Line 914:
}
}
</syntaxhighlight>
</lang>
{{out| Program Input and Output : Instead of bold and strikeout text format, numbers are represented in different color}}
<pre>
Line 950:
=={{header|C++}}==
{{trans|C}}
<langsyntaxhighlight lang="cpp">#include <cassert>
#include <iostream>
 
Line 1,007:
 
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>580 / 34 = 17 remainder 2</pre>
Line 1,013:
=={{header|Common Lisp}}==
 
<langsyntaxhighlight lang="lisp">
(defun egyptian-division (dividend divisor)
(let* ((doublings (reverse (loop for n = divisor then (* 2 n)
Line 1,030:
do (incf answer p)
(incf accumulator d))))
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,040:
 
=={{header|D}}==
<syntaxhighlight lang="d">
<lang D>
import std.stdio;
 
Line 1,099:
assert(remainder == 2);
}
</syntaxhighlight>
</lang>
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
Line 1,105:
{{libheader| System.Console}}Thanks for JensBorrisholt [https://github.com/JensBorrisholt/DelphiConsole].
{{Trans|C#}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Egyptian_division;
 
Line 1,254:
Console.Write('Press any key to continue . . . ');
Console.ReadKey(true);
end.</langsyntaxhighlight>
{{out}}<pre>
 
Line 1,285:
Press any key to continue . . .</pre>
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">-module(egypt).
 
-export([ediv/2]).
Line 1,301:
accumulate(N, [T|Ts], [D|Ds], Q, C) when (C + D) =< N -> accumulate(N, Ts, Ds, Q+T, C+D);
accumulate(N, [_|Ts], [_|Ds], Q, C) -> accumulate(N, Ts, Ds, Q, C).
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,309:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">// A function to perform Egyptian Division: Nigel Galloway August 11th., 2017
let egyptianDivision N G =
let rec fn n g = seq{yield (n,g); yield! fn (n+n) (g+g)}
Seq.foldBack (fun (n,i) (g,e)->if (i<=g) then ((g-i),(e+n)) else (g,e)) (fn 1 G |> Seq.takeWhile(fun (_,g)->g<=N)) (N,0)
</syntaxhighlight>
</lang>
Which may be used:
<langsyntaxhighlight lang="fsharp">
let (n,g) = egyptianDivision 580 34
printfn "580 divided by 34 is %d remainder %d" g n
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,326:
=={{header|Factor}}==
{{works with|Factor|0.98}}
<langsyntaxhighlight lang="factor">USING: assocs combinators formatting kernel make math sequences ;
IN: rosetta-code.egyptian-division
 
Line 1,344:
} 2cleave ;
 
580 34 ediv "580 divided by 34 is %d remainder %d\n" printf</langsyntaxhighlight>
{{out}}
<pre>
Line 1,351:
 
=={{header|Forth}}==
<syntaxhighlight lang="forth">
<lang FORTH>
variable tab-end
 
Line 1,375:
: .egypt ( m n -- )
cr 2dup swap . ." divided by " . ." is " e/mod swap . ." remainder " . ;
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,383:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' version 09-08-2017
' compile with: fbc -s console
 
Line 1,421:
Print : Print "hit any key to end program"
Sleep
End</langsyntaxhighlight>
{{out}}
<pre>580 divided by 34 using Egytian division returns 17 mod(ulus) 2</pre>
Line 1,427:
=={{header|Go}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 1,469:
quotient, remainder := egyptianDivide(dividend, divisor)
fmt.Println(dividend, "divided by", divisor, "is", quotient, "with remainder", remainder)
}</langsyntaxhighlight>
 
{{out}}
Line 1,478:
=={{header|Groovy}}==
{{trans|Java}}
<langsyntaxhighlight lang="groovy">class EgyptianDivision {
/**
* Runs the method and divides 580 by 34
Line 1,521:
println(String.format("%d, remainder %d", answer, dividend - accumulator))
}
}</langsyntaxhighlight>
{{out}}
<pre>17, remainder 2</pre>
Line 1,527:
=={{header|Haskell}}==
Deriving division from (+) and (-) by unfolding from a seed pair (1, divisor) up to a series of successively doubling pairs, and then refolding that series of 'two column rows' back down to a (quotient, remainder) pair, using (0, dividend) as the initial accumulator value. In other words, taking the divisor as a unit, and deriving the binary composition of the dividend in terms of that unit.
<langsyntaxhighlight Haskelllang="haskell">import Data.List (unfoldr)
 
egyptianQuotRem :: Integer -> Integer -> (Integer, Integer)
Line 1,540:
 
main :: IO ()
main = print $ egyptianQuotRem 580 34</langsyntaxhighlight>
{{Out}}
<pre>(17,2)</pre>
Line 1,546:
We can make the process of calculation more visible by adding a trace layer:
 
<langsyntaxhighlight Haskelllang="haskell">import Data.List (unfoldr)
import Debug.Trace (trace)
 
Line 1,577:
 
main :: IO ()
main = print $ egyptianQuotRem 580 34</langsyntaxhighlight>
{{Out}}
<pre>Number pair unfolded to series of doubling rows:
Line 1,591:
Another approach, using lazy lists and foldr:
 
<langsyntaxhighlight lang="haskell">doublings = iterate ((+) >>= id)
 
powers = doublings 1
Line 1,602:
 
main :: IO ()
main = print $ egy 580 34</langsyntaxhighlight>
{{Out}}
<pre>17</pre>
Line 1,610:
Implementation:
 
<langsyntaxhighlight Jlang="j">doublings=:_1 }. (+:@]^:(> {:)^:a: (,~ 1:))
ansacc=: 1 }. (] + [ * {.@[ >: {:@:+)/@([,.doublings)
egydiv=: (0,[)+1 _1*ansacc</langsyntaxhighlight>
 
Task example:
 
<langsyntaxhighlight Jlang="j"> 580 doublings 34
1 34
2 68
Line 1,625:
17 578
580 egydiv 34
17 2</langsyntaxhighlight>
 
Notes:
Line 1,634:
 
=={{header|Java}}==
<syntaxhighlight lang="java">
<lang Java>
import java.util.ArrayList;
import java.util.List;
Line 1,687:
}
 
</syntaxhighlight>
</lang>
{{Out}}
<pre>17, remainder 2</pre>
Line 1,693:
=={{header|JavaScript}}==
===ES6===
<langsyntaxhighlight JavaScriptlang="javascript">(() => {
'use strict';
 
Line 1,781:
// MAIN ---
return main();
})();</langsyntaxhighlight>
{{Out}}
<pre>[17,2]</pre>
Line 1,787:
=={{header|Julia}}==
{{works with|Julia|0.6}}
<langsyntaxhighlight lang="julia">function egyptiandivision(dividend::Int, divisor::Int)
N = 64
powers = Vector{Int}(N)
Line 1,819:
@test egyptiandivision(x, y) == divrem(x, y)
end
end</langsyntaxhighlight>
 
{{out}}
Line 1,827:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.4
 
data class DivMod(val quotient: Int, val remainder: Int)
Line 1,860:
val (quotient, remainder) = egyptianDivide(dividend, divisor)
println("$dividend divided by $divisor is $quotient with remainder $remainder")
}</langsyntaxhighlight>
 
{{out}}
Line 1,869:
=={{header|Lua}}==
{{trans|Python}}
<langsyntaxhighlight lang="lua">function egyptian_divmod(dividend,divisor)
local pwrs, dbls = {1}, {divisor}
while dbls[#dbls] <= dividend do
Line 1,889:
local i, j = 580, 34
local d, m = egyptian_divmod(i, j)
print(i.." divided by "..j.." using the Egyptian method is "..d.." remainder "..m)</langsyntaxhighlight>
{{out}}
<pre>580 divided by 34 using the Egyptian method is 17 remainder 2</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">ClearAll[EgyptianDivide]
EgyptianDivide[dividend_, divisor_] := Module[{table, i, answer, accumulator},
table = {{1, divisor}};
Line 1,915:
{answer, dividend - accumulator}
]
EgyptianDivide[580, 34]</langsyntaxhighlight>
{{out}}
<pre>{17, 2}</pre>
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE EgyptianDivision;
FROM FormatString IMPORT FormatString;
FROM Terminal IMPORT WriteString,ReadChar;
Line 1,962:
 
ReadChar
END EgyptianDivision.</langsyntaxhighlight>
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import strformat
 
func egyptianDivision(dividend, divisor: int): tuple[quotient, remainder: int] =
Line 1,995:
let divisor = 34
var (quotient, remainder) = egyptianDivision(dividend, divisor)
echo fmt"{dividend} divided by {divisor} is {quotient} with remainder {remainder}"</langsyntaxhighlight>
{{out}}
<pre>
Line 2,003:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="perl">sub egyptian_divmod {
my($dividend, $divisor) = @_;
die "Invalid divisor" if $divisor <= 0;
Line 2,022:
my($n,$d) = @$_;
printf "Egyption divmod %s %% %s = %s remainder %s\n", $n, $d, egyptian_divmod( $n, $d )
}</langsyntaxhighlight>
{{out}}
<pre>Egyption divmod 580 % 34 = 17 remainder 2
Line 2,029:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">egyptian_division</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">dividend</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">divisor</span><span style="color: #0000FF;">)</span>
Line 2,051:
<span style="color: #000000;">egyptian_division</span><span style="color: #0000FF;">(</span><span style="color: #000000;">580</span><span style="color: #0000FF;">,</span><span style="color: #000000;">34</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,058:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(seed (in "/dev/urandom" (rd 8)))
 
(de divmod (Dend Disor)
Line 2,085:
(let (A (rand 1 1000) B (rand 1 A))
(test (divmod A B) (egyptian A B)) ) )
(println (egyptian 580 34))</langsyntaxhighlight>
 
{{out}}
Line 2,092:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">egyptian_divide(Dividend, Divisor, Quotient, Remainder):-
powers2_multiples(Dividend, [1], Powers, [Divisor], Multiples),
accumulate(Dividend, Powers, Multiples, 0, Quotient, 0, Acc),
Line 2,123:
 
main:-
test_egyptian_divide(580, 34).</langsyntaxhighlight>
 
{{out}}
Line 2,132:
=={{header|Python}}==
===Idiomatic=== <!-- When compared to a Haskell translation -->
<langsyntaxhighlight lang="python">from itertools import product
 
def egyptian_divmod(dividend, divisor):
Line 2,154:
i, j = 580, 34
print(f'{i} divided by {j} using the Egyption method is %i remainder %i'
% egyptian_divmod(i, j))</langsyntaxhighlight>
 
'''Sample output'''
Line 2,168:
 
{{Trans|Haskell}}
<langsyntaxhighlight lang="python">'''Quotient and remainder of division by the Rhind papyrus method.'''
 
from functools import reduce
Line 2,251:
# MAIN ----------------------------------------------------
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>(17, 2)</pre>
Line 2,257:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ dup 0 = if
[ $ "Cannot divide by zero."
fail ]
Line 2,296:
say "." ] is task ( n n --> )
 
580 34 task</langsyntaxhighlight>
 
{{out}}
Line 2,304:
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">Egyptian_division <- function(num, den){
pow2 = 0
row = 1
Line 2,340:
Egyptian_division(580, 34)
Egyptian_division(300, 2)
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,349:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">#lang racket
 
(define (quotient/remainder-egyptian dividend divisor (trace? #f))
Line 2,389:
 
(module+ main
(quotient/remainder-egyptian 580 34 #t))</langsyntaxhighlight>
 
{{out}}
Line 2,413:
===Normal version===
Only works with positive real numbers, not negative or complex.
<syntaxhighlight lang="raku" perl6line>sub egyptian-divmod (Real $dividend is copy where * >= 0, Real $divisor where * > 0) {
my $accumulator = 0;
([1, $divisor], { [.[0] + .[0], .[1] + .[1]] } … ^ *.[1] > $dividend)
Line 2,424:
printf "%s divmod %s = %s remainder %s\n",
$n, $d, |egyptian-divmod( $n, $d )
}</langsyntaxhighlight>
{{out}}
<pre>580 divmod 34 = 17 remainder 2
Line 2,436:
 
This is intended to be humorous and should not be regarded as good (or even sane) programming practice. That being said, 𓂽 & 𓂻 really are the ancient Egyptian symbols for addition and subtraction, and the Egyptian number notation is as accurate as possible. Everything else owes more to whimsy than rigor.
<syntaxhighlight lang="raku" perl6line>my (\𓄤, \𓄊, \𓎆, \𓄰) = (0, 1, 10, 10e7);
sub infix:<𓂽> { $^𓃠 + $^𓃟 }
sub infix:<𓂻> { $^𓃲 - $^𓆊 }
Line 2,458:
printf "%s divmod %s = %s remainder %s =OR= %s 𓅓 %s = %s remainder %s\n",
𓃾, 𓆙, |(𓃾 𓅓 𓆙), (𓃾, 𓆙, |(𓃾 𓅓 𓆙))».&𓁶;
}</langsyntaxhighlight>
 
{{out}}
Line 2,467:
=={{header|REXX}}==
Only addition and subtraction is used in this version of the Egyptian division method.
<langsyntaxhighlight lang="rexx">/*REXX program performs division on positive integers using the Egyptian division method*/
numeric digits 1000 /*support gihugic numbers & be gung-ho.*/
parse arg n d . /*obtain optional arguments from the CL*/
Line 2,490:
ans= ans + pow.s /*calculate the (newer) running answer.*/
end /*s*/
return ans num-acc /*return the answer and the remainder. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 2,501:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 2,531:
see string(dividend) + " divided by " + string(divisor) + " using egytian division" + nl
see " returns " + string(answer) + " mod(ulus) " + string(dividend-accumulator)
</syntaxhighlight>
</lang>
Output:
<pre>
Line 2,539:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">def egyptian_divmod(dividend, divisor)
table = [[1, divisor]]
table << table.last.map{|e| e*2} while table.last.first * 2 <= dividend
Line 2,553:
 
puts "Quotient = %s Remainder = %s" % egyptian_divmod(580, 34)
</syntaxhighlight>
</lang>
{{out}}
<pre>Quotient = 17 Remainder = 2
Line 2,559:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">fn egyptian_divide(dividend: u32, divisor: u32) -> (u32, u32) {
let dividend = dividend as u64;
let divisor = divisor as u64;
Line 2,584:
let (div, rem) = egyptian_divide(580, 34);
println!("580 divided by 34 is {} remainder {}", div, rem);
}</langsyntaxhighlight>
{{out}}
<pre>580 divided by 34 is 17 remainder 2</pre>
Line 2,590:
=={{header|Scala}}==
{{Out}}Best seen running in your browser either by [https://scalafiddle.io/sf/sYSdo9u/0 ScalaFiddle (ES aka JavaScript, non JVM)] or [https://scastie.scala-lang.org/3yry7OurSQS72xNMK0GMEg Scastie (remote JVM)].
<langsyntaxhighlight Scalalang="scala">object EgyptianDivision extends App {
 
private def divide(dividend: Int, divisor: Int): Unit = {
Line 2,618:
divide(580, 34)
 
}</langsyntaxhighlight>
 
=={{header|Sidef}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">func egyptian_divmod(dividend, divisor) {
var table = [[1, divisor]]
table << table[-1].map{|e| 2*e } while (2*table[-1][0] <= dividend)
Line 2,636:
}
 
say ("Quotient = %s Remainder = %s" % egyptian_divmod(580, 34))</langsyntaxhighlight>
{{out}}
<pre>
Line 2,644:
=={{header|Swift}}==
 
<langsyntaxhighlight lang="swift">extension BinaryInteger {
@inlinable
public func egyptianDivide(by divisor: Self) -> (quo: Self, rem: Self) {
Line 2,677:
 
print("\(dividend) divided by \(divisor) = \(quo) rem \(rem)")
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,684:
 
=={{header|Tailspin}}==
<langsyntaxhighlight lang="tailspin">
templates egyptianDivision
def dividend: $(1);
Line 2,702:
[580"1", 34"1"] -> egyptianDivision -> 'Quotient: $.answer; Remainder: $: 580"1" - $.accumulator;' -> !OUT::write
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,708:
 
=={{header|VBA}}==
<langsyntaxhighlight lang="vb">Option Explicit
 
Private Type MyTable
Line 2,763:
Divise.Quotient = a.answer
Divise.Remainder = Deg.Dividend - a.accumulator
End Function</langsyntaxhighlight>
{{out}}
<pre>Quotient = 17 Remainder = 2</pre>
Line 2,769:
=={{header|Visual Basic .NET}}==
{{trans|D}}
<langsyntaxhighlight lang="vbnet">Module Module1
 
Function EgyptianDivision(dividend As ULong, divisor As ULong, ByRef remainder As ULong) As ULong
Line 2,816:
End Sub
 
End Module</langsyntaxhighlight>
{{out}}
<pre>580 / 34 = 17 rem 2</pre>
Line 2,822:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang="vlang">fn egyptian_divide(dividend int, divisor int) ?(int, int) {
 
if dividend < 0 || divisor <= 0 {
Line 2,861:
quotient, remainder := egyptian_divide(dividend, divisor)?
println("$dividend divided by $divisor is $quotient with remainder $remainder")
}</langsyntaxhighlight>
 
{{out}}
Line 2,870:
=={{header|Wren}}==
{{trans|Go}}
<langsyntaxhighlight lang="ecmascript">var egyptianDivide = Fn.new { |dividend, divisor|
if (dividend < 0 || divisor <= 0) Fiber.abort("Invalid argument(s).")
if (dividend < divisor) return [0, dividend]
Line 2,897:
var divisor = 34
var res = egyptianDivide.call(dividend, divisor)
System.print("%(dividend) ÷ %(divisor) = %(res[0]) with remainder %(res[1]).")</langsyntaxhighlight>
 
{{out}}
Line 2,905:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn egyptianDivmod(dividend,divisor){
table:=[0..].pump(List, 'wrap(n){ // (2^n,divisor*2^n)
r:=T( p:=(2).pow(n), s:=divisor*p); (s<=dividend) and r or Void.Stop });
Line 2,913:
}
return(accumulator,dividend);
}</langsyntaxhighlight>
<langsyntaxhighlight lang="zkl">foreach dividend,divisor in (T(T(580,34), T(580,17), T(578,34), T(7532795332300578,235117))){
println("%d %% %d = %s".fmt(dividend,divisor,egyptianDivmod(dividend,divisor)));
}</langsyntaxhighlight>
{{out}}
<pre>
10,327

edits