Balanced ternary: Difference between revisions

m
(→‎{{header|11l}}: Static type variables and static methods are supported now)
Line 29:
{{trans|Python}}
 
<syntaxhighlight lang="11l">FT py_idiv(a, b)BalancedTernary
I a >= 0
R a I/ b
R (a - b + 1) I/ b
 
T BalancedTernary
:str2dig = [‘+’ = 1, ‘-’ = -1, ‘0’ = 0]
:dig2str = [1 = ‘+’, -1 = ‘-’, 0 = ‘0’]
Line 51 ⟶ 46:
R [Int]()
V n3 = ((n % 3) + 3) % 3
I n3 == 0 {R [0] [+] .:int2ternary(py_idiv(n, -I/ 3))}
I n3 == 1 {R [1] [+] .:int2ternary(py_idiv(n, -I/ 3))}
I n3 == 2 {R [-1] [+] .:int2ternary(py_idiv((n + 1), -I/ 3))}
X RuntimeError(‘’)
 
1,480

edits