Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Write the same algorithm in VB as shown in this REXX implementation. |
Call time 'R'
Numeric Digits 12
Parse Arg mxs area list
If mxs ='' Then mxs =200
If area='' Then area=210
If list='' Then list=10
tx='primitive Heronian triangles'
Call heronian mxs
Say nt tx 'found with side length up to' mxs "(inclusive)."
Call show '2'
Call show '3'
Say time('E')... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Change the following REXX code into Go without altering its purpose. |
Call time 'R'
Numeric Digits 12
Parse Arg mxs area list
If mxs ='' Then mxs =200
If area='' Then area=210
If list='' Then list=10
tx='primitive Heronian triangles'
Call heronian mxs
Say nt tx 'found with side length up to' mxs "(inclusive)."
Call show '2'
Call show '3'
Say time('E')... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Produce a functionally identical Go code for the snippet given in REXX. |
Call time 'R'
Numeric Digits 12
Parse Arg mxs area list
If mxs ='' Then mxs =200
If area='' Then area=210
If list='' Then list=10
tx='primitive Heronian triangles'
Call heronian mxs
Say nt tx 'found with side length up to' mxs "(inclusive)."
Call show '2'
Call show '3'
Say time('E')... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Write the same algorithm in C as shown in this Ruby implementation. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Convert this Ruby block to C, preserving its control flow and logic. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Convert the following code from Ruby to C#, ensuring the logic remains intact. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Rewrite the snippet below in C# so it works the same as the original Ruby code. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Please provide an equivalent version of this Ruby code in C++. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Write the same algorithm in C++ as shown in this Ruby implementation. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Preserve the algorithm and functionality while converting the code from Ruby to Java. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Generate an equivalent Java version of this Ruby code. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Please provide an equivalent version of this Ruby code in Python. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Rewrite the snippet below in Python so it works the same as the original Ruby code. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Produce a language-to-language conversion: from Ruby to VB, same semantics. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Produce a language-to-language conversion: from Ruby to VB, same semantics. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Convert this Ruby block to Go, preserving its control flow and logic. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Rewrite the snippet below in Go so it works the same as the original Ruby code. | class Triangle
def self.valid?(a,b,c)
short, middle, long = [a, b, c].sort
short + middle > long
end
attr_reader :sides, :perimeter, :area
def initialize(a,b,c)
@sides = [a, b, c].sort
@perimeter = a + b + c
s = @perimeter / 2.0
@area = Math.sqrt(s * (s - a) * (s - b) * (s - ... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Produce a language-to-language conversion: from Scala to C, same semantics. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Write the same algorithm in C as shown in this Scala implementation. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Write a version of this Scala function in C# with identical behavior. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Produce a language-to-language conversion: from Scala to C#, same semantics. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Translate this program into C++ but keep the logic exactly as in Scala. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Preserve the algorithm and functionality while converting the code from Scala to C++. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Write a version of this Scala function in Java with identical behavior. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Transform the following Scala implementation into Java, maintaining the same output and logic. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Translate this program into Python but keep the logic exactly as in Scala. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Translate this program into Python but keep the logic exactly as in Scala. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Please provide an equivalent version of this Scala code in VB. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Write the same code in VB as shown below in Scala. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Rewrite the snippet below in Go so it works the same as the original Scala code. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Please provide an equivalent version of this Scala code in Go. | import java.util.ArrayList
object Heron {
private val n = 200
fun run() {
val l = ArrayList<IntArray>()
for (c in 1..n)
for (b in 1..c)
for (a in 1..b)
if (gcd(gcd(a, b), c) == 1) {
val p = a + b + c
... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Rewrite this program in C while keeping its functionality equivalent to the Swift version. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Write the same algorithm in C as shown in this Swift implementation. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Rewrite the snippet below in C# so it works the same as the original Swift code. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Write the same algorithm in C# as shown in this Swift implementation. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Please provide an equivalent version of this Swift code in C++. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Port the provided Swift code into C++ while preserving the original functionality. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Produce a functionally identical Java code for the snippet given in Swift. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Convert this Swift snippet to Java and keep its semantics consistent. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Maintain the same structure and functionality when rewriting this code in Python. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Transform the following Swift implementation into Python, maintaining the same output and logic. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Translate this program into VB but keep the logic exactly as in Swift. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Port the provided Swift code into VB while preserving the original functionality. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Ensure the translated Go code behaves exactly like the original Swift snippet. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Maintain the same structure and functionality when rewriting this code in Go. | import Foundation
typealias PrimitiveHeronianTriangle = (s1:Int, s2:Int, s3:Int, p:Int, a:Int)
func heronianArea(side1 s1:Int, side2 s2:Int, side3 s3:Int) -> Int? {
let d1 = Double(s1)
let d2 = Double(s2)
let d3 = Double(s3)
let s = (d1 + d2 + d3) / 2.0
let a = sqrt(s * (s - d1) * (s - d2) * ... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Keep all operations the same but rewrite the snippet in C. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Write the same algorithm in C as shown in this Tcl implementation. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Write the same code in C# as shown below in Tcl. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Generate an equivalent C# version of this Tcl code. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... |
Change the following Tcl code into C++ without altering its purpose. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Write the same code in C++ as shown below in Tcl. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Convert this Tcl snippet to Java and keep its semantics consistent. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Rewrite the snippet below in Java so it works the same as the original Tcl code. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Write a version of this Tcl function in Python with identical behavior. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Rewrite the snippet below in Python so it works the same as the original Tcl code. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Generate an equivalent VB version of this Tcl code. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Transform the following Tcl implementation into VB, maintaining the same output and logic. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Maintain the same structure and functionality when rewriting this code in Go. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Convert this Tcl block to Go, preserving its control flow and logic. | if {[info commands let] eq ""} {
proc let {name args} {
tailcall ::set $name [uplevel 1 $args]
}
interp alias {} = {} expr
namespace import ::tcl::mathfunc::* ::tcl::mathop::*
interp alias {} sum {} +
proc coprime {a args} {
set gcd $a
foreach arg $args {
... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Preserve the algorithm and functionality while converting the code from C to Rust. | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Port the provided C++ code into Rust while preserving the original functionality. | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Port the following code from C# to Rust with equivalent syntax and logic. | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Convert this Go snippet to Rust and keep its semantics consistent. | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Rewrite the snippet below in Python so it works the same as the original Rust code. | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Rewrite the snippet below in VB so it works the same as the original Rust code. | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Transform the following C implementation into Rust, maintaining the same output and logic. | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Ensure the translated Rust code behaves exactly like the original C# snippet. | using System;
using System.Collections.Generic;
namespace heron
{
class Program{
static void Main(string[] args){
List<int[]> list = new List<int[]>();
for (int c = 1; c <= 200; c++)
for (int b = 1; b <= c; b++)
for (int a = 1; a <= b; ... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Keep all operations the same but rewrite the snippet in Rust. | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Write the same algorithm in Rust as shown in this Go implementation. | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Convert this Rust snippet to Python and keep its semantics consistent. | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Generate a VB translation of this Rust snippet without changing its computational steps. | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Produce a functionally identical Rust code for the snippet given in C++. | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Rewrite the snippet below in Rust so it works the same as the original Java code. | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... | use num_integer::Integer;
use std::{f64, usize};
const MAXSIZE: usize = 200;
#[derive(Debug)]
struct HerionanTriangle {
a: usize,
b: usize,
c: usize,
area: usize,
perimeter: usize,
}
fn get_area(a: &usize, b: &usize, c: &usize) -> f64 {
let s = (a + b + c) as f64 / 2.;
(s * (s - *a as f64... |
Write the same code in C# as shown below in Ada. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| using System;
namespace CheckTerminal {
class Program {
static void Main(string[] args) {
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected);
}
}
}
|
Generate an equivalent C# version of this Ada code. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| using System;
namespace CheckTerminal {
class Program {
static void Main(string[] args) {
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected);
}
}
}
|
Convert this Ada snippet to C and keep its semantics consistent. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| #include <unistd.h>
#include <stdio.h>
int main()
{
puts(isatty(fileno(stdout))
? "stdout is tty"
: "stdout is not tty");
return 0;
}
|
Rewrite the snippet below in C so it works the same as the original Ada code. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| #include <unistd.h>
#include <stdio.h>
int main()
{
puts(isatty(fileno(stdout))
? "stdout is tty"
: "stdout is not tty");
return 0;
}
|
Change the following Ada code into C++ without altering its purpose. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| #if _WIN32
#include <io.h>
#define ISATTY _isatty
#define FILENO _fileno
#else
#include <unistd.h>
#define ISATTY isatty
#define FILENO fileno
#endif
#include <iostream>
int main() {
if (ISATTY(FILENO(stdout))) {
std::cout << "stdout is a tty\n";
} else {
std::cout << "stdout is not a tty\n";
... |
Generate an equivalent C++ version of this Ada code. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| #if _WIN32
#include <io.h>
#define ISATTY _isatty
#define FILENO _fileno
#else
#include <unistd.h>
#define ISATTY isatty
#define FILENO fileno
#endif
#include <iostream>
int main() {
if (ISATTY(FILENO(stdout))) {
std::cout << "stdout is a tty\n";
} else {
std::cout << "stdout is not a tty\n";
... |
Port the following code from Ada to Go with equivalent syntax and logic. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| package main
import (
"os"
"fmt"
)
func main() {
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
fmt.Println("Hello terminal")
} else {
fmt.Println("Who are you? You're not a terminal")
}
}
|
Translate the given Ada code snippet into Go without altering its behavior. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| package main
import (
"os"
"fmt"
)
func main() {
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
fmt.Println("Hello terminal")
} else {
fmt.Println("Who are you? You're not a terminal")
}
}
|
Preserve the algorithm and functionality while converting the code from Ada to Python. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| from sys import stdout
if stdout.isatty():
print 'The output device is a teletype. Or something like a teletype.'
else:
print 'The output device isn\'t like a teletype.'
|
Ensure the translated Python code behaves exactly like the original Ada snippet. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| from sys import stdout
if stdout.isatty():
print 'The output device is a teletype. Or something like a teletype.'
else:
print 'The output device isn\'t like a teletype.'
|
Write a version of this Ada function in VB with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| Module Module1
Sub Main()
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected)
End Sub
End Module
|
Please provide an equivalent version of this Ada code in VB. | with Ada.Text_IO; use Ada.Text_IO;
with Interfaces.C_Streams; use Interfaces.C_Streams;
procedure Test_tty is
begin
if Isatty(Fileno(Stdout)) = 0 then
Put_Line(Standard_Error, "stdout is not a tty.");
else
Put_Line(Standard_Error, "stdout is a tty.");
end if;
end Test_tty;
| Module Module1
Sub Main()
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected)
End Sub
End Module
|
Rewrite the snippet below in C so it works the same as the original Common_Lisp code. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| #include <unistd.h>
#include <stdio.h>
int main()
{
puts(isatty(fileno(stdout))
? "stdout is tty"
: "stdout is not tty");
return 0;
}
|
Maintain the same structure and functionality when rewriting this code in C. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| #include <unistd.h>
#include <stdio.h>
int main()
{
puts(isatty(fileno(stdout))
? "stdout is tty"
: "stdout is not tty");
return 0;
}
|
Port the following code from Common_Lisp to C# with equivalent syntax and logic. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| using System;
namespace CheckTerminal {
class Program {
static void Main(string[] args) {
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected);
}
}
}
|
Ensure the translated C# code behaves exactly like the original Common_Lisp snippet. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| using System;
namespace CheckTerminal {
class Program {
static void Main(string[] args) {
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected);
}
}
}
|
Rewrite the snippet below in C++ so it works the same as the original Common_Lisp code. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| #if _WIN32
#include <io.h>
#define ISATTY _isatty
#define FILENO _fileno
#else
#include <unistd.h>
#define ISATTY isatty
#define FILENO fileno
#endif
#include <iostream>
int main() {
if (ISATTY(FILENO(stdout))) {
std::cout << "stdout is a tty\n";
} else {
std::cout << "stdout is not a tty\n";
... |
Produce a language-to-language conversion: from Common_Lisp to C++, same semantics. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| #if _WIN32
#include <io.h>
#define ISATTY _isatty
#define FILENO _fileno
#else
#include <unistd.h>
#define ISATTY isatty
#define FILENO fileno
#endif
#include <iostream>
int main() {
if (ISATTY(FILENO(stdout))) {
std::cout << "stdout is a tty\n";
} else {
std::cout << "stdout is not a tty\n";
... |
Convert the following code from Common_Lisp to Python, ensuring the logic remains intact. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| from sys import stdout
if stdout.isatty():
print 'The output device is a teletype. Or something like a teletype.'
else:
print 'The output device isn\'t like a teletype.'
|
Change the programming language of this snippet from Common_Lisp to Python without modifying what it does. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| from sys import stdout
if stdout.isatty():
print 'The output device is a teletype. Or something like a teletype.'
else:
print 'The output device isn\'t like a teletype.'
|
Write a version of this Common_Lisp function in VB with identical behavior. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| Module Module1
Sub Main()
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected)
End Sub
End Module
|
Change the following Common_Lisp code into VB without altering its purpose. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| Module Module1
Sub Main()
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected)
End Sub
End Module
|
Produce a language-to-language conversion: from Common_Lisp to Go, same semantics. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| package main
import (
"os"
"fmt"
)
func main() {
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
fmt.Println("Hello terminal")
} else {
fmt.Println("Who are you? You're not a terminal")
}
}
|
Maintain the same structure and functionality when rewriting this code in Go. | (with-open-stream (s *standard-output*)
(format T "stdout is~:[ not~
(interactive-stream-p s)))
| package main
import (
"os"
"fmt"
)
func main() {
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
fmt.Println("Hello terminal")
} else {
fmt.Println("Who are you? You're not a terminal")
}
}
|
Write the same algorithm in C as shown in this D implementation. | import std.stdio;
extern(C) int isatty(int);
void main() {
writeln("Stdout is tty: ", stdout.fileno.isatty == 1);
}
| #include <unistd.h>
#include <stdio.h>
int main()
{
puts(isatty(fileno(stdout))
? "stdout is tty"
: "stdout is not tty");
return 0;
}
|
Transform the following D implementation into C, maintaining the same output and logic. | import std.stdio;
extern(C) int isatty(int);
void main() {
writeln("Stdout is tty: ", stdout.fileno.isatty == 1);
}
| #include <unistd.h>
#include <stdio.h>
int main()
{
puts(isatty(fileno(stdout))
? "stdout is tty"
: "stdout is not tty");
return 0;
}
|
Write the same code in C# as shown below in D. | import std.stdio;
extern(C) int isatty(int);
void main() {
writeln("Stdout is tty: ", stdout.fileno.isatty == 1);
}
| using System;
namespace CheckTerminal {
class Program {
static void Main(string[] args) {
Console.WriteLine("Stdout is tty: {0}", Console.IsOutputRedirected);
}
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.