Egyptian division: Difference between revisions

adding lambdatalk
(adding lambdatalk)
Line 1,907:
580 divided by 34 is 17 with remainder 2
</pre>
 
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
 
{def doublings
{def doublings.loop
{lambda {:a :c}
{if {> {A.get 1 {A.last :c}} :a}
then {A.sublast! :c}
else {doublings.loop
:a
{A.addlast! {A.new {* 2 {A.get 0 {A.last :c}}}
{* 2 {A.get 1 {A.last :c}}}} :c}} }}}
{lambda {:a :b}
{doublings.loop :a {A.new {A.new 1 :b}}} }}
-> doublings
 
divide
-> {def divide
{def divide.loop
{lambda {:a :b :table :last :i}
{if {< {+ :last {A.get 1 {A.get :i :table}}} :a}
then {A.new {+ {* {A.get 0 {A.last :table}} 1} 1}
{- :a {+ :last {A.get 1 {A.get :i :table}}}}}
else {divide.loop :a :b :table :last {- :i 1} }}}}
{lambda {:a :b}
{let { {:a :a} {:b :b}
{:table {doublings :a :b}}
} {divide.loop :a :b :table
{A.get 1 {A.last :table}}
{- {A.length :table} 1} }}}}
 
{divide 580 34}
-> [17,2] // 580 = 17*34+2
{divide 100 3}
-> [33,1] // 100 = 3*33+1
{divide 7 2}
-> [3,1] // 7 = 2*3+1
 
</syntaxhighlight>
 
=={{header|Lua}}==
99

edits