Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Produce a language-to-language conversion: from Factor to C++, same semantics. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Port the provided Factor code into Java while preserving the original functionality. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Transform the following Factor implementation into Java, maintaining the same output and logic. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Translate the given Factor code snippet into Python without altering its behavior. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Translate the given Factor code snippet into Python without altering its behavior. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Port the following code from Factor to VB with equivalent syntax and logic. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Maintain the same structure and functionality when rewriting this code in VB. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Preserve the algorithm and functionality while converting the code from Factor to Go. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Keep all operations the same but rewrite the snippet in Go. | USING: combinators combinators.smart kernel math
math.statistics prettyprint sequences sorting ;
IN: rosetta-code.five-number
<PRIVATE
: bisect ( seq -- lower upper )
dup length even? [ halves ]
[ dup midpoint@ 1 + [ head ] [ tail* ] 2bi ] if ;
: (fivenum) ( seq -- summary )
natural-sort {
[ infi... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Generate an equivalent C version of this Groovy code. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Produce a language-to-language conversion: from Groovy to C, same semantics. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Rewrite the snippet below in C# so it works the same as the original Groovy code. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Change the programming language of this snippet from Groovy to C# without modifying what it does. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Rewrite the snippet below in C++ so it works the same as the original Groovy code. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Generate a C++ translation of this Groovy snippet without changing its computational steps. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Generate an equivalent Java version of this Groovy code. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Rewrite the snippet below in Java so it works the same as the original Groovy code. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Can you help me rewrite this code in Python instead of Groovy, keeping it the same logically? | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Ensure the translated Python code behaves exactly like the original Groovy snippet. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Port the provided Groovy code into VB while preserving the original functionality. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Rewrite the snippet below in VB so it works the same as the original Groovy code. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Produce a functionally identical Go code for the snippet given in Groovy. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Please provide an equivalent version of this Groovy code in Go. | class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1
if (size <= 0) {
throw new IllegalArgumentException("Array slice cannot be empty")
}
int m = start + (int) (size / 2)
return (size % 2 == 1) ? x[m] ... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Rewrite this program in C while keeping its functionality equivalent to the Haskell version. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Write the same algorithm in C as shown in this Haskell implementation. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Write a version of this Haskell function in C# with identical behavior. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Port the provided Haskell code into C# while preserving the original functionality. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Produce a language-to-language conversion: from Haskell to C++, same semantics. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Convert this Haskell snippet to C++ and keep its semantics consistent. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Transform the following Haskell implementation into Java, maintaining the same output and logic. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Please provide an equivalent version of this Haskell code in Java. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Write the same algorithm in Python as shown in this Haskell implementation. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Maintain the same structure and functionality when rewriting this code in Python. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Rewrite this program in VB while keeping its functionality equivalent to the Haskell version. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Generate a Go translation of this Haskell snippet without changing its computational steps. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Preserve the algorithm and functionality while converting the code from Haskell to Go. | import Data.List (sort)
fivenum :: [Double] -> [Double]
fivenum [] = []
fivenum xs
| l >= 5 =
fmap
( (/ 2)
. ( (+) . (!!) s
. floor
<*> (!!) s . ceiling
)
. pred
)
[1, q, succ l / 2, succ l - q, l]
| otherwise = s
where
l =... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Port the provided J code into C while preserving the original functionality. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Ensure the translated C code behaves exactly like the original J snippet. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Write a version of this J function in C# with identical behavior. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Keep all operations the same but rewrite the snippet in C#. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Port the provided J code into C++ while preserving the original functionality. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Transform the following J implementation into C++, maintaining the same output and logic. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Port the provided J code into Java while preserving the original functionality. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Produce a functionally identical Java code for the snippet given in J. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Produce a functionally identical Python code for the snippet given in J. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Translate the given J code snippet into Python without altering its behavior. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Convert the following code from J to VB, ensuring the logic remains intact. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Change the programming language of this snippet from J to VB without modifying what it does. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Write the same code in Go as shown below in J. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Generate a Go translation of this J snippet without changing its computational steps. | midpts=: (1 + #) <:@(] , -:@[ , -) -:@<.@-:@(3 + #)
quartiles=: -:@(+/)@((<. ,: >.)@midpts { /:~@])
fivenum=: <./ , quartiles , >./
| package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Convert this Julia snippet to C and keep its semantics consistent. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Preserve the algorithm and functionality while converting the code from Julia to C. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Produce a language-to-language conversion: from Julia to C#, same semantics. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Rewrite the snippet below in C# so it works the same as the original Julia code. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Please provide an equivalent version of this Julia code in C++. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Produce a functionally identical C++ code for the snippet given in Julia. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Generate a Java translation of this Julia snippet without changing its computational steps. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Change the following Julia code into Java without altering its purpose. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Produce a functionally identical Python code for the snippet given in Julia. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Produce a functionally identical Python code for the snippet given in Julia. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Can you help me rewrite this code in VB instead of Julia, keeping it the same logically? | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Change the programming language of this snippet from Julia to VB without modifying what it does. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Produce a functionally identical Go code for the snippet given in Julia. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Translate this program into Go but keep the logic exactly as in Julia. | function mediansorted(x::AbstractVector{T}, i::Integer, l::Integer)::T where T
len = l - i + 1
len > zero(len) || throw(ArgumentError("Array slice cannot be empty."))
mid = i + len ÷ 2
return isodd(len) ? x[mid] : (x[mid-1] + x[mid]) / 2
end
function fivenum(x::AbstractVector{T}) where T<:AbstractFloat... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Produce a language-to-language conversion: from Lua to C, same semantics. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Rewrite the snippet below in C so it works the same as the original Lua code. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Convert this Lua snippet to C# and keep its semantics consistent. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Rewrite this program in C# while keeping its functionality equivalent to the Lua version. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Rewrite this program in C++ while keeping its functionality equivalent to the Lua version. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Maintain the same structure and functionality when rewriting this code in C++. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Port the provided Lua code into Java while preserving the original functionality. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Maintain the same structure and functionality when rewriting this code in Java. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Rewrite this program in Python while keeping its functionality equivalent to the Lua version. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Generate an equivalent Python version of this Lua code. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Write the same code in VB as shown below in Lua. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Translate this program into VB but keep the logic exactly as in Lua. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Maintain the same structure and functionality when rewriting this code in Go. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Ensure the translated Go code behaves exactly like the original Lua snippet. | function slice(tbl, low, high)
local copy = {}
for i=low or 1, high or #tbl do
copy[#copy+1] = tbl[i]
end
return copy
end
function median(tbl)
m = math.floor(#tbl / 2) + 1
if #tbl % 2 == 1 then
return tbl[m]
end
return (tbl[m-1] + tbl[m]) / 2
end
function fivenum(tbl... | package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Convert the following code from Mathematica to C, ensuring the logic remains intact. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Write the same algorithm in C as shown in this Mathematica implementation. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Keep all operations the same but rewrite the snippet in C#. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Port the following code from Mathematica to C# with equivalent syntax and logic. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Write the same code in C++ as shown below in Mathematica. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Preserve the algorithm and functionality while converting the code from Mathematica to C++. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Rewrite this program in Java while keeping its functionality equivalent to the Mathematica version. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Generate a Java translation of this Mathematica snippet without changing its computational steps. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Change the programming language of this snippet from Mathematica to Python without modifying what it does. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Translate the given Mathematica code snippet into Python without altering its behavior. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| from __future__ import division
import math
import sys
def fivenum(array):
n = len(array)
if n == 0:
print("you entered an empty array.")
sys.exit()
x = sorted(array)
n4 = math.floor((n+3.0)/2.0)/2.0
d = [1, n4, (n+1)/2, n+1-n4, n]
sum_array = []
for e in range(5):... |
Preserve the algorithm and functionality while converting the code from Mathematica to VB. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Port the provided Mathematica code into VB while preserving the original functionality. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| #define floor(x) ((x*2.0-0.5) Shr 1)
Sub rapidSort (array()As Single, l As Integer, r As Integer)
Dim As Integer n, wert, nptr, rep
Dim As Single arr, LoVal = array(l), HiVal = array(r)
For n = l To r
If LoVal > array(n) Then LoVal = array(n)
If HiVal < array(n) Then HiVal = array(n)
Ne... |
Ensure the translated Go code behaves exactly like the original Mathematica snippet. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Transform the following Mathematica implementation into Go, maintaining the same output and logic. | ClearAll[FiveNum]
FiveNum[x_List] := Quantile[x, Range[0, 1, 1/4]]
FiveNum[RandomVariate[NormalDistribution[], 10000]]
| package main
import (
"fmt"
"math"
"sort"
)
func fivenum(a []float64) (n5 [5]float64) {
sort.Float64s(a)
n := float64(len(a))
n4 := float64((len(a)+3)/2) / 2
d := []float64{1, n4, (n + 1) / 2, n + 1 - n4, n}
for e, de := range d {
floor := int(de - 1)
ceil := int(math.C... |
Generate an equivalent C version of this MATLAB code. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Convert the following code from MATLAB to C, ensuring the logic remains intact. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| #include <stdio.h>
#include <stdlib.h>
double median(double *x, int start, int end_inclusive) {
int size = end_inclusive - start + 1;
if (size <= 0) {
printf("Array slice cannot be empty\n");
exit(1);
}
int m = start + size / 2;
if (size % 2) return x[m];
return (x[m - 1] + x[m]... |
Port the following code from MATLAB to C# with equivalent syntax and logic. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Translate the given MATLAB code snippet into C# without altering its behavior. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Fivenum {
public static class Helper {
public static string AsString<T>(this ICollection<T> c, string format = "{0}") {
StringBuilder sb = new StringBuilder("[");
int count = 0;
... |
Rewrite the snippet below in C++ so it works the same as the original MATLAB code. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Convert this MATLAB block to C++, preserving its control flow and logic. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| #include <algorithm>
#include <iostream>
#include <ostream>
#include <vector>
template<std::size_t> struct int_ {};
template <class Tuple, size_t Pos>
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos>) {
out << std::get< std::tuple_size<Tuple>::value - Pos >(t) << ", ";
return print_t... |
Preserve the algorithm and functionality while converting the code from MATLAB to Java. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Generate an equivalent Java version of this MATLAB code. | function r = fivenum(x)
r = quantile(x,[0:4]/4);
end;
| import java.util.Arrays;
public class Fivenum {
static double median(double[] x, int start, int endInclusive) {
int size = endInclusive - start + 1;
if (size <= 0) throw new IllegalArgumentException("Array slice cannot be empty");
int m = start + size / 2;
return (size % 2 == 1) ? ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.