Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Produce a functionally identical C++ code for the snippet given in D.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
#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; ...
Can you help me rewrite this code in C++ instead of D, keeping it the same logically?
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
#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 Java as shown in this D implementation.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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)...
Change the programming language of this snippet from D to Java without modifying what it does.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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 D code into Python while preserving the original functionality.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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 D to Python.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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 D snippet without changing its computational steps.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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...
Keep all operations the same but rewrite the snippet in VB.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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 D to Go.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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 D to Go without modifying what it does.
import std.stdio, std.math, std.range, std.algorithm, std.numeric, std.traits, std.typecons; double hero(in uint a, in uint b, in uint c) pure nothrow @safe @nogc { immutable s = (a + b + c) / 2.0; immutable a2 = s * (s - a) * (s - b) * (s - c); return (a2 > 0) ? a2.sqrt : 0.0; } bool isHeronian(in uint a...
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...
Port the provided Elixir code into C while preserving the original functionality.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
#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 Elixir code snippet into C without altering its behavior.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
#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 Elixir to C#, ensuring the logic remains intact.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Elixir code into C# while preserving the original functionality.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Elixir implementation.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
#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 Elixir.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
#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; ...
Maintain the same structure and functionality when rewriting this code in Java.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Java but keep the logic exactly as in Elixir.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 the following code from Elixir to Python, ensuring the logic remains intact.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Python translation of this Elixir snippet without changing its computational steps.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Elixir code snippet into VB without altering its behavior.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Elixir implementation into VB, maintaining the same output and logic.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Elixir code.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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 Elixir code in Go.
defmodule Heronian do def triangle?(a,b,c) when a+b <= c, do: false def triangle?(a,b,c) do area = area(a,b,c) area == round(area) and primitive?(a,b,c) end def area(a,b,c) do s = (a + b + c) / 2 :math.sqrt(s * (s-a) * (s-b) * (s-c)) end defp primitive?(a,b,c), do: gcd(gcd(a,b),c) == 1...
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...
Port the following code from Factor to C with equivalent syntax and logic.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
#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...
Maintain the same structure and functionality when rewriting this code in C.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
#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 Factor code.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Factor code.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Factor code.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
#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 Factor.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
#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; ...
Generate an equivalent Java version of this Factor code.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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)...
Produce a functionally identical Java code for the snippet given in Factor.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Factor.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Python.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Factor code in VB.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Factor code into VB without altering its purpose.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Factor implementation.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 the following code from Factor to Go, ensuring the logic remains intact.
USING: accessors assocs backtrack combinators.extras combinators.short-circuit formatting io kernel locals math math.functions math.order math.parser math.ranges mirrors qw sequences sorting.slots ; IN: rosetta-code.heronian-triangles TUPLE: triangle a b c area perimeter ; :: area ( a b c -- x ) a b + c + 2 / :> ...
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 Fortran to C#.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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; ...
Can you help me rewrite this code in C# instead of Fortran, keeping it the same logically?
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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 Fortran to C++ without modifying what it does.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
#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 Fortran code in C++.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
#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 Fortran code in C.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
#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 Fortran code into C without altering its purpose.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
#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 Java while keeping its functionality equivalent to the Fortran version.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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)...
Produce a language-to-language conversion: from Fortran to Java, same semantics.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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 Fortran block to Python, preserving its control flow and logic.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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 Fortran code.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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 Fortran, keeping it the same logically?
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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...
Translate the given Fortran code snippet into VB without altering its behavior.
MODULE GREEK MATHEMATICIANS CONTAINS INTEGER FUNCTION GCD(I,J) INTEGER I,J INTEGER N,M,R N = MAX(I,J) M = MIN(I,J) 1 R = MOD(N,M) c write (6,*) "M,N,R",M,N,R IF (R.GT.0) THEN N = M M = R ...
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 Haskell to C, same semantics.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
#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 Haskell to C without modifying what it does.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
#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 Haskell function in C# with identical behavior.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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 Haskell.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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 Haskell snippet.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
#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; ...
Maintain the same structure and functionality when rewriting this code in C++.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
#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 Java as shown in this Haskell implementation.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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 Haskell block to Java, preserving its control flow and logic.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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)...
Can you help me rewrite this code in Python instead of Haskell, keeping it the same logically?
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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 Python translation of this Haskell snippet without changing its computational steps.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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(...
Change the following Haskell code into VB without altering its purpose.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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 VB so it works the same as the original Haskell code.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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...
Generate an equivalent Go version of this Haskell code.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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...
Ensure the translated Go code behaves exactly like the original Haskell snippet.
import qualified Data.List as L import Data.Maybe import Data.Ord import Text.Printf perfectSqrt :: Integral a => a -> Maybe a perfectSqrt n | n == 1 = Just 1 | n < 4 = Nothing | otherwise = let search low high = let guess = (low + high) `div` 2 square = guess ^ 2 next ...
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 J implementation.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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...
Port the following code from J to C with equivalent syntax and logic.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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...
Rewrite this program in C# while keeping its functionality equivalent to the J version.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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; ...
Rewrite the snippet below in C# so it works the same as the original J code.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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; ...
Write the same code in C++ as shown below in J.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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; ...
Translate this program into C++ but keep the logic exactly as in J.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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; ...
Transform the following J implementation into Java, maintaining the same output and logic.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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)...
Can you help me rewrite this code in Java instead of J, keeping it the same logically?
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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 J implementation into Python, maintaining the same output and logic.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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(...
Generate an equivalent Python version of this J code.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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(...
Write a version of this J function in VB with identical behavior.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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...
Maintain the same structure and functionality when rewriting this code in VB.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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 algorithm in Go as shown in this J implementation.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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...
Convert this J block to Go, preserving its control flow and logic.
a=: 0&{"1 b=: 1&{"1 c=: 2&{"1 s=: (a+b+c) % 2: area=: 2 %: s*(s-a)*(s-b)*(s-c) perim=: +/"1 isPrimHero=: (0&~: * (= <.@:+))@area * 1 = 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...
Keep all operations the same but rewrite the snippet in C.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
#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...
Port the following code from Julia to C with equivalent syntax and logic.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
#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 Julia code.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 the following code from Julia to C#, ensuring the logic remains intact.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 this program in C++ while keeping its functionality equivalent to the Julia version.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
#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 Julia to C++, ensuring the logic remains intact.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
#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; ...
Change the following Julia code into Java without altering its purpose.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 Julia to Java with equivalent syntax and logic.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 the given Julia code snippet into Python without altering its behavior.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 Python version of this Julia code.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 VB while keeping its functionality equivalent to the Julia version.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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...
Generate a VB translation of this Julia snippet without changing its computational steps.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 Julia.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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.
type IntegerTriangle{T<:Integer} a::T b::T c::T p::T σ::T end function IntegerTriangle{T<:Integer}(a::T, b::T, c::T) p = a + b + c s = div(p, 2) σ = isqrt(s*(s-a)*(s-b)*(s-c)) (x, y, z) = sort([a, b, c]) IntegerTriangle(x, y, z, p, σ) end function isprimheronian{T<:Integer}(a::...
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 Lua block to C, preserving its control flow and logic.
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 = ...
#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...
Transform the following Lua implementation into C, maintaining the same output and logic.
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 = ...
#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 Lua to C#, ensuring the logic remains intact.
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 = ...
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 a version of this Lua function in C# 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 = ...
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 Lua snippet.
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 = ...
#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 Lua to C++, ensuring the logic remains intact.
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 = ...
#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 Lua code in Java.
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 = ...
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.
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 = ...
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)...