Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Port the following code from Julia to C with equivalent syntax and logic.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Produce a language-to-language conversion: from Julia to C#, same semantics.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Change the programming language of this snippet from Julia to C# without modifying what it does.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Convert this Julia snippet to C++ and keep its semantics consistent.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Port the provided Julia code into C++ while preserving the original functionality.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Write a version of this Julia function in Java with identical behavior.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Rewrite this program in Java while keeping its functionality equivalent to the Julia version.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Convert this Julia block to Python, preserving its control flow and logic.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Ensure the translated Python code behaves exactly like the original Julia snippet.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Rewrite this program in VB while keeping its functionality equivalent to the Julia version.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Write the same algorithm in VB as shown in this Julia implementation.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Port the provided Julia code into Go while preserving the original functionality.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Produce a language-to-language conversion: from Julia to Go, same semantics.
struct BalancedTernary <: Signed digits::Vector{Int8} end BalancedTernary() = zero(BalancedTernary) BalancedTernary(n) = convert(BalancedTernary, n) const sgn2chr = Dict{Int8,Char}(-1 => '-', 0 => '0', +1 => '+') Base.show(io::IO, bt::BalancedTernary) = print(io, join(sgn2chr[x] for x in reverse(bt.digits))) Base....
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Change the programming language of this snippet from Lua to C without modifying what it does.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Rewrite this program in C while keeping its functionality equivalent to the Lua version.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Convert the following code from Lua to C#, ensuring the logic remains intact.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Transform the following Lua implementation into C#, maintaining the same output and logic.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Keep all operations the same but rewrite the snippet in C++.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Convert this Lua snippet to C++ and keep its semantics consistent.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Rewrite the snippet below in Java so it works the same as the original Lua code.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Convert this Lua block to Java, preserving its control flow and logic.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Convert the following code from Lua to Python, ensuring the logic remains intact.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Transform the following Lua implementation into Python, maintaining the same output and logic.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Rewrite the snippet below in VB so it works the same as the original Lua code.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Translate this program into VB but keep the logic exactly as in Lua.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Convert this Lua snippet to Go and keep its semantics consistent.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Change the programming language of this snippet from Lua to Go without modifying what it does.
function to_bt(n) local d = { '0', '+', '-' } local v = { 0, 1, -1 } local b = "" while n ~= 0 do local r = n % 3 if r < 0 then r = r + 3 end b = b .. d[r + 1] n = n - v[r + 1] n = math.floor(n / 3) end return b:reverse() end func...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Transform the following Mathematica implementation into C, maintaining the same output and logic.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Generate an equivalent C version of this Mathematica code.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Can you help me rewrite this code in C# instead of Mathematica, keeping it the same logically?
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Transform the following Mathematica implementation into C#, maintaining the same output and logic.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Preserve the algorithm and functionality while converting the code from Mathematica to C++.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Translate this program into C++ but keep the logic exactly as in Mathematica.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Convert the following code from Mathematica to Java, ensuring the logic remains intact.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Produce a language-to-language conversion: from Mathematica to Java, same semantics.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Can you help me rewrite this code in Python instead of Mathematica, keeping it the same logically?
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Transform the following Mathematica implementation into Python, maintaining the same output and logic.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Change the following Mathematica code into VB without altering its purpose.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Port the following code from Mathematica to VB with equivalent syntax and logic.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Write the same code in Go as shown below in Mathematica.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Port the following code from Mathematica to Go with equivalent syntax and logic.
frombt = FromDigits[StringCases[#, {"+" -> 1, "-" -> -1, "0" -> 0}], 3] &; tobt = If[Quotient[#, 3, -1] == 0, "", #0@Quotient[#, 3, -1]] <> (Mod[#, 3, -1] /. {1 -> "+", -1 -> "-", 0 -> "0"}) &; btnegate = StringReplace[#, {"+" -> "-", "-" -> "+"}] &; btadd = StringReplace[ StringJoin[ Fold[S...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Maintain the same structure and functionality when rewriting this code in C.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Write the same code in C as shown below in Nim.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Translate the given Nim code snippet into C# without altering its behavior.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Maintain the same structure and functionality when rewriting this code in C#.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Please provide an equivalent version of this Nim code in C++.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Translate this program into C++ but keep the logic exactly as in Nim.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Translate the given Nim code snippet into Java without altering its behavior.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Change the programming language of this snippet from Nim to Java without modifying what it does.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Translate this program into Python but keep the logic exactly as in Nim.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Write the same algorithm in Python as shown in this Nim implementation.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Maintain the same structure and functionality when rewriting this code in VB.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Translate the given Nim code snippet into VB without altering its behavior.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Keep all operations the same but rewrite the snippet in Go.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Change the following Nim code into Go without altering its purpose.
import strformat import tables type Trit = range[-1'i8..1'i8] BTernary = seq[Trit] const Trits: array[Trit, char] = ['-', '0', '+'] TN = Trit(-1) TZ = Trit(0) TP = Trit(1) AddTable = {-2: @[TP, TN], -1: @[TN], 0: @[TZ], 1: @[TP], 2: @[TN, TP]}.toTable() ModTrits: array[-2..2, T...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Produce a language-to-language conversion: from OCaml to C, same semantics.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Keep all operations the same but rewrite the snippet in C.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Change the programming language of this snippet from OCaml to C# without modifying what it does.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Preserve the algorithm and functionality while converting the code from OCaml to C#.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Port the following code from OCaml to C++ with equivalent syntax and logic.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Convert this OCaml snippet to C++ and keep its semantics consistent.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Change the following OCaml code into Java without altering its purpose.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Can you help me rewrite this code in Java instead of OCaml, keeping it the same logically?
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Rewrite the snippet below in Python so it works the same as the original OCaml code.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Write the same algorithm in Python as shown in this OCaml implementation.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Generate a VB translation of this OCaml snippet without changing its computational steps.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Generate an equivalent VB version of this OCaml code.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Please provide an equivalent version of this OCaml code in Go.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Produce a functionally identical Go code for the snippet given in OCaml.
type btdigit = Pos | Zero | Neg type btern = btdigit list let to_string n = String.concat "" (List.rev_map (function Pos -> "+" | Zero -> "0" | Neg -> "-") n) let from_string s = let sl = ref [] in let digit = function '+' -> Pos | '-' -> Neg | '0' -> Zero | _ -> failwith "invalid digit" in St...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Rewrite this program in C while keeping its functionality equivalent to the Perl version.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Write the same code in C as shown below in Perl.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Port the provided Perl code into C# while preserving the original functionality.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Produce a functionally identical C# code for the snippet given in Perl.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Port the provided Perl code into C++ while preserving the original functionality.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Translate this program into C++ but keep the logic exactly as in Perl.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Convert this Perl block to Java, preserving its control flow and logic.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Please provide an equivalent version of this Perl code in Java.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Generate an equivalent Python version of this Perl code.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Port the following code from Perl to Python with equivalent syntax and logic.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Convert this Perl snippet to VB and keep its semantics consistent.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Change the programming language of this snippet from Perl to VB without modifying what it does.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Ensure the translated Go code behaves exactly like the original Perl snippet.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Rewrite this program in Go while keeping its functionality equivalent to the Perl version.
use strict; use warnings; my @d = qw( 0 + - ); my @v = qw( 0 1 -1 ); sub to_bt { my $n = shift; my $b = ''; while( $n ) { my $r = $n%3; $b .= $d[$r]; $n -= $v[$r]; $n /= 3; } return scalar reverse $b; } sub from_bt { my $n = 0; for( split //, shift ) { $n *= 3; ...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Generate a C translation of this Racket snippet without changing its computational steps.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Rewrite the snippet below in C so it works the same as the original Racket code.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Change the following Racket code into C# without altering its purpose.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Produce a functionally identical C# code for the snippet given in Racket.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...
Produce a functionally identical C++ code for the snippet given in Racket.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Port the following code from Racket to C++ with equivalent syntax and logic.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
#include <iostream> #include <string> #include <climits> using namespace std; class BalancedTernary { protected: string value; int charToInt(char c) const { if (c == '0') return 0; return 44 - c; } string negate(string s) const { for (int i = 0; i < s.length(); ++i) { if (s[i] == '+') s[i] ...
Produce a language-to-language conversion: from Racket to Java, same semantics.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Produce a language-to-language conversion: from Racket to Java, same semantics.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
public class BalancedTernary { public static void main(String[] args) { BTernary a=new BTernary("+-0++0+"); BTernary b=new BTernary(-436); BTernary c=new BTernary("+-++-"); System.out.println("a="+a.intValue()); System.out.println("b="+b.intValue()); System.out.println("c="+c.intValue()); System.o...
Preserve the algorithm and functionality while converting the code from Racket to Python.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Produce a language-to-language conversion: from Racket to Python, same semantics.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
class BalancedTernary: str2dig = {'+': 1, '-': -1, '0': 0} dig2str = {1: '+', -1: '-', 0: '0'} table = ((0, -1), (1, -1), (-1, 0), (0, 0), (1, 0), (-1, 1), (0, 1)) def __init__(self, inp): if isinstance(inp, str): self.digits = [BalancedTernary.str2dig[c] for c in reversed(...
Port the provided Racket code into VB while preserving the original functionality.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Can you help me rewrite this code in VB instead of Racket, keeping it the same logically?
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
Imports System.Text Module Module1 Sub Main() Dim a As New BalancedTernary("+-0++0+") Console.WriteLine("a: {0} = {1}", a, a.ToLong) Dim b As New BalancedTernary(-436) Console.WriteLine("b: {0} = {1}", b, b.ToLong) Dim c As New BalancedTernary("+-++-") Console.WriteL...
Change the programming language of this snippet from Racket to Go without modifying what it does.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Write the same algorithm in Go as shown in this Racket implementation.
#lang racket (define (bt->integer t) (if (null? t) 0 (+ (first t) (* 3 (bt->integer (rest t)))))) (define (integer->bt n) (letrec ([recur (λ (b r) (cons b (convert (floor (/ r 3)))))] [convert (λ (n) (if (zero? n) null (case (modulo n 3) ...
package main import ( "fmt" "strings" ) type bt []int8 func btString(s string) (*bt, bool) { s = strings.TrimLeft(s, "0") b := make(bt, len(s)) for i, last := 0, len(s)-1; i < len(s); i++ { switch s[i] { case '-': b[last-i] = -1 case '0': b...
Generate a C translation of this REXX snippet without changing its computational steps.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Produce a language-to-language conversion: from REXX to C, same semantics.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
#include <stdio.h> #include <string.h> void reverse(char *p) { size_t len = strlen(p); char *r = p + len - 1; while (p < r) { *p ^= *r; *r ^= *p; *p++ ^= *r--; } } void to_bt(int n, char *b) { static char d[] = { '0', '+', '-' }; static int v[] = { 0, 1, -1 }; char...
Maintain the same structure and functionality when rewriting this code in C#.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
using System; using System.Text; using System.Collections.Generic; public class BalancedTernary { public static void Main() { BalancedTernary a = new BalancedTernary("+-0++0+"); System.Console.WriteLine("a: " + a + " = " + a.ToLong()); BalancedTernary b = new BalancedTernary(-436); System.Console.WriteLine("...