Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Write the same code in PHP as shown below in Racket. | #lang racket
(require math)
(define earth-radius 6371)
(define (distance lat1 long1 lat2 long2)
(define (h a b) (sqr (sin (/ (- b a) 2))))
(* 2 earth-radius
(asin (sqrt (+ (h lat1 lat2)
(* (cos lat1) (cos lat2) (h long1 long2)))))))
(define (deg-to-rad d m s)
(* (/ pi 180) (+ d (/ m ... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Write the same algorithm in PHP as shown in this REXX implementation. |
say " Nashville: north 36º 7.2', west 86º 40.2' = 36.12º, -86.67º"
say "Los Angles: north 33º 56.4', west 118º 24.0' = 33.94º, -118.40º"
say
dist=surfaceDistance(36.12, -86.67, 33.94, -118.4)
kdist=format(dist/1 ,,2)
mdist=format(dist/1.609344,,2)
ndist=format(mdist*5280/6076.1,... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Convert the following code from REXX to PHP, ensuring the logic remains intact. |
say " Nashville: north 36º 7.2', west 86º 40.2' = 36.12º, -86.67º"
say "Los Angles: north 33º 56.4', west 118º 24.0' = 33.94º, -118.40º"
say
dist=surfaceDistance(36.12, -86.67, 33.94, -118.4)
kdist=format(dist/1 ,,2)
mdist=format(dist/1.609344,,2)
ndist=format(mdist*5280/6076.1,... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Write a version of this Ruby function in PHP with identical behavior. | include Math
def haversine(lat1, lon1, lat2, lon2)
r = 6372.8
deg2rad = PI/180
dLat = (lat2 - lat1) * deg2rad
dLon = (lon2 - lon1) * deg2rad
lat1 = lat1 * deg2rad
lat2 = lat2 * deg2rad
a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2
c = 2 * asin(sqrt(a))
... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Please provide an equivalent version of this Ruby code in PHP. | include Math
def haversine(lat1, lon1, lat2, lon2)
r = 6372.8
deg2rad = PI/180
dLat = (lat2 - lat1) * deg2rad
dLon = (lon2 - lon1) * deg2rad
lat1 = lat1 * deg2rad
lat2 = lat2 * deg2rad
a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2
c = 2 * asin(sqrt(a))
... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Port the following code from Scala to PHP with equivalent syntax and logic. | import java.lang.Math.*
const val R = 6372.8
fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
val λ1 = toRadians(lat1)
val λ2 = toRadians(lat2)
val Δλ = toRadians(lat2 - lat1)
val Δφ = toRadians(lon2 - lon1)
return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Generate an equivalent PHP version of this Scala code. | import java.lang.Math.*
const val R = 6372.8
fun haversine(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double {
val λ1 = toRadians(lat1)
val λ2 = toRadians(lat2)
val Δλ = toRadians(lat2 - lat1)
val Δφ = toRadians(lon2 - lon1)
return 2 * R * asin(sqrt(pow(sin(Δλ / 2), 2.0) + pow(sin(Δ... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Rewrite the snippet below in PHP so it works the same as the original Swift code. | import Foundation
func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double {
let lat1rad = lat1 * Double.pi/180
let lon1rad = lon1 * Double.pi/180
let lat2rad = lat2 * Double.pi/180
let lon2rad = lon2 * Double.pi/180
let dLat = lat2rad - lat1rad
let dLon = lon2rad - lon... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Rewrite this program in PHP while keeping its functionality equivalent to the Swift version. | import Foundation
func haversine(lat1:Double, lon1:Double, lat2:Double, lon2:Double) -> Double {
let lat1rad = lat1 * Double.pi/180
let lon1rad = lon1 * Double.pi/180
let lat2rad = lat2 * Double.pi/180
let lon2rad = lon2 * Double.pi/180
let dLat = lat2rad - lat1rad
let dLon = lon2rad - lon... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Please provide an equivalent version of this Tcl code in PHP. | package require Tcl 8.5
proc haversineFormula {lat1 lon1 lat2 lon2} {
set rads [expr atan2(0,-1)/180]
set R 6372.8 ;
set dLat [expr {($lat2-$lat1) * $rads}]
set dLon [expr {($lon2-$lon1) * $rads}]
set lat1 [expr {$lat1 * $rads}]
set lat2 [expr {$lat2 * $rads}]
set a [expr {sin($dLat/2)*... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Generate an equivalent PHP version of this Tcl code. | package require Tcl 8.5
proc haversineFormula {lat1 lon1 lat2 lon2} {
set rads [expr atan2(0,-1)/180]
set R 6372.8 ;
set dLat [expr {($lat2-$lat1) * $rads}]
set dLon [expr {($lon2-$lon1) * $rads}]
set lat1 [expr {$lat1 * $rads}]
set lat2 [expr {$lat2 * $rads}]
set a [expr {sin($dLat/2)*... | class POI {
private $latitude;
private $longitude;
public function __construct($latitude, $longitude) {
$this->latitude = deg2rad($latitude);
$this->longitude = deg2rad($longitude);
}
public function getLatitude() {
return $this->latitude;
}
public function getLong... |
Write the same code in Rust as shown below in C. | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define R 6371
#define TO_RAD (3.1415926536 / 180)
double dist(double th1, double ph1, double th2, double ph2)
{
double dx, dy, dz;
ph1 -= ph2;
ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD;
dz = sin(th1) - sin(th2);
dx = cos(ph1) * cos(th1) - cos(th2);
dy ... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Write the same code in Rust as shown below in C. | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define R 6371
#define TO_RAD (3.1415926536 / 180)
double dist(double th1, double ph1, double th2, double ph2)
{
double dx, dy, dz;
ph1 -= ph2;
ph1 *= TO_RAD, th1 *= TO_RAD, th2 *= TO_RAD;
dz = sin(th1) - sin(th2);
dx = cos(ph1) * cos(th1) - cos(th2);
dy ... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Convert this C++ block to Rust, preserving its control flow and logic. | #define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
const static double EarthRadiusKm = 6372.8;
inline double DegreeToRadian(double angle)
{
return M_PI * angle / 180.0;
}
class Coordinate
{
public:
Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude)
{}
double... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Produce a language-to-language conversion: from C# to Rust, same semantics. | public static class Haversine {
public static double calculate(double lat1, double lon1, double lat2, double lon2) {
var R = 6372.8;
var dLat = toRadians(lat2 - lat1);
var dLon = toRadians(lon2 - lon1);
lat1 = toRadians(lat1);
lat2 = toRadians(lat2);
var a = Math.Sin(dLat / 2) * Math.Sin(... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Write the same algorithm in Rust as shown in this C# implementation. | public static class Haversine {
public static double calculate(double lat1, double lon1, double lat2, double lon2) {
var R = 6372.8;
var dLat = toRadians(lat2 - lat1);
var dLon = toRadians(lon2 - lon1);
lat1 = toRadians(lat1);
lat2 = toRadians(lat2);
var a = Math.Sin(dLat / 2) * Math.Sin(... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Convert the following code from Java to Rust, ensuring the logic remains intact. | public class Haversine {
public static final double R = 6372.8;
public static double haversine(double lat1, double lon1, double lat2, double lon2) {
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
double dLat = lat2 - lat1;
double dLon = Math.toRadians(lon2 - lon1);
... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Change the programming language of this snippet from Java to Rust without modifying what it does. | public class Haversine {
public static final double R = 6372.8;
public static double haversine(double lat1, double lon1, double lat2, double lon2) {
lat1 = Math.toRadians(lat1);
lat2 = Math.toRadians(lat2);
double dLat = lat2 - lat1;
double dLon = Math.toRadians(lon2 - lon1);
... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Port the provided Go code into Rust while preserving the original functionality. | package main
import (
"fmt"
"math"
)
func haversine(θ float64) float64 {
return .5 * (1 - math.Cos(θ))
}
type pos struct {
φ float64
ψ float64
}
func degPos(lat, lon float64) pos {
return pos{lat * math.Pi / 180, lon * math.Pi / 180}
}
const rEarth = 6372.8
func hsDist(p1, p2 pos) float... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Generate a Rust translation of this Go snippet without changing its computational steps. | package main
import (
"fmt"
"math"
)
func haversine(θ float64) float64 {
return .5 * (1 - math.Cos(θ))
}
type pos struct {
φ float64
ψ float64
}
func degPos(lat, lon float64) pos {
return pos{lat * math.Pi / 180, lon * math.Pi / 180}
}
const rEarth = 6372.8
func hsDist(p1, p2 pos) float... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Please provide an equivalent version of this Rust code in Python. | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... | from math import radians, sin, cos, sqrt, asin
def haversine(lat1, lon1, lat2, lon2):
R = 6372.8
dLat = radians(lat2 - lat1)
dLon = radians(lon2 - lon1)
lat1 = radians(lat1)
lat2 = radians(lat2)
a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2
c = 2 * asin(sqrt(a))
... |
Preserve the algorithm and functionality while converting the code from Rust to VB. | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... | Const MER = 6371
Public DEG_TO_RAD As Double
Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double
lat1 = lat1 * DEG_TO_RAD
lat2 = lat2 * DEG_TO_RAD
long1 = long1 * DEG_TO_RAD
long2 = long2 * DEG_TO_RAD
haversine = MER * WorksheetFunction.Acos(Sin(... |
Convert this Rust snippet to VB and keep its semantics consistent. | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... | Const MER = 6371
Public DEG_TO_RAD As Double
Function haversine(lat1 As Double, long1 As Double, lat2 As Double, long2 As Double) As Double
lat1 = lat1 * DEG_TO_RAD
lat2 = lat2 * DEG_TO_RAD
long1 = long1 * DEG_TO_RAD
long2 = long2 * DEG_TO_RAD
haversine = MER * WorksheetFunction.Acos(Sin(... |
Convert this Rust block to Python, preserving its control flow and logic. | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... | from math import radians, sin, cos, sqrt, asin
def haversine(lat1, lon1, lat2, lon2):
R = 6372.8
dLat = radians(lat2 - lat1)
dLon = radians(lon2 - lon1)
lat1 = radians(lat1)
lat2 = radians(lat2)
a = sin(dLat / 2)**2 + cos(lat1) * cos(lat2) * sin(dLon / 2)**2
c = 2 * asin(sqrt(a))
... |
Ensure the translated Rust code behaves exactly like the original C++ snippet. | #define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
const static double EarthRadiusKm = 6372.8;
inline double DegreeToRadian(double angle)
{
return M_PI * angle / 180.0;
}
class Coordinate
{
public:
Coordinate(double latitude ,double longitude):myLatitude(latitude), myLongitude(longitude)
{}
double... | struct Point {
lat: f64,
lon: f64,
}
fn haversine(origin: Point, destination: Point) -> f64 {
const R: f64 = 6372.8;
let lat1 = origin.lat.to_radians();
let lat2 = destination.lat.to_radians();
let d_lat = lat2 - lat1;
let d_lon = (destination.lon - origin.lon).to_radians();
let a = (... |
Generate a C# translation of this Ada snippet without changing its computational steps. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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;
... |
Maintain the same structure and functionality when rewriting this code in C#. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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 Ada. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | #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 Ada to C. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | #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 Ada implementation. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | #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... |
Change the programming language of this snippet from Ada to C++ without modifying what it does. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | #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 Go version of this Ada code. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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 Ada block to Go, preserving its control flow and logic. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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 Java version of this Ada code. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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) ? ... |
Preserve the algorithm and functionality while converting the code from Ada to Java. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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) ? ... |
Preserve the algorithm and functionality while converting the code from Ada to Python. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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 Ada to Python with equivalent syntax and logic. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | 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 Ada code snippet into VB without altering its behavior. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | Option Base 1
Private Function median(tbl As Variant, lo As Integer, hi As Integer)
Dim l As Integer: l = hi - lo + 1
Dim m As Integer: m = lo + WorksheetFunction.Floor_Precise(l / 2)
If l Mod 2 = 1 Then
median = tbl(m)
Else
median = (tbl(m - 1) + tbl(m)) / 2
End if
End Function
Pri... |
Generate an equivalent VB version of this Ada code. | with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Generic_Array_Sort;
procedure Main is
package Real_Io is new Float_IO (Long_Float);
use Real_Io;
type Data_Array is array (Natural range <>) of Long_Float;
subtype Five_Num_Type is Data_Array (0 .. 4);
procedure Sort is new Ada.Containers.Generic_... | Option Base 1
Private Function median(tbl As Variant, lo As Integer, hi As Integer)
Dim l As Integer: l = hi - lo + 1
Dim m As Integer: m = lo + WorksheetFunction.Floor_Precise(l / 2)
If l Mod 2 = 1 Then
median = tbl(m)
Else
median = (tbl(m - 1) + tbl(m)) / 2
End if
End Function
Pri... |
Translate this program into C but keep the logic exactly as in Arturo. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | #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]... |
Maintain the same structure and functionality when rewriting this code in C. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | #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]... |
Change the programming language of this snippet from Arturo to C# without modifying what it does. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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;
... |
Preserve the algorithm and functionality while converting the code from Arturo to C#. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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 Arturo code. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | #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... |
Keep all operations the same but rewrite the snippet in C++. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | #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 Java code for the snippet given in Arturo. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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 Arturo code snippet into Java without altering its behavior. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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) ? ... |
Convert this Arturo block to Python, preserving its control flow and logic. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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 a version of this Arturo function in Python with identical behavior. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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 Arturo to VB with equivalent syntax and logic. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | #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... |
Keep all operations the same but rewrite the snippet in VB. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | #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 language-to-language conversion: from Arturo to Go, same semantics. | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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... |
Can you help me rewrite this code in Go instead of Arturo, keeping it the same logically? | fivenum: function [lst][
lst: sort lst
m: (size lst)/2
lowerEnd: (odd? size lst)? -> m -> m-1
return @[
first lst
median slice lst 0 lowerEnd
median slice lst 0 dec size lst
median slice lst m dec size lst
last lst
]
]
lists: @[
@[15.0, 6.0, 42.0, 41.0, ... | 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 D block to C, preserving its control flow and logic. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | #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 this program in C while keeping its functionality equivalent to the D version. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | #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 D to C#. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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 a version of this D function in C# with identical behavior. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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;
... |
Convert this D snippet to C++ and keep its semantics consistent. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | #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 language-to-language conversion: from D to C++, same semantics. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | #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... |
Ensure the translated Java code behaves exactly like the original D snippet. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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 D. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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) ? ... |
Ensure the translated Python code behaves exactly like the original D snippet. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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 this D snippet to Python and keep its semantics consistent. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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 D to VB, ensuring the logic remains intact. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | #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... |
Transform the following D implementation into VB, maintaining the same output and logic. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | #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 D. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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 D code in Go. | import std.algorithm;
import std.exception;
import std.math;
import std.stdio;
double median(double[] x) {
enforce(x.length >= 0, "Array slice cannot be empty");
int m = x.length / 2;
if (x.length % 2 == 1) {
return x[m];
}
return (x[m-1] + x[m]) / 2.0;
}
double[] fivenum(double[] x) {
... | 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 functionally identical C code for the snippet given in Delphi. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | #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 Delphi code. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | #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]... |
Translate the given Delphi code snippet into C# without altering its behavior. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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#. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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 Delphi code snippet into C++ without altering its behavior. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | #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... |
Please provide an equivalent version of this Delphi code in C++. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | #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... |
Translate this program into Java but keep the logic exactly as in Delphi. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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) ? ... |
Convert this Delphi snippet to Java and keep its semantics consistent. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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 Delphi to Python without modifying what it does. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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 the snippet below in Python so it works the same as the original Delphi code. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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 Delphi to VB, ensuring the logic remains intact. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | #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... |
Keep all operations the same but rewrite the snippet in VB. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | #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 language-to-language conversion: from Delphi to Go, same semantics. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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... |
Maintain the same structure and functionality when rewriting this code in Go. | program Fivenum;
uses
System.SysUtils,
System.Generics.Collections;
function Median(x: TArray<Double>; start, endInclusive: Integer): Double;
var
size, m: Integer;
begin
size := endInclusive - start + 1;
if (size <= 0) then
raise EArgumentException.Create('Array slice cannot be empty');
m := start +... | 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 F# code. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | #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 provided F# code into C while preserving the original functionality. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | #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 F# to C#, ensuring the logic remains intact. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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 following F# code into C# without altering its purpose. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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 F# version. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | #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 F# snippet without changing its computational steps. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | #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... |
Write the same code in Java as shown below in F#. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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) ? ... |
Convert this F# snippet to Java and keep its semantics consistent. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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 F# code in Python. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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 language-to-language conversion: from F# to Python, same semantics. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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 F# to VB, ensuring the logic remains intact. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | #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 language-to-language conversion: from F# to VB, same semantics. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | #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... |
Convert the following code from F# to Go, ensuring the logic remains intact. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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... |
Change the following F# code into Go without altering its purpose. | open System
let rec last = function
| hd :: [] -> hd
| _ :: tl -> last tl
| _ -> failwith "Empty list."
let median x =
for e in x do
if Double.IsNaN(e) then failwith "unable to deal with lists containing NaN"
let size = List.length(x)
if size <= 0 then failwith "Array slice cannot be... | 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... |
Change the following Factor code into C without altering its purpose. | 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 <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 Factor to C. | 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 <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]... |
Transform the following Factor implementation into C#, 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... | 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 Factor code in C#. | 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... | 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 Factor code into C++ 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... | #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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.