Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Produce a functionally identical Python code for the snippet given in Lua. |
local function tryHt( a, b, c )
local result
local s = ( a + b + c ) / 2;
local areaSquared = s * ( s - a ) * ( s - b ) * ( s - c );
if areaSquared > 0 then
local area = math.sqrt( areaSquared );
if math.floor( area ) == area then
result = { a = a, b = ... | 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(... |
Can you help me rewrite this code in Python instead of Lua, keeping it the same logically? |
local function tryHt( a, b, c )
local result
local s = ( a + b + c ) / 2;
local areaSquared = s * ( s - a ) * ( s - b ) * ( s - c );
if areaSquared > 0 then
local area = math.sqrt( areaSquared );
if math.floor( area ) == area then
result = { a = a, b = ... | 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 the given Lua code snippet into VB without altering its behavior. |
local function tryHt( a, b, c )
local result
local s = ( a + b + c ) / 2;
local areaSquared = s * ( s - a ) * ( s - b ) * ( s - c );
if areaSquared > 0 then
local area = math.sqrt( areaSquared );
if math.floor( area ) == area then
result = { a = a, b = ... | 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 a version of this Lua function in VB with identical behavior. |
local function tryHt( a, b, c )
local result
local s = ( a + b + c ) / 2;
local areaSquared = s * ( s - a ) * ( s - b ) * ( s - c );
if areaSquared > 0 then
local area = math.sqrt( areaSquared );
if math.floor( area ) == area then
result = { a = a, b = ... | 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 a version of this Lua function in Go with identical behavior. |
local function tryHt( a, b, c )
local result
local s = ( a + b + c ) / 2;
local areaSquared = s * ( s - a ) * ( s - b ) * ( s - c );
if areaSquared > 0 then
local area = math.sqrt( areaSquared );
if math.floor( area ) == area then
result = { a = a, b = ... | 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... |
Change the following Lua code into Go without altering its purpose. |
local function tryHt( a, b, c )
local result
local s = ( a + b + c ) / 2;
local areaSquared = s * ( s - a ) * ( s - b ) * ( s - c );
if areaSquared > 0 then
local area = math.sqrt( areaSquared );
if math.floor( area ) == area then
result = { a = a, b = ... | 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 Mathematica code in C. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | #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 Mathematica implementation. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | #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 this program in C# while keeping its functionality equivalent to the Mathematica version. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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 Mathematica implementation. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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; ... |
Port the provided Mathematica code into C++ while preserving the original functionality. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | #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;
... |
Keep all operations the same but rewrite the snippet in C++. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | #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;
... |
Ensure the translated Java code behaves exactly like the original Mathematica snippet. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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 Mathematica code. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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)... |
Keep all operations the same but rewrite the snippet in Python. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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 functionally identical Python code for the snippet given in Mathematica. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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 the given Mathematica code snippet into VB without altering its behavior. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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 algorithm in VB as shown in this Mathematica implementation. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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 algorithm in Go as shown in this Mathematica implementation. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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... |
Change the programming language of this snippet from Mathematica to Go without modifying what it does. | ClearAll[Heron]
Heron[a_, b_, c_] := With[{s = (a + b + c)/2}, Sqrt[s (s - a) (s - b) (s - c)]]
PrintTemporary[Dynamic[{a, b, c}]];
results = Reap[
Do[
If[a < b + c \[And] b < c + a \[And] c < a + b,
If[GCD[a, b, c] == 1,
If[IntegerQ[Heron[a, b, c]],
Sow[<|"Sides" -> {a, b, c}, "Area" -> H... | 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... |
Can you help me rewrite this code in C instead of Nim, keeping it the same logically? | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | #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 this program in C while keeping its functionality equivalent to the Nim version. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | #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... |
Generate an equivalent C# version of this Nim code. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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; ... |
Convert this Nim snippet to C# and keep its semantics consistent. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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 programming language of this snippet from Nim to C++ without modifying what it does. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | #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;
... |
Rewrite the snippet below in C++ so it works the same as the original Nim code. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | #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;
... |
Please provide an equivalent version of this Nim code in Java. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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)... |
Preserve the algorithm and functionality while converting the code from Nim to Java. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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)... |
Ensure the translated Python code behaves exactly like the original Nim snippet. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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 Nim code. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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 functionally identical VB code for the snippet given in Nim. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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... |
Preserve the algorithm and functionality while converting the code from Nim to VB. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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 Go code for the snippet given in Nim. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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 Go. | import math, algorithm, lenientops, strformat, sequtils
type HeronianTriangle = tuple[a, b, c: int; p: int; area: int]
func `$` (t: HeronianTriangle): string =
fmt"{t.a:3d}, {t.b:3d}, {t.c:3d} {t.p:7d} {t.area:8d}"
func hero(a, b, c: int): float =
let s = (a + b + c) / 2
result = sqrt(s * (s - a) * (s - b) * (... | 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 Pascal block to C, preserving its control flow and logic. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | #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... |
Translate the given Pascal code snippet into C without altering its behavior. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | #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 Pascal block to C#, preserving its control flow and logic. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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; ... |
Preserve the algorithm and functionality while converting the code from Pascal to C#. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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 Pascal. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | #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 Pascal. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | #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 language-to-language conversion: from Pascal to Java, same semantics. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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)... |
Keep all operations the same but rewrite the snippet in Java. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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)... |
Port the following code from Pascal to Python with equivalent syntax and logic. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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(... |
Write the same code in Python as shown below in Pascal. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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(... |
Can you help me rewrite this code in VB instead of Pascal, keeping it the same logically? | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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 following code from Pascal to VB with equivalent syntax and logic. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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 Pascal code into Go without altering its purpose. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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... |
Change the programming language of this snippet from Pascal to Go without modifying what it does. | program heronianTriangles ( input, output );
type
Heronian = record a, b, c, area, perimeter : integer end;
refHeronian = ^Heronian;
var
ht : array [ 1 .. 1000 ] of refHeronian;
htCount, htPos : integer;
a, b, c, i : integer;
lower, upper : integer;
k, h, t ... | 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... |
Can you help me rewrite this code in C instead of Perl, keeping it the same logically? | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | #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 Perl code. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | #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... |
Change the programming language of this snippet from Perl to C# without modifying what it does. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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; ... |
Port the provided Perl code into C# while preserving the original functionality. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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 Perl code. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | #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 Perl block to Java, preserving its control flow and logic. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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)... |
Port the following code from Perl to Java with equivalent syntax and logic. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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)... |
Ensure the translated Python code behaves exactly like the original Perl snippet. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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 this program in Python while keeping its functionality equivalent to the Perl version. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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(... |
Port the following code from Perl to VB with equivalent syntax and logic. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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 this program in VB while keeping its functionality equivalent to the Perl version. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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... |
Please provide an equivalent version of this Perl code in Go. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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... |
Change the programming language of this snippet from Perl to Go without modifying what it does. | use strict;
use warnings;
use List::Util qw(max);
sub gcd { $_[1] == 0 ? $_[0] : gcd($_[1], $_[0] % $_[1]) }
sub hero {
my ($a, $b, $c) = @_[0,1,2];
my $s = ($a + $b + $c) / 2;
sqrt $s*($s - $a)*($s - $b)*($s - $c);
}
sub heronian_area {
my $hero = hero my ($a, $b, $c) = @_[0,1,2];
sprintf("%.0f"... | 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 code in C as shown below in PowerShell. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | #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... |
Change the following PowerShell code into C without altering its purpose. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | #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... |
Change the following PowerShell code into C# without altering its purpose. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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 functionally identical C# code for the snippet given in PowerShell. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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 functionally identical C++ code for the snippet given in PowerShell. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | #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;
... |
Transform the following PowerShell implementation into C++, maintaining the same output and logic. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | #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 Java as shown below in PowerShell. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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)... |
Port the provided PowerShell code into Java while preserving the original functionality. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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 PowerShell block to Python, preserving its control flow and logic. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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(... |
Write the same code in Python as shown below in PowerShell. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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(... |
Keep all operations the same but rewrite the snippet in VB. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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 PowerShell implementation into VB, maintaining the same output and logic. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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 algorithm in Go as shown in this PowerShell implementation. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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 PowerShell to Go, same semantics. | function Get-Gcd($a, $b){
if($a -ge $b){
$dividend = $a
$divisor = $b
}
else{
$dividend = $b
$divisor = $a
}
$leftover = 1
while($leftover -ne 0){
$leftover = $dividend % $divisor
if($leftover -ne 0){
$dividend = $divisor
$divisor = $leftov... | 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 R code in C. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | #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... |
Generate a C translation of this R snippet without changing its computational steps. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | #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 R snippet to C# and keep its semantics consistent. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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; ... |
Transform the following R implementation into C#, maintaining the same output and logic. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 R code into C++ without altering its purpose. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | #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 the following code from R to C++, ensuring the logic remains intact. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | #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;
... |
Rewrite this program in Java while keeping its functionality equivalent to the R version. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 R code. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 R. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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(... |
Preserve the algorithm and functionality while converting the code from R to Python. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 R code. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 this program in VB while keeping its functionality equivalent to the R version. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 R snippet. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 R snippet to Go and keep its semantics consistent. | area <- function(a, b, c) {
s = (a + b + c) / 2
a2 = s*(s-a)*(s-b)*(s-c)
if (a2>0) sqrt(a2) else 0
}
is.heronian <- function(a, b, c) {
h = area(a, b, c)
h > 0 && 0==h%%1
}
gcd <- function(x,y) {
r <- x%%y;
ifelse(r, gcd(y, r), y)
}
gcd3 <- function(x, y, z) {
gcd(gcd(x, y), z)
}
maxsid... | 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 code in C as shown below 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')... | #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... |
Translate this program into C but keep the logic exactly as 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')... | #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... |
Change the following REXX code into C# 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')... | 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; ... |
Ensure the translated C# code behaves exactly like the original REXX snippet. |
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')... | 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; ... |
Maintain the same structure and functionality when rewriting this code in C++. |
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')... | #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;
... |
Rewrite this program in C++ while keeping its functionality equivalent to the REXX version. |
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')... | #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;
... |
Please provide an equivalent version of this REXX code in Java. |
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')... | 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 the same algorithm in Java 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')... | 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 the same code in Python as shown below 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')... | 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(... |
Convert this REXX block to Python, preserving its control flow and logic. |
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')... | 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(... |
Port the provided REXX code into VB while preserving the original functionality. |
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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.