Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Preserve the algorithm and functionality while converting the code from REXX to 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("...
Convert the following code from REXX to C++, ensuring the logic remains intact.
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 <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 REXX code into C++ while preserving the original functionality.
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 <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 REXX to Java with equivalent syntax and logic.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
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 a Java 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...
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 REXX code.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
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 Python so it works the same as the original REXX code.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
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 code in VB as shown below in REXX.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
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...
Produce a functionally identical VB code for the snippet given in REXX.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
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 REXX block to Go, preserving its control flow and logic.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
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 REXX implementation into Go, maintaining the same output and logic.
numeric digits 10000 Ao = '+-0++0+' ; Abt = Ao Bo = '-436' ; Bbt = d2bt(Bo); @ = "(decimal)" Co = '+-++-' ; Cbt = Co ; @@ = "balanced ternary =" call btShow '[a]', Abt ca...
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 C code for the snippet given in Ruby.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
#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 a version of this Ruby function in C with identical behavior.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
#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#.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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("...
Ensure the translated C# code behaves exactly like the original Ruby snippet.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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 Ruby block to C++, preserving its control flow and logic.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
#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] ...
Keep all operations the same but rewrite the snippet in C++.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
#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] ...
Preserve the algorithm and functionality while converting the code from Ruby to Java.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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...
Port the following code from Ruby to Java with equivalent syntax and logic.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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...
Transform the following Ruby implementation into Python, maintaining the same output and logic.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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 a version of this Ruby function in Python with identical behavior.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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 Ruby implementation into VB, maintaining the same output and logic.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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 VB code behaves exactly like the original Ruby snippet.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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 Go version of this Ruby code.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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 Ruby implementation.
class BalancedTernary include Comparable def initialize(str = "") if str =~ /[^-+0]+/ raise ArgumentError, "invalid BalancedTernary number: end @digits = trim0(str) end I2BT = {0 => ["0",0], 1 => ["+",0], 2 => ["-",1]} def self.from_int(value) n = value.to_i digits = "" whil...
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 C as shown in this Scala implementation.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
#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 Scala.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
#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 Scala code snippet into C# without altering its behavior.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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("...
Translate this program into C# but keep the logic exactly as in Scala.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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 Scala to C++.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
#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 functionally identical C++ code for the snippet given in Scala.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
#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 Scala to Java, same semantics.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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 Scala snippet to Java and keep its semantics consistent.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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...
Maintain the same structure and functionality when rewriting this code in Python.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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 Python.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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 Scala snippet without changing its computational steps.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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...
Rewrite this program in VB while keeping its functionality equivalent to the Scala version.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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 Scala.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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 Go translation of this Scala snippet without changing its computational steps.
import java.math.BigInteger val bigZero = BigInteger.ZERO val bigOne = BigInteger.ONE val bigThree = BigInteger.valueOf(3L) data class BTernary(private var value: String) : Comparable<BTernary> { init { require(value.all { it in "0+-" }) value = value.trimStart('0') } constructor(v: In...
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...
Keep all operations the same but rewrite the snippet in C.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
#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 following code from Tcl to C with equivalent syntax and logic.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
#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 this Tcl block to C#, preserving its control flow and logic.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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("...
Write a version of this Tcl function in C# with identical behavior.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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++.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
#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 Tcl to C++, ensuring the logic remains intact.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
#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] ...
Generate an equivalent Java version of this Tcl code.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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 Tcl block to Java, preserving its control flow and logic.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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 Python while keeping its functionality equivalent to the Tcl version.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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(...
Can you help me rewrite this code in Python instead of Tcl, keeping it the same logically?
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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 programming language of this snippet from Tcl to VB without modifying what it does.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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 Tcl code.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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 Tcl version.
package require Tcl 8.5 proc bt-int b { set n 0 foreach c [split $b ""] { set n [expr {$n * 3}] switch -- $c { + { incr n 1 } - { incr n -1 } } } return $n } proc int-bt n { if {$n == 0} { return "0" } while {$n != 0} { lappend result [lindex {0 + -} [expr {$n % 3}]] set n ...
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 C to Rust with equivalent syntax and logic.
#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...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Keep all operations the same but rewrite the snippet in Rust.
#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...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Change the programming language of this snippet from C++ to Rust without modifying what it does.
#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] ...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Preserve the algorithm and functionality while converting the code from C++ to Rust.
#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] ...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Produce a language-to-language conversion: from Java to Rust, same semantics.
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...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Please provide an equivalent version of this Java code in Rust.
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...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Convert this Go block to Rust, preserving its control flow and logic.
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...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Convert this Go snippet to Rust and keep its semantics consistent.
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...
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
Convert this Rust snippet to Python and keep its semantics consistent.
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
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(...
Can you help me rewrite this code in VB instead of Rust, keeping it the same logically?
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
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...
Rewrite the snippet below in Python so it works the same as the original Rust code.
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
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 Rust snippet to VB and keep its semantics consistent.
use std::{ cmp::min, convert::{TryFrom, TryInto}, fmt, ops::{Add, Mul, Neg}, str::FromStr, }; fn main() -> Result<(), &'static str> { let a = BalancedTernary::from_str("+-0++0+")?; let b = BalancedTernary::from(-436); let c = BalancedTernary::from_str("+-++-")?; println!("a = {} = {...
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...
Produce a language-to-language conversion: from Ada to C#, same semantics.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Transform the following Ada implementation into C#, maintaining the same output and logic.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Produce a functionally identical C code for the snippet given in Ada.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Produce a language-to-language conversion: from Ada to C, same semantics.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Generate a C++ translation of this Ada snippet without changing its computational steps.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Rewrite this program in C++ while keeping its functionality equivalent to the Ada version.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Write the same algorithm in Go as shown in this Ada implementation.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Rewrite the snippet below in Go so it works the same as the original Ada code.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Write the same code in Python as shown below in Ada.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Produce a language-to-language conversion: from Ada to Python, same semantics.
with Ada.Text_IO; with GNAT.SHA1; procedure Main is begin Ada.Text_IO.Put_Line ("SHA1 (""Rosetta Code"") = " & GNAT.SHA1.Digest ("Rosetta Code")); end Main;
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Preserve the algorithm and functionality while converting the code from Arturo to C.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Rewrite the snippet below in C so it works the same as the original Arturo code.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Please provide an equivalent version of this Arturo code in C#.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Rewrite the snippet below in C# so it works the same as the original Arturo code.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Change the following Arturo code into C++ without altering its purpose.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Can you help me rewrite this code in C++ instead of Arturo, keeping it the same logically?
print digest.sha "The quick brown fox jumped over the lazy dog's back"
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Preserve the algorithm and functionality while converting the code from Arturo to Python.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Produce a functionally identical Python code for the snippet given in Arturo.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Write the same algorithm in Go as shown in this Arturo implementation.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Rewrite the snippet below in Go so it works the same as the original Arturo code.
print digest.sha "The quick brown fox jumped over the lazy dog's back"
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Generate an equivalent C version of this AutoHotKey code.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Maintain the same structure and functionality when rewriting this code in C.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Translate this program into C# but keep the logic exactly as in AutoHotKey.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Change the following AutoHotKey code into C# without altering its purpose.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Change the programming language of this snippet from AutoHotKey to C++ without modifying what it does.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Convert the following code from AutoHotKey to C++, ensuring the logic remains intact.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...
Produce a functionally identical Python code for the snippet given in AutoHotKey.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Generate a Python translation of this AutoHotKey snippet without changing its computational steps.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
import crypto { sha1 } let hash = sha1.hexdigest('Ars longa, vita brevis') print hash
Port the following code from AutoHotKey to Go with equivalent syntax and logic.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Convert this AutoHotKey snippet to Go and keep its semantics consistent.
str := "Rosetta Code" MsgBox, % "String:`n" (str) "`n`nSHA:`n" SHA(str) SHA(string, encoding = "utf-8") { return CalcStringHash(string, 0x8004, encoding) } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"] ...
package main import ( "crypto/sha1" "fmt" ) func main() { h := sha1.New() h.Write([]byte("Rosetta Code")) fmt.Printf("%x\n", h.Sum(nil)) }
Convert the following code from BBC_Basic to C, ensuring the logic remains intact.
PRINT FNsha1("Rosetta Code") END DEF FNsha1(message$) LOCAL buflen%, buffer%, hprov%, hhash%, hash$, i% CALG_SHA1 = &8004 CRYPT_VERIFYCONTEXT = &F0000000 HP_HASHVAL = 2 PROV_RSA_FULL = 1 buflen% = 64 DIM buffer% LOCAL buflen%-1 SYS "CryptAcquireCo...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Produce a functionally identical C code for the snippet given in BBC_Basic.
PRINT FNsha1("Rosetta Code") END DEF FNsha1(message$) LOCAL buflen%, buffer%, hprov%, hhash%, hash$, i% CALG_SHA1 = &8004 CRYPT_VERIFYCONTEXT = &F0000000 HP_HASHVAL = 2 PROV_RSA_FULL = 1 buflen% = 64 DIM buffer% LOCAL buflen%-1 SYS "CryptAcquireCo...
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/sha.h> int main() { int i; unsigned char result[SHA_DIGEST_LENGTH]; const char *string = "Rosetta Code"; SHA1(string, strlen(string), result); for(i = 0; i < SHA_DIGEST_LENGTH; i++) printf("%02x%c", result[i], i < (SHA_DIGES...
Write a version of this BBC_Basic function in C# with identical behavior.
PRINT FNsha1("Rosetta Code") END DEF FNsha1(message$) LOCAL buflen%, buffer%, hprov%, hhash%, hash$, i% CALG_SHA1 = &8004 CRYPT_VERIFYCONTEXT = &F0000000 HP_HASHVAL = 2 PROV_RSA_FULL = 1 buflen% = 64 DIM buffer% LOCAL buflen%-1 SYS "CryptAcquireCo...
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Transform the following BBC_Basic implementation into C#, maintaining the same output and logic.
PRINT FNsha1("Rosetta Code") END DEF FNsha1(message$) LOCAL buflen%, buffer%, hprov%, hhash%, hash$, i% CALG_SHA1 = &8004 CRYPT_VERIFYCONTEXT = &F0000000 HP_HASHVAL = 2 PROV_RSA_FULL = 1 buflen% = 64 DIM buffer% LOCAL buflen%-1 SYS "CryptAcquireCo...
using System; using System.Security.Cryptography; using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace RosettaCode.SHA1 { [TestClass] public class SHA1CryptoServiceProviderTest { [TestMethod] public void TestComputeHash() { var input = new UTF...
Please provide an equivalent version of this BBC_Basic code in C++.
PRINT FNsha1("Rosetta Code") END DEF FNsha1(message$) LOCAL buflen%, buffer%, hprov%, hhash%, hash$, i% CALG_SHA1 = &8004 CRYPT_VERIFYCONTEXT = &F0000000 HP_HASHVAL = 2 PROV_RSA_FULL = 1 buflen% = 64 DIM buffer% LOCAL buflen%-1 SYS "CryptAcquireCo...
#include <string> #include <iostream> #include "Poco/SHA1Engine.h" #include "Poco/DigestStream.h" using Poco::DigestEngine ; using Poco::SHA1Engine ; using Poco::DigestOutputStream ; int main( ) { std::string myphrase ( "Rosetta Code" ) ; SHA1Engine sha1 ; DigestOutputStream outstr( sha1 ) ; outstr << myp...