Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Maintain the same structure and functionality when rewriting this code in C#.
FUNCTION MEDIAN(some-table (ALL))
using System; using System.Linq; namespace Test { class Program { static void Main() { double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 }; myArr = myArr.OrderBy(i => i).ToArray(); int mid = myArr.Length / 2; double median; ...
Convert the following code from COBOL to C++, ensuring the logic remains intact.
FUNCTION MEDIAN(some-table (ALL))
#include <algorithm> template <typename Iterator> double median(Iterator begin, Iterator end) { Iterator middle = begin + (end - begin) / 2; std::nth_element(begin, middle, end); if ((end - begin) % 2 != 0) { return *middle; } else { Iterator lower_middle = std::max_element(begin, midd...
Produce a language-to-language conversion: from COBOL to Java, same semantics.
FUNCTION MEDIAN(some-table (ALL))
public static double median(List<Double> list) { Collections.sort(list); return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2; }
Keep all operations the same but rewrite the snippet in Python.
FUNCTION MEDIAN(some-table (ALL))
def median(aray): srtd = sorted(aray) alen = len(srtd) return 0.5*( srtd[(alen-1)//2] + srtd[alen//2]) a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a) a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a)
Keep all operations the same but rewrite the snippet in VB.
FUNCTION MEDIAN(some-table (ALL))
Private Function medianq(s As Variant) As Double Dim res As Double, tmp As Integer Dim l As Integer, k As Integer res = 0 l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1) If l Then res = quick_select(s, k) If l Mod 2 = 0 Then tmp = quick_...
Keep all operations the same but rewrite the snippet in Go.
FUNCTION MEDIAN(some-table (ALL))
package main import ( "fmt" "sort" ) func main() { fmt.Println(median([]float64{3, 1, 4, 1})) fmt.Println(median([]float64{3, 1, 4, 1, 5})) } func median(a []float64) float64 { sort.Float64s(a) half := len(a) / 2 m := a[half] if len(a)%2 == 0 { m = (m + a[half-1]) / 2 ...
Preserve the algorithm and functionality while converting the code from REXX to C.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
#include <stdio.h> #include <stdlib.h> typedef struct floatList { float *list; int size; } *FloatList; int floatcmp( const void *a, const void *b) { if (*(const float *)a < *(const float *)b) return -1; else return *(const float *)a > *(const float *)b; } float median( FloatList fl ) { qsort( f...
Rewrite this program in C# while keeping its functionality equivalent to the REXX version.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
using System; using System.Linq; namespace Test { class Program { static void Main() { double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 }; myArr = myArr.OrderBy(i => i).ToArray(); int mid = myArr.Length / 2; double median; ...
Generate an equivalent C++ version of this REXX code.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
#include <algorithm> template <typename Iterator> double median(Iterator begin, Iterator end) { Iterator middle = begin + (end - begin) / 2; std::nth_element(begin, middle, end); if ((end - begin) % 2 != 0) { return *middle; } else { Iterator lower_middle = std::max_element(begin, midd...
Convert this REXX snippet to Java and keep its semantics consistent.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
public static double median(List<Double> list) { Collections.sort(list); return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2; }
Convert this REXX block to Python, preserving its control flow and logic.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
def median(aray): srtd = sorted(aray) alen = len(srtd) return 0.5*( srtd[(alen-1)//2] + srtd[alen//2]) a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a) a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a)
Maintain the same structure and functionality when rewriting this code in VB.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
Private Function medianq(s As Variant) As Double Dim res As Double, tmp As Integer Dim l As Integer, k As Integer res = 0 l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1) If l Then res = quick_select(s, k) If l Mod 2 = 0 Then tmp = quick_...
Write the same algorithm in Go as shown in this REXX implementation.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
package main import ( "fmt" "sort" ) func main() { fmt.Println(median([]float64{3, 1, 4, 1})) fmt.Println(median([]float64{3, 1, 4, 1, 5})) } func median(a []float64) float64 { sort.Float64s(a) half := len(a) / 2 m := a[half] if len(a)%2 == 0 { m = (m + a[half-1]) / 2 ...
Keep all operations the same but rewrite the snippet in C.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
#include <stdio.h> #include <stdlib.h> typedef struct floatList { float *list; int size; } *FloatList; int floatcmp( const void *a, const void *b) { if (*(const float *)a < *(const float *)b) return -1; else return *(const float *)a > *(const float *)b; } float median( FloatList fl ) { qsort( f...
Ensure the translated C# code behaves exactly like the original Ruby snippet.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
using System; using System.Linq; namespace Test { class Program { static void Main() { double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 }; myArr = myArr.OrderBy(i => i).ToArray(); int mid = myArr.Length / 2; double median; ...
Produce a language-to-language conversion: from Ruby to C++, same semantics.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
#include <algorithm> template <typename Iterator> double median(Iterator begin, Iterator end) { Iterator middle = begin + (end - begin) / 2; std::nth_element(begin, middle, end); if ((end - begin) % 2 != 0) { return *middle; } else { Iterator lower_middle = std::max_element(begin, midd...
Ensure the translated Java code behaves exactly like the original Ruby snippet.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
public static double median(List<Double> list) { Collections.sort(list); return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2; }
Change the following Ruby code into Python without altering its purpose.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
def median(aray): srtd = sorted(aray) alen = len(srtd) return 0.5*( srtd[(alen-1)//2] + srtd[alen//2]) a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a) a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a)
Convert the following code from Ruby to VB, ensuring the logic remains intact.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
Private Function medianq(s As Variant) As Double Dim res As Double, tmp As Integer Dim l As Integer, k As Integer res = 0 l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1) If l Then res = quick_select(s, k) If l Mod 2 = 0 Then tmp = quick_...
Change the programming language of this snippet from Ruby to Go without modifying what it does.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
package main import ( "fmt" "sort" ) func main() { fmt.Println(median([]float64{3, 1, 4, 1})) fmt.Println(median([]float64{3, 1, 4, 1, 5})) } func median(a []float64) float64 { sort.Float64s(a) half := len(a) / 2 m := a[half] if len(a)%2 == 0 { m = (m + a[half-1]) / 2 ...
Transform the following Scala implementation into C, maintaining the same output and logic.
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
#include <stdio.h> #include <stdlib.h> typedef struct floatList { float *list; int size; } *FloatList; int floatcmp( const void *a, const void *b) { if (*(const float *)a < *(const float *)b) return -1; else return *(const float *)a > *(const float *)b; } float median( FloatList fl ) { qsort( f...
Write a version of this Scala function in C# with identical behavior.
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
using System; using System.Linq; namespace Test { class Program { static void Main() { double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 }; myArr = myArr.OrderBy(i => i).ToArray(); int mid = myArr.Length / 2; double median; ...
Write a version of this Scala function in C++ with identical behavior.
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
#include <algorithm> template <typename Iterator> double median(Iterator begin, Iterator end) { Iterator middle = begin + (end - begin) / 2; std::nth_element(begin, middle, end); if ((end - begin) % 2 != 0) { return *middle; } else { Iterator lower_middle = std::max_element(begin, midd...
Can you help me rewrite this code in Java instead of Scala, keeping it the same logically?
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
public static double median(List<Double> list) { Collections.sort(list); return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2; }
Translate the given Scala code snippet into Python without altering its behavior.
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
def median(aray): srtd = sorted(aray) alen = len(srtd) return 0.5*( srtd[(alen-1)//2] + srtd[alen//2]) a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a) a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a)
Write the same algorithm in VB as shown in this Scala implementation.
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
Private Function medianq(s As Variant) As Double Dim res As Double, tmp As Integer Dim l As Integer, k As Integer res = 0 l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1) If l Then res = quick_select(s, k) If l Mod 2 = 0 Then tmp = quick_...
Preserve the algorithm and functionality while converting the code from Scala to Go.
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
package main import ( "fmt" "sort" ) func main() { fmt.Println(median([]float64{3, 1, 4, 1})) fmt.Println(median([]float64{3, 1, 4, 1, 5})) } func median(a []float64) float64 { sort.Float64s(a) half := len(a) / 2 m := a[half] if len(a)%2 == 0 { m = (m + a[half-1]) / 2 ...
Produce a functionally identical C code for the snippet given in Tcl.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
#include <stdio.h> #include <stdlib.h> typedef struct floatList { float *list; int size; } *FloatList; int floatcmp( const void *a, const void *b) { if (*(const float *)a < *(const float *)b) return -1; else return *(const float *)a > *(const float *)b; } float median( FloatList fl ) { qsort( f...
Convert this Tcl snippet to C# and keep its semantics consistent.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
using System; using System.Linq; namespace Test { class Program { static void Main() { double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 }; myArr = myArr.OrderBy(i => i).ToArray(); int mid = myArr.Length / 2; double median; ...
Rewrite the snippet below in C++ so it works the same as the original Tcl code.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
#include <algorithm> template <typename Iterator> double median(Iterator begin, Iterator end) { Iterator middle = begin + (end - begin) / 2; std::nth_element(begin, middle, end); if ((end - begin) % 2 != 0) { return *middle; } else { Iterator lower_middle = std::max_element(begin, midd...
Ensure the translated Java code behaves exactly like the original Tcl snippet.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
public static double median(List<Double> list) { Collections.sort(list); return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2; }
Transform the following Tcl implementation into Python, maintaining the same output and logic.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
def median(aray): srtd = sorted(aray) alen = len(srtd) return 0.5*( srtd[(alen-1)//2] + srtd[alen//2]) a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a) a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a)
Translate the given Tcl code snippet into VB without altering its behavior.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
Private Function medianq(s As Variant) As Double Dim res As Double, tmp As Integer Dim l As Integer, k As Integer res = 0 l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1) If l Then res = quick_select(s, k) If l Mod 2 = 0 Then tmp = quick_...
Port the following code from Tcl to Go with equivalent syntax and logic.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
package main import ( "fmt" "sort" ) func main() { fmt.Println(median([]float64{3, 1, 4, 1})) fmt.Println(median([]float64{3, 1, 4, 1, 5})) } func median(a []float64) float64 { sort.Float64s(a) half := len(a) / 2 m := a[half] if len(a)%2 == 0 { m = (m + a[half-1]) / 2 ...
Write the same code in PHP as shown below in Rust.
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Preserve the algorithm and functionality while converting the code from Ada to PHP.
with Ada.Text_IO, Ada.Float_Text_IO; procedure FindMedian is f: array(1..10) of float := ( 4.4, 2.3, -1.7, 7.5, 6.6, 0.0, 1.9, 8.2, 9.3, 4.5 ); min_idx: integer; min_val, median_val, swap: float; begin for i in f'range loop min_idx := i; min_val := f(i); for j in i+1 .. f'last...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Keep all operations the same but rewrite the snippet in PHP.
arr: [1 2 3 4 5 6 7] arr2: [1 2 3 4 5 6] print median arr print median arr2
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Rewrite the snippet below in PHP so it works the same as the original AutoHotKey code.
seq = 4.1, 7.2, 1.7, 9.3, 4.4, 3.2, 5 MsgBox % median(seq, "`,")   median(seq, delimiter) { Sort, seq, ND%delimiter% StringSplit, seq, seq, % delimiter median := Floor(seq0 / 2) Return seq%median% }
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Change the following AWK code into PHP without altering its purpose.
BEGIN { d[1] = 3.0 d[2] = 4.0 d[3] = 1.0 d[4] = -8.4 d[5] = 7.2 d[6] = 4.0 d[7] = 1.0 d[8] = 1.2 showD("Before: ") gnomeSortD() showD("Sorted: ") printf "Median: %f\n", medianD() exit } function medianD( len, mid) { len = length(d) mid = int(len/2) + 1 ...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Change the programming language of this snippet from BBC_Basic to PHP without modifying what it does.
INSTALL @lib$+"SORTLIB" Sort% = FN_sortinit(0,0) DIM a(6), b(5) a() = 4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2 b() = 4.1, 7.2, 1.7, 9.3, 4.4, 3.2 PRINT "Median of a() is " ; FNmedian(a()) PRINT "Median of b() is " ; FNmedian(b()) END DEF FNmedian(a()) LOCAL C% ...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Translate this program into PHP but keep the logic exactly as in Common_Lisp.
(defn median [ns] (let [ns (sort ns) cnt (count ns) mid (bit-shift-right cnt 1)] (if (odd? cnt) (nth ns mid) (/ (+ (nth ns mid) (nth ns (dec mid))) 2))))
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Change the following D code into PHP without altering its purpose.
import std.stdio, std.algorithm; T median(T)(T[] nums) pure nothrow { nums.sort(); if (nums.length & 1) return nums[$ / 2]; else return (nums[$ / 2 - 1] + nums[$ / 2]) / 2.0; } void main() { auto a1 = [5.1, 2.6, 6.2, 8.8, 4.6, 4.1]; writeln("Even median: ", a1.median); auto a2...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Rewrite the snippet below in PHP so it works the same as the original Delphi code.
program AveragesMedian; uses Generics.Collections, Types; function Median(aArray: TDoubleDynArray): Double; var lMiddleIndex: Integer; begin TArray.Sort<Double>(aArray); lMiddleIndex := Length(aArray) div 2; if Odd(Length(aArray)) then Result := aArray[lMiddleIndex] else Result := (aArray[lMiddle...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Write the same algorithm in PHP as shown in this Elixir implementation.
defmodule Average do def median([]), do: nil def median(list) do len = length(list) sorted = Enum.sort(list) mid = div(len, 2) if rem(len,2) == 0, do: (Enum.at(sorted, mid-1) + Enum.at(sorted, mid)) / 2, else: Enum.at(sorted, mid) end end median = fn list -> IO.puts " medi...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Rewrite the snippet below in PHP so it works the same as the original Erlang code.
-module(median). -import(lists, [nth/2, sort/1]). -compile(export_all). test(MaxInt,ListSize,TimesToRun) -> test(MaxInt,ListSize,TimesToRun,[[],[]]). test(_,_,0,[GMAcc, OMAcc]) -> Len = length(GMAcc), {GMT,GMV} = lists:foldl(fun({T, V}, {AT,AV}) -> {AT + T, AV + V} end, {0,0}, GMAcc), {OMT,OMV} = lis...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Produce a language-to-language conversion: from F# to PHP, same semantics.
let rec splitToFives list = match list with | a::b::c::d::e::tail -> ([a;b;c;d;e])::(splitToFives tail) | [] -> [] | _ -> let left = 5 - List.length (list) let last = List.append list (List.init left (fun _ -> System.Double.PositiveInfinity) ) ...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Can you help me rewrite this code in PHP instead of Factor, keeping it the same logically?
USING: arrays kernel locals math math.functions random sequences ; IN: median : pivot ( seq -- pivot ) random ; : split ( seq pivot -- {lt,eq,gt} ) [ [ < ] curry partition ] keep [ = ] curry partition 3array ; DEFER: nth-in-order :: nth-in-order-recur ( seq ind -- elt ) seq dup pivot split dup [ length ] m...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Change the programming language of this snippet from Forth to PHP without modifying what it does.
-1 cells constant -cell : cell- -cell + ; defer lessthan ' < is lessthan : mid over - 2/ -cell and + ; : exch dup @ >r over @ swap ! r> swap ! ; : part 2dup mid @ >r 2dup begin swap begin dup @ r@ lessthan while cell+ repeat swap begin r@ over @ lessthan while cell- repeat 2dup <= if 2dup ...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Transform the following Fortran implementation into PHP, maintaining the same output and logic.
program Median_Test real :: a(7) = (/ 4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2 /), & b(6) = (/ 4.1, 7.2, 1.7, 9.3, 4.4, 3.2 /) print *, median(a) print *, median(b) contains function median(a, found) real, dimension(:), intent(in) :: a logical, optional,...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Rewrite the snippet below in PHP so it works the same as the original Groovy code.
def median(Iterable col) { def s = col as SortedSet if (s == null) return null if (s.empty) return 0 def n = s.size() def m = n.intdiv(2) def l = s.collect { it } n%2 == 1 ? l[m] : (l[m] + l[m-1])/2 }
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Generate a PHP translation of this Haskell snippet without changing its computational steps.
import Data.List (partition) nth :: Ord t => [t] -> Int -> t nth (x:xs) n | k == n = x | k > n = nth ys n | otherwise = nth zs $ n - k - 1 where (ys, zs) = partition (< x) xs k = length ys medianMay :: (Fractional a, Ord a) => [a] -> Maybe a medianMay xs | n < 1 = Nothing | even n = Just ((nth xs ...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Rewrite this program in PHP while keeping its functionality equivalent to the J version.
require 'stats/base' median 1 9 2 4 3
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Maintain the same structure and functionality when rewriting this code in PHP.
using Statistics function median2(n) s = sort(n) len = length(n) if len % 2 == 0 return (s[floor(Int, len / 2) + 1] + s[floor(Int, len / 2)]) / 2 else return s[floor(Int, len / 2) + 1] end end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] b = [4.1, 7.2, 1.7, 9.3, 4.4, 3.2] @show a b median2(a) median(a) median2(b...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Convert the following code from Lua to PHP, ensuring the logic remains intact.
function median (numlist) if type(numlist) ~= 'table' then return numlist end table.sort(numlist) if #numlist %2 == 0 then return (numlist[#numlist/2] + numlist[#numlist/2+1]) / 2 end return numlist[math.ceil(#numlist/2)] end print(median({4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2})) print(median({4.1, 7.2, 1....
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Rewrite this program in PHP while keeping its functionality equivalent to the Mathematica version.
Median[{1, 5, 3, 2, 4}] Median[{1, 5, 3, 6, 4, 2}]
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Convert the following code from MATLAB to PHP, ensuring the logic remains intact.
function medianValue = findmedian(setOfValues) medianValue = median(setOfValues); end
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Maintain the same structure and functionality when rewriting this code in PHP.
import algorithm, strutils proc median(xs: seq[float]): float = var ys = xs sort(ys, system.cmp[float]) 0.5 * (ys[ys.high div 2] + ys[ys.len div 2]) var a = @[4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] echo formatFloat(median(a), precision = 0) a = @[4.1, 7.2, 1.7, 9.3, 4.4, 3.2] echo formatFloat(median(a), precisio...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Please provide an equivalent version of this OCaml code in PHP.
let median array = let len = Array.length array in Array.sort compare array; (array.((len-1)/2) +. array.(len/2)) /. 2.0;; let a = [|4.1; 5.6; 7.2; 1.7; 9.3; 4.4; 3.2|];; median a;; let a = [|4.1; 7.2; 1.7; 9.3; 4.4; 3.2|];; median a;;
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Can you help me rewrite this code in PHP instead of Pascal, keeping it the same logically?
Program AveragesMedian(output); type TDoubleArray = array of double; procedure bubbleSort(var list: TDoubleArray); var i, j, n: integer; t: double; begin n := length(list); for i := n downto 2 do for j := 0 to i - 1 do if list[j] > list[j + 1] then begin t := list[j]; list[j...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Please provide an equivalent version of this Perl code in PHP.
sub median { my @a = sort {$a <=> $b} @_; return ($a[$ }
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Keep all operations the same but rewrite the snippet in PHP.
function Measure-Data { [CmdletBinding()] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, Position=0)] [double[]] $Data ) Begin { function Get-Mode ([double[]]$Data) { if ($Data.Count -gt ($Data | Sele...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Port the following code from Racket to PHP with equivalent syntax and logic.
#lang racket (define (median numbers) (define sorted (list->vector (sort (vector->list numbers) <))) (define count (vector-length numbers)) (if (zero? count) #f (/ (+ (vector-ref sorted (floor (/ (sub1 count) 2))) (vector-ref sorted (floor (/ count 2)))) 2))) (median '#(5 3 4)) ...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Write the same algorithm in PHP as shown in this COBOL implementation.
FUNCTION MEDIAN(some-table (ALL))
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Preserve the algorithm and functionality while converting the code from REXX to PHP.
options replace format comments java crossref symbols nobinary class RAvgMedian00 public -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method median(lvector = java.util.List) public static returns Rexx cvector = ArrayList(lvector) -- make a copy of input to ensure it's conten...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Change the programming language of this snippet from Ruby to PHP without modifying what it does.
def median(ary) srtd = ary.sort alen = srtd.size 0.5*(srtd[(alen-1)//2] + srtd[alen//2]) end a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2] puts median a a = [4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2, 5.0] puts median a a = [5.0] puts median a
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Keep all operations the same but rewrite the snippet in PHP.
fun median(l: List<Double>) = l.sorted().let { (it[it.size / 2] + it[(it.size - 1) / 2]) / 2 } fun main(args: Array<String>) { median(listOf(5.0, 3.0, 4.0)).let { println(it) } median(listOf(5.0, 4.0, 2.0, 3.0)).let { println(it) } median(listOf(3.0, 4.0, 1.0, -8.4, 7.2, 4.0, 1.0, 1.2)).let { println(i...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Ensure the translated PHP code behaves exactly like the original Tcl snippet.
proc median args { set list [lsort -real $args] set len [llength $list] if {$len & 1} { return [lindex $list [expr {($len-1)/2}]] } set idx2 [expr {$len/2}] set idx1 [expr {$idx2-1}] return [expr { ([lindex $list $idx1] + [lindex $list $idx2])/2.0 }] } puts [me...
function median($arr) { sort($arr); $count = count($arr); //count the number of values in array $middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value if ($count % 2) { // odd number, middle is the median $median = $arr[$middleval]; } else { // even number, ca...
Change the following C code into Rust without altering its purpose.
#include <stdio.h> #include <stdlib.h> typedef struct floatList { float *list; int size; } *FloatList; int floatcmp( const void *a, const void *b) { if (*(const float *)a < *(const float *)b) return -1; else return *(const float *)a > *(const float *)b; } float median( FloatList fl ) { qsort( f...
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
Convert this C++ snippet to Rust and keep its semantics consistent.
#include <algorithm> template <typename Iterator> double median(Iterator begin, Iterator end) { Iterator middle = begin + (end - begin) / 2; std::nth_element(begin, middle, end); if ((end - begin) % 2 != 0) { return *middle; } else { Iterator lower_middle = std::max_element(begin, midd...
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
Keep all operations the same but rewrite the snippet in Rust.
using System; using System.Linq; namespace Test { class Program { static void Main() { double[] myArr = new double[] { 1, 5, 3, 6, 4, 2 }; myArr = myArr.OrderBy(i => i).ToArray(); int mid = myArr.Length / 2; double median; ...
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
Please provide an equivalent version of this Java code in Rust.
public static double median(List<Double> list) { Collections.sort(list); return (list.get(list.size() / 2) + list.get((list.size() - 1) / 2)) / 2; }
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
Rewrite this program in Rust while keeping its functionality equivalent to the Go version.
package main import ( "fmt" "sort" ) func main() { fmt.Println(median([]float64{3, 1, 4, 1})) fmt.Println(median([]float64{3, 1, 4, 1, 5})) } func median(a []float64) float64 { sort.Float64s(a) half := len(a) / 2 m := a[half] if len(a)%2 == 0 { m = (m + a[half-1]) / 2 ...
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
Translate the given Rust code snippet into Python without altering its behavior.
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
def median(aray): srtd = sorted(aray) alen = len(srtd) return 0.5*( srtd[(alen-1)//2] + srtd[alen//2]) a = (4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a) a = (4.1, 7.2, 1.7, 9.3, 4.4, 3.2) print a, median(a)
Maintain the same structure and functionality when rewriting this code in VB.
fn median(mut xs: Vec<f64>) -> f64 { xs.sort_by(|x,y| x.partial_cmp(y).unwrap() ); let n = xs.len(); if n % 2 == 0 { (xs[n/2] + xs[n/2 - 1]) / 2.0 } else { xs[n/2] } } fn main() { let nums = vec![2.,3.,5.,0.,9.,82.,353.,32.,12.]; println!("{:?}", median(nums)) }
Private Function medianq(s As Variant) As Double Dim res As Double, tmp As Integer Dim l As Integer, k As Integer res = 0 l = UBound(s): k = WorksheetFunction.Floor_Precise((l + 1) / 2, 1) If l Then res = quick_select(s, k) If l Mod 2 = 0 Then tmp = quick_...
Generate an equivalent C# version of this Ada code.
type Int_Access is access Integer; Int_Acc : Int_Access := new Integer'(5);
static void Main(string[] args) { int p; p = 1; Console.WriteLine("Ref Before: " + p); Value(ref p); Console.WriteLine("Ref After : " + p); p = 1; Console.WriteLine("Val Before: " + p); Value(p); Console.WriteLine("Val After : " + p); Console.ReadLine(); } private static void Value(ref int Value) { Value...
Ensure the translated C code behaves exactly like the original Ada snippet.
type Int_Access is access Integer; Int_Acc : Int_Access := new Integer'(5);
inline unsigned char foo (unsigned char a, unsigned char b, unsigned char c){ return a+b+c; }
Preserve the algorithm and functionality while converting the code from Ada to Java.
type Int_Access is access Integer; Int_Acc : Int_Access := new Integer'(5);
public class Foo { public int x = 0; } void somefunction() { Foo a; a = new Foo(); Foo b = a; a.x = 5; System.out.println(b.x); }
Ensure the translated Python code behaves exactly like the original Ada snippet.
type Int_Access is access Integer; Int_Acc : Int_Access := new Integer'(5);
a = "foo" b = [] class Foo(object): pass c = Foo() class Bar(object): def __init__(self, initializer = None) if initializer is not None: self.value = initializer d = Bar(10) print d.value if a is b: pass if id(a) == id(b): pass def a(fmt, *args): if ...
Write the same code in VB as shown below in Ada.
type Int_Access is access Integer; Int_Acc : Int_Access := new Integer'(5);
Dim samplevariable as New Object Dim anothervariable as Object Set anothervariable = sameplevariable
Port the following code from AutoHotKey to C with equivalent syntax and logic.
VarSetCapacity(var, 100)   NumPut(87, var, 0, "Char")  MsgBox % NumGet(var, 0, "Char")  MsgBox % &var   MsgBox % *&var 
inline unsigned char foo (unsigned char a, unsigned char b, unsigned char c){ return a+b+c; }
Convert this AutoHotKey block to C#, preserving its control flow and logic.
VarSetCapacity(var, 100)   NumPut(87, var, 0, "Char")  MsgBox % NumGet(var, 0, "Char")  MsgBox % &var   MsgBox % *&var 
static void Main(string[] args) { int p; p = 1; Console.WriteLine("Ref Before: " + p); Value(ref p); Console.WriteLine("Ref After : " + p); p = 1; Console.WriteLine("Val Before: " + p); Value(p); Console.WriteLine("Val After : " + p); Console.ReadLine(); } private static void Value(ref int Value) { Value...
Port the provided AutoHotKey code into C++ while preserving the original functionality.
VarSetCapacity(var, 100)   NumPut(87, var, 0, "Char")  MsgBox % NumGet(var, 0, "Char")  MsgBox % &var   MsgBox % *&var 
int* pointer2(&var);
Translate the given AutoHotKey code snippet into Java without altering its behavior.
VarSetCapacity(var, 100)   NumPut(87, var, 0, "Char")  MsgBox % NumGet(var, 0, "Char")  MsgBox % &var   MsgBox % *&var 
public class Foo { public int x = 0; } void somefunction() { Foo a; a = new Foo(); Foo b = a; a.x = 5; System.out.println(b.x); }
Port the following code from AutoHotKey to Python with equivalent syntax and logic.
VarSetCapacity(var, 100)   NumPut(87, var, 0, "Char")  MsgBox % NumGet(var, 0, "Char")  MsgBox % &var   MsgBox % *&var 
a = "foo" b = [] class Foo(object): pass c = Foo() class Bar(object): def __init__(self, initializer = None) if initializer is not None: self.value = initializer d = Bar(10) print d.value if a is b: pass if id(a) == id(b): pass def a(fmt, *args): if ...
Write the same code in VB as shown below in AutoHotKey.
VarSetCapacity(var, 100)   NumPut(87, var, 0, "Char")  MsgBox % NumGet(var, 0, "Char")  MsgBox % &var   MsgBox % *&var 
Dim samplevariable as New Object Dim anothervariable as Object Set anothervariable = sameplevariable
Translate the given AutoHotKey code snippet into Go without altering its behavior.
VarSetCapacity(var, 100)   NumPut(87, var, 0, "Char")  MsgBox % NumGet(var, 0, "Char")  MsgBox % &var   MsgBox % *&var 
var p *int i = &p
Produce a language-to-language conversion: from BBC_Basic to C, same semantics.
pointer_to_varA = ^varA% !pointer_to_varA = 123456 PRINT !pointer_to_varA pointer_to_varB = ^varB |pointer_to_varB = PI PRINT |pointer_to_varB PROCmyproc : pointer_to_myproc = ^PROCmyproc PROC(pointer_to_myproc) ...
inline unsigned char foo (unsigned char a, unsigned char b, unsigned char c){ return a+b+c; }
Generate a C# translation of this BBC_Basic snippet without changing its computational steps.
pointer_to_varA = ^varA% !pointer_to_varA = 123456 PRINT !pointer_to_varA pointer_to_varB = ^varB |pointer_to_varB = PI PRINT |pointer_to_varB PROCmyproc : pointer_to_myproc = ^PROCmyproc PROC(pointer_to_myproc) ...
static void Main(string[] args) { int p; p = 1; Console.WriteLine("Ref Before: " + p); Value(ref p); Console.WriteLine("Ref After : " + p); p = 1; Console.WriteLine("Val Before: " + p); Value(p); Console.WriteLine("Val After : " + p); Console.ReadLine(); } private static void Value(ref int Value) { Value...
Port the following code from BBC_Basic to C++ with equivalent syntax and logic.
pointer_to_varA = ^varA% !pointer_to_varA = 123456 PRINT !pointer_to_varA pointer_to_varB = ^varB |pointer_to_varB = PI PRINT |pointer_to_varB PROCmyproc : pointer_to_myproc = ^PROCmyproc PROC(pointer_to_myproc) ...
int* pointer2(&var);
Change the following BBC_Basic code into Java without altering its purpose.
pointer_to_varA = ^varA% !pointer_to_varA = 123456 PRINT !pointer_to_varA pointer_to_varB = ^varB |pointer_to_varB = PI PRINT |pointer_to_varB PROCmyproc : pointer_to_myproc = ^PROCmyproc PROC(pointer_to_myproc) ...
public class Foo { public int x = 0; } void somefunction() { Foo a; a = new Foo(); Foo b = a; a.x = 5; System.out.println(b.x); }
Rewrite the snippet below in Python so it works the same as the original BBC_Basic code.
pointer_to_varA = ^varA% !pointer_to_varA = 123456 PRINT !pointer_to_varA pointer_to_varB = ^varB |pointer_to_varB = PI PRINT |pointer_to_varB PROCmyproc : pointer_to_myproc = ^PROCmyproc PROC(pointer_to_myproc) ...
a = "foo" b = [] class Foo(object): pass c = Foo() class Bar(object): def __init__(self, initializer = None) if initializer is not None: self.value = initializer d = Bar(10) print d.value if a is b: pass if id(a) == id(b): pass def a(fmt, *args): if ...
Ensure the translated VB code behaves exactly like the original BBC_Basic snippet.
pointer_to_varA = ^varA% !pointer_to_varA = 123456 PRINT !pointer_to_varA pointer_to_varB = ^varB |pointer_to_varB = PI PRINT |pointer_to_varB PROCmyproc : pointer_to_myproc = ^PROCmyproc PROC(pointer_to_myproc) ...
Dim samplevariable as New Object Dim anothervariable as Object Set anothervariable = sameplevariable
Rewrite the snippet below in Go so it works the same as the original BBC_Basic code.
pointer_to_varA = ^varA% !pointer_to_varA = 123456 PRINT !pointer_to_varA pointer_to_varB = ^varB |pointer_to_varB = PI PRINT |pointer_to_varB PROCmyproc : pointer_to_myproc = ^PROCmyproc PROC(pointer_to_myproc) ...
var p *int i = &p
Port the following code from D to C with equivalent syntax and logic.
void main() { int var; int* ptr = &var; int[10] data; auto p2 = data.ptr; struct S {} class C {} void foo1(S s) {} void foo2(C c) {} void foo3(int i) {} void foo4(int[4] i) {} void foo6(int[] i) {} ...
inline unsigned char foo (unsigned char a, unsigned char b, unsigned char c){ return a+b+c; }
Generate an equivalent C# version of this D code.
void main() { int var; int* ptr = &var; int[10] data; auto p2 = data.ptr; struct S {} class C {} void foo1(S s) {} void foo2(C c) {} void foo3(int i) {} void foo4(int[4] i) {} void foo6(int[] i) {} ...
static void Main(string[] args) { int p; p = 1; Console.WriteLine("Ref Before: " + p); Value(ref p); Console.WriteLine("Ref After : " + p); p = 1; Console.WriteLine("Val Before: " + p); Value(p); Console.WriteLine("Val After : " + p); Console.ReadLine(); } private static void Value(ref int Value) { Value...
Write the same algorithm in C++ as shown in this D implementation.
void main() { int var; int* ptr = &var; int[10] data; auto p2 = data.ptr; struct S {} class C {} void foo1(S s) {} void foo2(C c) {} void foo3(int i) {} void foo4(int[4] i) {} void foo6(int[] i) {} ...
int* pointer2(&var);
Port the provided D code into Java while preserving the original functionality.
void main() { int var; int* ptr = &var; int[10] data; auto p2 = data.ptr; struct S {} class C {} void foo1(S s) {} void foo2(C c) {} void foo3(int i) {} void foo4(int[4] i) {} void foo6(int[] i) {} ...
public class Foo { public int x = 0; } void somefunction() { Foo a; a = new Foo(); Foo b = a; a.x = 5; System.out.println(b.x); }
Rewrite the snippet below in Python so it works the same as the original D code.
void main() { int var; int* ptr = &var; int[10] data; auto p2 = data.ptr; struct S {} class C {} void foo1(S s) {} void foo2(C c) {} void foo3(int i) {} void foo4(int[4] i) {} void foo6(int[] i) {} ...
a = "foo" b = [] class Foo(object): pass c = Foo() class Bar(object): def __init__(self, initializer = None) if initializer is not None: self.value = initializer d = Bar(10) print d.value if a is b: pass if id(a) == id(b): pass def a(fmt, *args): if ...
Write the same algorithm in VB as shown in this D implementation.
void main() { int var; int* ptr = &var; int[10] data; auto p2 = data.ptr; struct S {} class C {} void foo1(S s) {} void foo2(C c) {} void foo3(int i) {} void foo4(int[4] i) {} void foo6(int[] i) {} ...
Dim samplevariable as New Object Dim anothervariable as Object Set anothervariable = sameplevariable
Write the same algorithm in Go as shown in this D implementation.
void main() { int var; int* ptr = &var; int[10] data; auto p2 = data.ptr; struct S {} class C {} void foo1(S s) {} void foo2(C c) {} void foo3(int i) {} void foo4(int[4] i) {} void foo6(int[] i) {} ...
var p *int i = &p