Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Rewrite this program in C# while keeping its functionality equivalent to the Nim version. | import random, tables
proc dice5(): int = rand(1..5)
proc dice7(): int =
while true:
let val = 5 * dice5() + dice5() - 6
if val < 21:
return val div 3 + 1
proc checkDist(f: proc(): int; repeat: Positive; tolerance: float) =
var counts: CountTable[int]
for _ in 1..repeat:
counts.inc f()
... | using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Write a version of this Nim function in C++ with identical behavior. | import random, tables
proc dice5(): int = rand(1..5)
proc dice7(): int =
while true:
let val = 5 * dice5() + dice5() - 6
if val < 21:
return val div 3 + 1
proc checkDist(f: proc(): int; repeat: Positive; tolerance: float) =
var counts: CountTable[int]
for _ in 1..repeat:
counts.inc f()
... | template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Generate a Java translation of this Nim snippet without changing its computational steps. | import random, tables
proc dice5(): int = rand(1..5)
proc dice7(): int =
while true:
let val = 5 * dice5() + dice5() - 6
if val < 21:
return val div 3 + 1
proc checkDist(f: proc(): int; repeat: Positive; tolerance: float) =
var counts: CountTable[int]
for _ in 1..repeat:
counts.inc f()
... | import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Preserve the algorithm and functionality while converting the code from Nim to Python. | import random, tables
proc dice5(): int = rand(1..5)
proc dice7(): int =
while true:
let val = 5 * dice5() + dice5() - 6
if val < 21:
return val div 3 + 1
proc checkDist(f: proc(): int; repeat: Positive; tolerance: float) =
var counts: CountTable[int]
for _ in 1..repeat:
counts.inc f()
... | from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Ensure the translated VB code behaves exactly like the original Nim snippet. | import random, tables
proc dice5(): int = rand(1..5)
proc dice7(): int =
while true:
let val = 5 * dice5() + dice5() - 6
if val < 21:
return val div 3 + 1
proc checkDist(f: proc(): int; repeat: Positive; tolerance: float) =
var counts: CountTable[int]
for _ in 1..repeat:
counts.inc f()
... | Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Produce a language-to-language conversion: from Nim to Go, same semantics. | import random, tables
proc dice5(): int = rand(1..5)
proc dice7(): int =
while true:
let val = 5 * dice5() + dice5() - 6
if val < 21:
return val div 3 + 1
proc checkDist(f: proc(): int; repeat: Positive; tolerance: float) =
var counts: CountTable[int]
for _ in 1..repeat:
counts.inc f()
... | package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Change the programming language of this snippet from OCaml to C without modifying what it does. | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dice... | int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Convert the following code from OCaml to C#, ensuring the logic remains intact. | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dice... | using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Can you help me rewrite this code in C++ instead of OCaml, keeping it the same logically? | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dice... | template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Convert this OCaml block to Java, preserving its control flow and logic. | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dice... | import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Convert the following code from OCaml to Python, ensuring the logic remains intact. | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dice... | from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Ensure the translated VB code behaves exactly like the original OCaml snippet. | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dice... | Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Convert this OCaml block to Go, preserving its control flow and logic. | let dice5() = 1 + Random.int 5 ;;
let dice7 =
let rolls2answer = Hashtbl.create 25 in
let n = ref 0 in
for roll1 = 1 to 5 do
for roll2 = 1 to 5 do
Hashtbl.add rolls2answer (roll1,roll2) (!n / 3 +1);
incr n
done;
done;
let rec aux() =
let trial = Hashtbl.find rolls2answer (dice5(),dice... | package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Rewrite the snippet below in C so it works the same as the original Pascal code. | unit UConverter;
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..19] of integer;
fBufCount, fBufPtr : integer;
fDice5 : TDice5;
fNrDice5 : int64;
public
constructor Create( aDice5 : TDice5);
procedure Rese... | int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Transform the following Pascal implementation into C#, maintaining the same output and logic. | unit UConverter;
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..19] of integer;
fBufCount, fBufPtr : integer;
fDice5 : TDice5;
fNrDice5 : int64;
public
constructor Create( aDice5 : TDice5);
procedure Rese... | using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Produce a language-to-language conversion: from Pascal to C++, same semantics. | unit UConverter;
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..19] of integer;
fBufCount, fBufPtr : integer;
fDice5 : TDice5;
fNrDice5 : int64;
public
constructor Create( aDice5 : TDice5);
procedure Rese... | template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Produce a functionally identical Java code for the snippet given in Pascal. | unit UConverter;
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..19] of integer;
fBufCount, fBufPtr : integer;
fDice5 : TDice5;
fNrDice5 : int64;
public
constructor Create( aDice5 : TDice5);
procedure Rese... | import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Convert this Pascal block to Python, preserving its control flow and logic. | unit UConverter;
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..19] of integer;
fBufCount, fBufPtr : integer;
fDice5 : TDice5;
fNrDice5 : int64;
public
constructor Create( aDice5 : TDice5);
procedure Rese... | from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Rewrite this program in VB while keeping its functionality equivalent to the Pascal version. | unit UConverter;
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..19] of integer;
fBufCount, fBufPtr : integer;
fDice5 : TDice5;
fNrDice5 : int64;
public
constructor Create( aDice5 : TDice5);
procedure Rese... | Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Ensure the translated Go code behaves exactly like the original Pascal snippet. | unit UConverter;
interface
type
TFace5 = 1..5;
TFace7 = 1..7;
TDice5 = function() : TFace5;
type TConverter = class( TObject)
private
fDigitBuf: array [0..19] of integer;
fBufCount, fBufPtr : integer;
fDice5 : TDice5;
fNrDice5 : int64;
public
constructor Create( aDice5 : TDice5);
procedure Rese... | package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Convert the following code from Perl to C, ensuring the logic remains intact. | sub dice5 { 1+int rand(5) }
sub dice7 {
while(1) {
my $d7 = (5*dice5()+dice5()-6) % 8;
return $d7 if $d7;
}
}
my %count7;
my $n = 1000000;
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
| int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Keep all operations the same but rewrite the snippet in C#. | sub dice5 { 1+int rand(5) }
sub dice7 {
while(1) {
my $d7 = (5*dice5()+dice5()-6) % 8;
return $d7 if $d7;
}
}
my %count7;
my $n = 1000000;
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
| using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Rewrite the snippet below in Java so it works the same as the original Perl code. | sub dice5 { 1+int rand(5) }
sub dice7 {
while(1) {
my $d7 = (5*dice5()+dice5()-6) % 8;
return $d7 if $d7;
}
}
my %count7;
my $n = 1000000;
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
| import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Please provide an equivalent version of this Perl code in Python. | sub dice5 { 1+int rand(5) }
sub dice7 {
while(1) {
my $d7 = (5*dice5()+dice5()-6) % 8;
return $d7 if $d7;
}
}
my %count7;
my $n = 1000000;
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
| from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Convert this Perl snippet to VB and keep its semantics consistent. | sub dice5 { 1+int rand(5) }
sub dice7 {
while(1) {
my $d7 = (5*dice5()+dice5()-6) % 8;
return $d7 if $d7;
}
}
my %count7;
my $n = 1000000;
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
| Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Rewrite this program in Go while keeping its functionality equivalent to the Perl version. | sub dice5 { 1+int rand(5) }
sub dice7 {
while(1) {
my $d7 = (5*dice5()+dice5()-6) % 8;
return $d7 if $d7;
}
}
my %count7;
my $n = 1000000;
$count7{dice7()}++ for 1..$n;
printf "%s: %5.2f%%\n", $_, 100*($count7{$_}/$n*7-1) for sort keys %count7;
| package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Write a version of this R function in C with identical behavior. | dice5 <- function(n=1) sample(5, n, replace=TRUE)
| int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Produce a functionally identical C# code for the snippet given in R. | dice5 <- function(n=1) sample(5, n, replace=TRUE)
| using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Can you help me rewrite this code in C++ instead of R, keeping it the same logically? | dice5 <- function(n=1) sample(5, n, replace=TRUE)
| template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Maintain the same structure and functionality when rewriting this code in Java. | dice5 <- function(n=1) sample(5, n, replace=TRUE)
| import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Rewrite the snippet below in Python so it works the same as the original R code. | dice5 <- function(n=1) sample(5, n, replace=TRUE)
| from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Change the following R code into VB without altering its purpose. | dice5 <- function(n=1) sample(5, n, replace=TRUE)
| Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Convert this R snippet to Go and keep its semantics consistent. | dice5 <- function(n=1) sample(5, n, replace=TRUE)
| package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Can you help me rewrite this code in C instead of Racket, keeping it the same logically? | #lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
| int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Write a version of this Racket function in C# with identical behavior. | #lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
| using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Can you help me rewrite this code in C++ instead of Racket, keeping it the same logically? | #lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
| template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Produce a language-to-language conversion: from Racket to Java, same semantics. | #lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
| import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Change the programming language of this snippet from Racket to Python without modifying what it does. | #lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
| from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Port the provided Racket code into VB while preserving the original functionality. | #lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
| Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Change the following Racket code into Go without altering its purpose. | #lang racket
(define (dice5) (add1 (random 5)))
(define (dice7)
(define res (+ (* 5 (dice5)) (dice5) -6))
(if (< res 21) (+ 1 (modulo res 7)) (dice7)))
| package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Convert the following code from REXX to C, ensuring the logic remains intact. |
parse arg trials sample seed .
if trials=='' | trials="," then trials= 1
if sample=='' | sample="," then sample= 1000000
if datatype(seed, 'W') then call random ,,seed
L= length(trials)
do #=1 for trials; die.= 0
k= 0
... | int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Convert this REXX snippet to C# and keep its semantics consistent. |
parse arg trials sample seed .
if trials=='' | trials="," then trials= 1
if sample=='' | sample="," then sample= 1000000
if datatype(seed, 'W') then call random ,,seed
L= length(trials)
do #=1 for trials; die.= 0
k= 0
... | using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Rewrite the snippet below in C++ so it works the same as the original REXX code. |
parse arg trials sample seed .
if trials=='' | trials="," then trials= 1
if sample=='' | sample="," then sample= 1000000
if datatype(seed, 'W') then call random ,,seed
L= length(trials)
do #=1 for trials; die.= 0
k= 0
... | template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Port the following code from REXX to Java with equivalent syntax and logic. |
parse arg trials sample seed .
if trials=='' | trials="," then trials= 1
if sample=='' | sample="," then sample= 1000000
if datatype(seed, 'W') then call random ,,seed
L= length(trials)
do #=1 for trials; die.= 0
k= 0
... | import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Produce a functionally identical Python code for the snippet given in REXX. |
parse arg trials sample seed .
if trials=='' | trials="," then trials= 1
if sample=='' | sample="," then sample= 1000000
if datatype(seed, 'W') then call random ,,seed
L= length(trials)
do #=1 for trials; die.= 0
k= 0
... | from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Convert this REXX snippet to VB and keep its semantics consistent. |
parse arg trials sample seed .
if trials=='' | trials="," then trials= 1
if sample=='' | sample="," then sample= 1000000
if datatype(seed, 'W') then call random ,,seed
L= length(trials)
do #=1 for trials; die.= 0
k= 0
... | Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Generate an equivalent Go version of this REXX code. |
parse arg trials sample seed .
if trials=='' | trials="," then trials= 1
if sample=='' | sample="," then sample= 1000000
if datatype(seed, 'W') then call random ,,seed
L= length(trials)
do #=1 for trials; die.= 0
k= 0
... | package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Produce a language-to-language conversion: from Ruby to C, same semantics. | require './distcheck.rb'
def d5
1 + rand(5)
end
def d7
loop do
d55 = 5*d5 + d5 - 6
return (d55 % 7 + 1) if d55 < 21
end
end
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}
| int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Can you help me rewrite this code in C# instead of Ruby, keeping it the same logically? | require './distcheck.rb'
def d5
1 + rand(5)
end
def d7
loop do
d55 = 5*d5 + d5 - 6
return (d55 % 7 + 1) if d55 < 21
end
end
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}
| using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Generate a C++ translation of this Ruby snippet without changing its computational steps. | require './distcheck.rb'
def d5
1 + rand(5)
end
def d7
loop do
d55 = 5*d5 + d5 - 6
return (d55 % 7 + 1) if d55 < 21
end
end
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}
| template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Convert the following code from Ruby to Java, ensuring the logic remains intact. | require './distcheck.rb'
def d5
1 + rand(5)
end
def d7
loop do
d55 = 5*d5 + d5 - 6
return (d55 % 7 + 1) if d55 < 21
end
end
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}
| import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Convert this Ruby block to Python, preserving its control flow and logic. | require './distcheck.rb'
def d5
1 + rand(5)
end
def d7
loop do
d55 = 5*d5 + d5 - 6
return (d55 % 7 + 1) if d55 < 21
end
end
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}
| from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Please provide an equivalent version of this Ruby code in VB. | require './distcheck.rb'
def d5
1 + rand(5)
end
def d7
loop do
d55 = 5*d5 + d5 - 6
return (d55 % 7 + 1) if d55 < 21
end
end
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}
| Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Keep all operations the same but rewrite the snippet in Go. | require './distcheck.rb'
def d5
1 + rand(5)
end
def d7
loop do
d55 = 5*d5 + d5 - 6
return (d55 % 7 + 1) if d55 < 21
end
end
distcheck(1_000_000) {d5}
distcheck(1_000_000) {d7}
| package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Convert the following code from Scala to C, ensuring the logic remains intact. |
import java.util.Random
val r = Random()
fun dice5() = 1 + r.nextInt(5)
fun dice7(): Int {
while (true) {
val t = (dice5() - 1) * 5 + dice5() - 1
if (t >= 21) continue
return 1 + t / 3
}
}
fun checkDist(gen: () -> Int, nRepeats: Int, tolerance: Double = 0.5) {
val occurs = mutable... | int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Write the same code in C# as shown below in Scala. |
import java.util.Random
val r = Random()
fun dice5() = 1 + r.nextInt(5)
fun dice7(): Int {
while (true) {
val t = (dice5() - 1) * 5 + dice5() - 1
if (t >= 21) continue
return 1 + t / 3
}
}
fun checkDist(gen: () -> Int, nRepeats: Int, tolerance: Double = 0.5) {
val occurs = mutable... | using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Please provide an equivalent version of this Scala code in C++. |
import java.util.Random
val r = Random()
fun dice5() = 1 + r.nextInt(5)
fun dice7(): Int {
while (true) {
val t = (dice5() - 1) * 5 + dice5() - 1
if (t >= 21) continue
return 1 + t / 3
}
}
fun checkDist(gen: () -> Int, nRepeats: Int, tolerance: Double = 0.5) {
val occurs = mutable... | template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Please provide an equivalent version of this Scala code in Java. |
import java.util.Random
val r = Random()
fun dice5() = 1 + r.nextInt(5)
fun dice7(): Int {
while (true) {
val t = (dice5() - 1) * 5 + dice5() - 1
if (t >= 21) continue
return 1 + t / 3
}
}
fun checkDist(gen: () -> Int, nRepeats: Int, tolerance: Double = 0.5) {
val occurs = mutable... | import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Produce a language-to-language conversion: from Scala to Python, same semantics. |
import java.util.Random
val r = Random()
fun dice5() = 1 + r.nextInt(5)
fun dice7(): Int {
while (true) {
val t = (dice5() - 1) * 5 + dice5() - 1
if (t >= 21) continue
return 1 + t / 3
}
}
fun checkDist(gen: () -> Int, nRepeats: Int, tolerance: Double = 0.5) {
val occurs = mutable... | from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Change the programming language of this snippet from Scala to VB without modifying what it does. |
import java.util.Random
val r = Random()
fun dice5() = 1 + r.nextInt(5)
fun dice7(): Int {
while (true) {
val t = (dice5() - 1) * 5 + dice5() - 1
if (t >= 21) continue
return 1 + t / 3
}
}
fun checkDist(gen: () -> Int, nRepeats: Int, tolerance: Double = 0.5) {
val occurs = mutable... | Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Convert this Scala snippet to Go and keep its semantics consistent. |
import java.util.Random
val r = Random()
fun dice5() = 1 + r.nextInt(5)
fun dice7(): Int {
while (true) {
val t = (dice5() - 1) * 5 + dice5() - 1
if (t >= 21) continue
return 1 + t / 3
}
}
fun checkDist(gen: () -> Int, nRepeats: Int, tolerance: Double = 0.5) {
val occurs = mutable... | package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Maintain the same structure and functionality when rewriting this code in C. | proc D5 {} {expr {1 + int(5 * rand())}}
proc D7 {} {
while 1 {
set d55 [expr {5 * [D5] + [D5] - 6}]
if {$d55 < 21} {
return [expr {$d55 % 7 + 1}]
}
}
}
| int rand5()
{
int r, rand_max = RAND_MAX - (RAND_MAX % 5);
while ((r = rand()) >= rand_max);
return r / (rand_max / 5) + 1;
}
int rand5_7()
{
int r;
while ((r = rand5() * 5 + rand5()) >= 27);
return r / 3 - 1;
}
int main()
{
printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n");
printf(check(rand7,... |
Produce a functionally identical C# code for the snippet given in Tcl. | proc D5 {} {expr {1 + int(5 * rand())}}
proc D7 {} {
while 1 {
set d55 [expr {5 * [D5] + [D5] - 6}]
if {$d55 < 21} {
return [expr {$d55 % 7 + 1}]
}
}
}
| using System;
public class SevenSidedDice
{
Random random = new Random();
static void Main(string[] args)
{
SevenSidedDice sevenDice = new SevenSidedDice();
Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven());
Console.Read();
}
int seven()
{
int v=21;
w... |
Can you help me rewrite this code in C++ instead of Tcl, keeping it the same logically? | proc D5 {} {expr {1 + int(5 * rand())}}
proc D7 {} {
while 1 {
set d55 [expr {5 * [D5] + [D5] - 6}]
if {$d55 < 21} {
return [expr {$d55 % 7 + 1}]
}
}
}
| template<typename F> class fivetoseven
{
public:
fivetoseven(F f): d5(f), rem(0), max(1) {}
int operator()();
private:
F d5;
int rem, max;
};
template<typename F>
int fivetoseven<F>::operator()()
{
while (rem/7 == max/7)
{
while (max < 7)
{
int rand5 = d5()-1;
max *= 5;
rem = 5*r... |
Maintain the same structure and functionality when rewriting this code in Java. | proc D5 {} {expr {1 + int(5 * rand())}}
proc D7 {} {
while 1 {
set d55 [expr {5 * [D5] + [D5] - 6}]
if {$d55 < 21} {
return [expr {$d55 % 7 + 1}]
}
}
}
| import java.util.Random;
public class SevenSidedDice
{
private static final Random rnd = new Random();
public static void main(String[] args)
{
SevenSidedDice now=new SevenSidedDice();
System.out.println("Random number from 1 to 7: "+now.seven());
}
int seven()
{
int v=21;
while(v>20)
v=five()+five()*... |
Please provide an equivalent version of this Tcl code in Python. | proc D5 {} {expr {1 + int(5 * rand())}}
proc D7 {} {
while 1 {
set d55 [expr {5 * [D5] + [D5] - 6}]
if {$d55 < 21} {
return [expr {$d55 % 7 + 1}]
}
}
}
| from random import randint
def dice5():
return randint(1, 5)
def dice7():
r = dice5() + dice5() * 5 - 6
return (r % 7) + 1 if r < 21 else dice7()
|
Write a version of this Tcl function in VB with identical behavior. | proc D5 {} {expr {1 + int(5 * rand())}}
proc D7 {} {
while 1 {
set d55 [expr {5 * [D5] + [D5] - 6}]
if {$d55 < 21} {
return [expr {$d55 % 7 + 1}]
}
}
}
| Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean
Dim Total As Long, Ei As Long, i As Integer
Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double
Debug.Print "[1] ""Data set:"" ";
For i = LBound(Observation... |
Produce a language-to-language conversion: from Tcl to Go, same semantics. | proc D5 {} {expr {1 + int(5 * rand())}}
proc D7 {} {
while 1 {
set d55 [expr {5 * [D5] + [D5] - 6}]
if {$d55 < 21} {
return [expr {$d55 % 7 + 1}]
}
}
}
| package main
import (
"fmt"
"math"
"math/rand"
"time"
)
func dice5() int {
return rand.Intn(5) + 1
}
func dice7() (i int) {
for {
i = 5*dice5() + dice5()
if i < 27 {
break
}
}
return (i / 3) - 1
}
func distCheck(f func() int, n int,
... |
Port the provided Ada code into C# while preserving the original functionality. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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 Ada snippet. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | #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 Ada snippet without changing its computational steps. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | #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 Ada implementation into C++, maintaining the same output and logic. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | #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 Ada, keeping it the same logically? | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | #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 Ada block to Go, preserving its control flow and logic. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | package main
import (
"fmt"
"math"
"sort"
)
const (
n = 200
header = "\nSides P A"
)
func gcd(a, b int) int {
leftover := 1
var dividend, divisor int
if (a > b) { dividend, divisor = a, b } else { dividend, divisor = b, a }
for (leftover != 0) {
leftover = divi... |
Rewrite the snippet below in Go so it works the same as the original Ada code. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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 Ada code in Java. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | import java.util.ArrayList;
public class Heron {
public static void main(String[] args) {
ArrayList<int[]> list = new ArrayList<>();
for (int c = 1; c <= 200; c++) {
for (int b = 1; b <= c; b++) {
for (int a = 1; a <= b; a++) {
if (gcd(gcd(a, b), c)... |
Generate an equivalent Java version of this Ada code. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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 following Ada code into Python without altering its purpose. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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 Ada code snippet into Python without altering its behavior. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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 Ada code snippet into VB without altering its behavior. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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 Ada implementation into VB, maintaining the same output and logic. | with Ada.Containers.Indefinite_Ordered_Sets;
with Ada.Finalization;
with Ada.Text_IO; use Ada.Text_IO;
procedure Heronian is
package Int_IO is new Ada.Text_IO.Integer_IO(Integer);
use Int_IO;
function GCD (A, B : in Natural) return Natural is (if B = 0 then A else GCD (B, A mod B));
function Int... | 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 C as shown in this AutoHotKey implementation. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | #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 AutoHotKey code snippet into C without altering its behavior. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | #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... |
Preserve the algorithm and functionality while converting the code from AutoHotKey to C#. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | 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 AutoHotKey. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | 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 AutoHotKey snippet. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | #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 C++ version of this AutoHotKey code. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | #include <algorithm>
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>
int gcd(int a, int b)
{
int rem = 1, dividend, divisor;
std::tie(divisor, dividend) = std::minmax(a, b);
while (rem != 0) {
rem = dividend % divisor;
if (rem != 0) {
dividend = divisor;
... |
Port the following code from AutoHotKey to Java with equivalent syntax and logic. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | 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 AutoHotKey code. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | 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 AutoHotKey block to Python, preserving its control flow and logic. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | 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 AutoHotKey version. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | from __future__ import division, print_function
from math import gcd, sqrt
def hero(a, b, c):
s = (a + b + c) / 2
a2 = s * (s - a) * (s - b) * (s - c)
return sqrt(a2) if a2 > 0 else 0
def is_heronian(a, b, c):
a = hero(a, b, c)
return a > 0 and a.is_integer()
def gcd3(x, y, z):
return gcd(... |
Transform the following AutoHotKey implementation into VB, maintaining the same output and logic. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Convert the following code from AutoHotKey to VB, ensuring the logic remains intact. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | Function heroArea(a As Integer, b As Integer, c As Integer) As Double
s = (a + b + c) / 2
On Error GoTo Err
heroArea = Sqr(s * (s - a) * (s - b) * (s - c))
Exit Function
Err:
heroArea = -1
End Function
Function hero(h As Double) As Boolean
hero = (h - Int(h) = 0) And h > 0
End Function
Publi... |
Write the same code in Go as shown below in AutoHotKey. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | 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 AutoHotKey to Go with equivalent syntax and logic. | Primitive_Heronian_triangles(MaxSide){
obj :=[]
loop, % MaxSide {
a := A_Index
loop % MaxSide-a+1 {
b := A_Index+a-1
loop % MaxSide-b+1 {
c := A_Index+b-1, s := (a+b+c)/2, Area := Sqrt(s*(s-a)*(s-b)*(s-c))
if (Area = Floor(Area)) && (Area>0) && !obj[a/s, b/s, c/s]
obj[a/s, b/s, c/s]:=1 ,res .= ... | 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 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... | #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 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<stdlib.h>
#include<stdio.h>
#include<math.h>
typedef struct{
int a,b,c;
int perimeter;
double area;
}triangle;
typedef struct elem{
triangle t;
struct elem* next;
}cell;
typedef cell* list;
void addAndOrderList(list *a,triangle t){
list iter,temp;
int flag = 0;
if(*a==NULL){
*a = (list)malloc(s... |
Write the same code in C# as shown below in 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... | 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 D code into C# without altering its purpose. | 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... | 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; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.