Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
46
Task/Arithmetic-Rational/Lingo/arithmetic-rational-1.lingo
Normal file
46
Task/Arithmetic-Rational/Lingo/arithmetic-rational-1.lingo
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
-- parent script "Frac"
|
||||
property num
|
||||
property denom
|
||||
|
||||
----------------------------------------
|
||||
-- @constructor
|
||||
-- @param {integer} numerator
|
||||
-- @param {integer} [denominator=1]
|
||||
----------------------------------------
|
||||
on new (me, numerator, denominator)
|
||||
if voidP(denominator) then denominator = 1
|
||||
if denominator=0 then return VOID -- rule out division by zero
|
||||
g = me._gcd(numerator, denominator)
|
||||
if g<>0 then
|
||||
numerator = numerator/g
|
||||
denominator = denominator/g
|
||||
else
|
||||
numerator = 0
|
||||
denominator = 1
|
||||
end if
|
||||
if denominator<0 then
|
||||
numerator = -numerator
|
||||
denominator = -denominator
|
||||
end if
|
||||
me.num = numerator
|
||||
me.denom = denominator
|
||||
return me
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- Returns string representation "<num>/<denom>"
|
||||
-- @return {string}
|
||||
----------------------------------------
|
||||
on toString (me)
|
||||
return me.num&"/"&me.denom
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
--
|
||||
----------------------------------------
|
||||
on _gcd (me, a, b)
|
||||
if a = 0 then return b
|
||||
if b = 0 then return a
|
||||
if a > b then return me._gcd(b, a mod b)
|
||||
return me._gcd(a, b mod a)
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue