Jump to content

Least common multiple: Difference between revisions

Line 144:
=={{header|AppleScript}}==
 
<lang AppleScript>-- lcmLEAST ::COMMON Integral a => aMULTIPLE -> a -> a---------------------------------------------------
 
-- lcm :: Integral a => a -> a -> a
on lcm(x, y)
if x = 0 or y = 0 then
Line 154 ⟶ 156:
 
 
-- TEST ----------------------------------------------------------------------
-- TEST
on run
Line 162 ⟶ 164:
end run
 
-- GENERIC FUNCTIONS ---------------------------------------------------------
 
-- GENERAL FUNCTIONS
 
-- abs :: Num a => a -> a
Line 176 ⟶ 177:
-- gcd :: Integral a => a -> a -> a
on gcd(x, y)
script _gcd
on lambda|λ|(a, b)
if b = 0 then
a
else
lambda|λ|(b, a mod b)
end if
end lambda|λ|
end script
_gcdresult's lambda|λ|(abs(x), abs(y))
end gcd</lang>
 
{{Out}}
<lang AppleScript>36</lang>
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.