Balanced ternary: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (→{{header|11l}}: Static type variables and static methods are supported now) |
Alextretyak (talk | contribs) m (→{{header|11l}}: `-I/`) |
||
Line 29: | Line 29: | ||
{{trans|Python}} |
{{trans|Python}} |
||
<syntaxhighlight lang="11l"> |
<syntaxhighlight lang="11l">T BalancedTernary |
||
I a >= 0 |
|||
R a I/ b |
|||
R (a - b + 1) I/ b |
|||
T BalancedTernary |
|||
:str2dig = [‘+’ = 1, ‘-’ = -1, ‘0’ = 0] |
:str2dig = [‘+’ = 1, ‘-’ = -1, ‘0’ = 0] |
||
:dig2str = [1 = ‘+’, -1 = ‘-’, 0 = ‘0’] |
:dig2str = [1 = ‘+’, -1 = ‘-’, 0 = ‘0’] |
||
Line 51: | Line 46: | ||
R [Int]() |
R [Int]() |
||
V n3 = ((n % 3) + 3) % 3 |
V n3 = ((n % 3) + 3) % 3 |
||
I n3 == 0 {R [0] [+] .:int2ternary |
I n3 == 0 {R [0] [+] .:int2ternary(n -I/ 3)} |
||
I n3 == 1 {R [1] [+] .:int2ternary |
I n3 == 1 {R [1] [+] .:int2ternary(n -I/ 3)} |
||
I n3 == 2 {R [-1] [+] .:int2ternary |
I n3 == 2 {R [-1] [+] .:int2ternary((n + 1) -I/ 3)} |
||
X RuntimeError(‘’) |
X RuntimeError(‘’) |
||