Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Convert this OCaml block to C++, preserving its control flow and logic. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Generate an equivalent Java version of this OCaml code. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Generate an equivalent Java version of this OCaml code. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Change the programming language of this snippet from OCaml to Python without modifying what it does. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Translate this program into Python but keep the logic exactly as in OCaml. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Maintain the same structure and functionality when rewriting this code in VB. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Convert this OCaml snippet to VB and keep its semantics consistent. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Port the provided OCaml code into Go while preserving the original functionality. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Write a version of this OCaml function in Go with identical behavior. | let pi = 3, fun n -> ((2*n-1)*(2*n-1), 6)
and nap = 2, fun n -> (max 1 (n-1), n)
and root2 = 1, fun n -> (1, 2) in
let eval (i,f) k =
let rec frac n =
let a, b = f n in
float a /. (float b +.
if n >= k then 0.0 else frac (n+1)) in
float i +. frac 1 in
Printf.printf "sqrt(2)\t= %.15f\n" (eval root2 1... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Generate a C translation of this Pascal snippet without changing its computational steps. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Ensure the translated C code behaves exactly like the original Pascal snippet. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Can you help me rewrite this code in C# instead of Pascal, keeping it the same logically? | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Rewrite this program in C# while keeping its functionality equivalent to the Pascal version. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Write the same algorithm in C++ as shown in this Pascal implementation. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Transform the following Pascal implementation into C++, maintaining the same output and logic. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Can you help me rewrite this code in Java instead of Pascal, keeping it the same logically? | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Produce a language-to-language conversion: from Pascal to Java, same semantics. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Convert this Pascal block to Python, preserving its control flow and logic. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Ensure the translated Python code behaves exactly like the original Pascal snippet. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Transform the following Pascal implementation into VB, maintaining the same output and logic. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Maintain the same structure and functionality when rewriting this code in VB. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Translate this program into Go but keep the logic exactly as in Pascal. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Convert this Pascal block to Go, preserving its control flow and logic. | program ContFrac_console;
uses
SysUtils;
type TCoeffFunction = function( n : integer) : extended;
procedure CalcContFrac( a, b : TCoeffFunction;
epsilon : extended;
maxNrTerms : integer = 1000);
var
n : integer;
sum, term, u, v : extended;
whyStopped : st... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Maintain the same structure and functionality when rewriting this code in C. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Produce a functionally identical C code for the snippet given in Perl. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Convert this Perl snippet to C# and keep its semantics consistent. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Maintain the same structure and functionality when rewriting this code in C#. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Write the same code in C++ as shown below in Perl. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Ensure the translated C++ code behaves exactly like the original Perl snippet. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Port the following code from Perl to Java with equivalent syntax and logic. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Write the same code in Java as shown below in Perl. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Write a version of this Perl function in Python with identical behavior. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Transform the following Perl implementation into Python, maintaining the same output and logic. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Please provide an equivalent version of this Perl code in VB. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Preserve the algorithm and functionality while converting the code from Perl to VB. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Generate a Go translation of this Perl snippet without changing its computational steps. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Transform the following Perl implementation into Go, maintaining the same output and logic. | use strict;
use warnings;
no warnings 'recursion';
use experimental 'signatures';
sub continued_fraction ($a, $b, $n = 100) {
$a->() + ($n and $b->() / continued_fraction($a, $b, $n-1));
}
printf "√2 ≈ %.9f\n", continued_fraction do { my $n; sub { $n++ ? 2 : 1 } }, sub { 1 };
printf... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Convert the following code from Racket to C, ensuring the logic remains intact. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Write the same code in C as shown below in Racket. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Transform the following Racket implementation into C#, maintaining the same output and logic. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Ensure the translated C# code behaves exactly like the original Racket snippet. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Port the provided Racket code into C++ while preserving the original functionality. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Change the following Racket code into C++ without altering its purpose. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Keep all operations the same but rewrite the snippet in Java. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Produce a language-to-language conversion: from Racket to Java, same semantics. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Generate a Python translation of this Racket snippet without changing its computational steps. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Translate the given Racket code snippet into Python without altering its behavior. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Change the following Racket code into VB without altering its purpose. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Preserve the algorithm and functionality while converting the code from Racket to VB. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Can you help me rewrite this code in Go instead of Racket, keeping it the same logically? | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Transform the following Racket implementation into Go, maintaining the same output and logic. | #lang racket
(define (calc cf n)
(match/values (cf 0)
[(a0 b0)
(+ a0
(for/fold ([t 0.0]) ([i (in-range (+ n 1) 0 -1)])
(match/values (cf i)
[(a b) (/ b (+ a t))])))]))
(define (cf-sqrt i) (values (if (> i 0) 2 1) 1))
(define (cf-napier i) (values (if (> i 0) i ... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Write the same code in C as shown below in COBOL. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Rewrite the snippet below in C so it works the same as the original COBOL code. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Rewrite this program in C# while keeping its functionality equivalent to the COBOL version. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Ensure the translated C# code behaves exactly like the original COBOL snippet. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Write the same algorithm in C++ as shown in this COBOL implementation. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Translate this program into C++ but keep the logic exactly as in COBOL. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Maintain the same structure and functionality when rewriting this code in Java. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Maintain the same structure and functionality when rewriting this code in Java. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Please provide an equivalent version of this COBOL code in Python. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Change the programming language of this snippet from COBOL to Python without modifying what it does. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Preserve the algorithm and functionality while converting the code from COBOL to VB. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Write a version of this COBOL function in VB with identical behavior. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Change the programming language of this snippet from COBOL to Go without modifying what it does. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Produce a functionally identical Go code for the snippet given in COBOL. | identification division.
program-id. show-continued-fractions.
environment division.
configuration section.
repository.
function continued-fractions
function all intrinsic.
procedure division.
fractions-main.
display "Square root 2 approxi... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Ensure the translated C code behaves exactly like the original REXX snippet. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Rewrite the snippet below in C so it works the same as the original REXX code. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Port the provided REXX code into C# while preserving the original functionality. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Write the same algorithm in C# as shown in this REXX implementation. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Generate a C++ translation of this REXX snippet without changing its computational steps. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Translate this program into C++ but keep the logic exactly as in REXX. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Keep all operations the same but rewrite the snippet in Java. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Transform the following REXX implementation into Java, maintaining the same output and logic. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Please provide an equivalent version of this REXX code in Python. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Write a version of this REXX function in Python with identical behavior. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Please provide an equivalent version of this REXX code in VB. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Write a version of this REXX function in VB with identical behavior. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Can you help me rewrite this code in Go instead of REXX, keeping it the same logically? |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Ensure the translated Go code behaves exactly like the original REXX snippet. |
* Derived from REXX ... Derived from PL/I with a little "massage"
* SQRT2= 1.41421356237309505 <- PL/I Result
* 1.41421356237309504880168872421 <- NetRexx Result 30 digits
* NAPIER= 2.71828182845904524
* 2.71828182845904523536028747135
* PI= 3.14159262280484695
* 3.1415926228... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Preserve the algorithm and functionality while converting the code from Ruby to C. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Rewrite the snippet below in C so it works the same as the original Ruby code. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Rewrite the snippet below in C# so it works the same as the original Ruby code. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Maintain the same structure and functionality when rewriting this code in C#. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Write a version of this Ruby function in C++ with identical behavior. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Can you help me rewrite this code in C++ instead of Ruby, keeping it the same logically? | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Write the same code in Java as shown below in Ruby. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Convert the following code from Ruby to Java, ensuring the logic remains intact. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Rewrite the snippet below in Python so it works the same as the original Ruby code. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Write a version of this Ruby function in Python with identical behavior. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | from fractions import Fraction
import itertools
try: zip = itertools.izip
except: pass
def CF(a, b, t):
terms = list(itertools.islice(zip(a, b), t))
z = Fraction(1,1)
for a, b in reversed(terms):
z = a + b / z
return z
def pRes(x, d):
q, x = divmod(x, 1)
res = str(q)
res += "."
for i in range(... |
Port the following code from Ruby to VB with equivalent syntax and logic. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Change the programming language of this snippet from Ruby to VB without modifying what it does. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | Public Const precision = 10000
Private Function continued_fraction(steps As Integer, rid_a As String, rid_b As String) As Double
Dim res As Double
res = 0
For n = steps To 1 Step -1
res = Application.Run(rid_b, n) / (Application.Run(rid_a, n) + res)
Next n
continued_fraction = Application.Run... |
Write the same algorithm in Go as shown in this Ruby implementation. | require 'bigdecimal'
sqrt2 = Object.new
def sqrt2.a(n); n == 1 ? 1 : 2; end
def sqrt2.b(n); 1; end
napier = Object.new
def napier.a(n); n == 1 ? 2 : n - 1; end
def napier.b(n); n == 1 ? 1 : n - 1; end
pi = Object.new
def pi.a(n); n == 1 ? 3 : 6; end
def pi.b(n); (2*n - 1)**2; end
def estimate(cfrac, prec)
la... | package main
import "fmt"
type cfTerm struct {
a, b int
}
type cf []cfTerm
func cfSqrt2(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] = cfTerm{2, 1}
}
f[0].a = 1
return f
}
func cfNap(nTerms int) cf {
f := make(cf, nTerms)
for n := range f {
f[n] =... |
Produce a language-to-language conversion: from Scala to C, same semantics. |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Maintain the same structure and functionality when rewriting this code in C. |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... |
#include <stdio.h>
typedef double (*coeff_func)(unsigned n);
double calc(coeff_func f_a, coeff_func f_b, unsigned expansions)
{
double a, b, r;
a = b = r = 0.0;
unsigned i;
for (i = expansions; i > 0; i--) {
a = f_a(i);
b = f_b(i);
r = b / (a + r);
}
a = f_a(0);
return a + r;
}
double sqrt2_a(unsi... |
Convert the following code from Scala to C#, ensuring the logic remains intact. |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Rewrite the snippet below in C# so it works the same as the original Scala code. |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... | using System;
using System.Collections.Generic;
namespace ContinuedFraction {
class Program {
static double Calc(Func<int, int[]> f, int n) {
double temp = 0.0;
for (int ni = n; ni >= 1; ni--) {
int[] p = f(ni);
temp = p[1] / (p[0] + temp);
... |
Convert this Scala block to C++, preserving its control flow and logic. |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Write the same algorithm in C++ as shown in this Scala implementation. |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... | #include <iomanip>
#include <iostream>
#include <tuple>
typedef std::tuple<double,double> coeff_t;
typedef coeff_t (*func_t)(int);
double calc(func_t func, int n)
{
double a, b, temp = 0;
for (; n > 0; --n) {
std::tie(a, b) = func(n);
temp = b / (a + temp);
}
std::tie(a, b) = func(0)... |
Can you help me rewrite this code in Java instead of Scala, keeping it the same logically? |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Write a version of this Scala function in Java with identical behavior. |
typealias Func = (Int) -> IntArray
fun calc(f: Func, n: Int): Double {
var temp = 0.0
for (i in n downTo 1) {
val p = f(i)
temp = p[1] / (p[0] + temp)
}
return f(0)[0] + temp
}
fun main(args: Array<String>) {
val pList = listOf<Pair<String, Func>>(
"sqrt(2)" to { n -> int... | import static java.lang.Math.pow;
import java.util.*;
import java.util.function.Function;
public class Test {
static double calc(Function<Integer, Integer[]> f, int n) {
double temp = 0;
for (int ni = n; ni >= 1; ni--) {
Integer[] p = f.apply(ni);
temp = p[1] / (double) (p[... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.