Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Rewrite the snippet below in C# so it works the same as the original PowerShell code.
function Select-NumberFromString { [CmdletBinding(DefaultParameterSetName="Decimal")] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [...
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
Produce a functionally identical C++ code for the snippet given in PowerShell.
function Select-NumberFromString { [CmdletBinding(DefaultParameterSetName="Decimal")] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [...
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
Write a version of this PowerShell function in Java with identical behavior.
function Select-NumberFromString { [CmdletBinding(DefaultParameterSetName="Decimal")] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [...
Scanner sc = new Scanner(System.in); sc.useRadix(base); sc.nextInt();
Change the programming language of this snippet from PowerShell to Python without modifying what it does.
function Select-NumberFromString { [CmdletBinding(DefaultParameterSetName="Decimal")] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [...
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Rewrite the snippet below in Go so it works the same as the original PowerShell code.
function Select-NumberFromString { [CmdletBinding(DefaultParameterSetName="Decimal")] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [...
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
Convert the following code from R to C, ensuring the logic remains intact.
as.numeric("20") as.numeric("0x20") as.hexmode(as.numeric("32")) as.octmode(as.numeric("20"))
#include <stdio.h> int main() { int num; sscanf("0123459", "%d", &num); printf("%d\n", num); sscanf("abcf123", "%x", &num); printf("%d\n", num); sscanf("7651", "%o", &num); printf("%d\n", num); return 0; }
Preserve the algorithm and functionality while converting the code from R to C#.
as.numeric("20") as.numeric("0x20") as.hexmode(as.numeric("32")) as.octmode(as.numeric("20"))
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
Port the provided R code into C++ while preserving the original functionality.
as.numeric("20") as.numeric("0x20") as.hexmode(as.numeric("32")) as.octmode(as.numeric("20"))
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
Ensure the translated Java code behaves exactly like the original R snippet.
as.numeric("20") as.numeric("0x20") as.hexmode(as.numeric("32")) as.octmode(as.numeric("20"))
Scanner sc = new Scanner(System.in); sc.useRadix(base); sc.nextInt();
Preserve the algorithm and functionality while converting the code from R to Python.
as.numeric("20") as.numeric("0x20") as.hexmode(as.numeric("32")) as.octmode(as.numeric("20"))
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Produce a functionally identical Go code for the snippet given in R.
as.numeric("20") as.numeric("0x20") as.hexmode(as.numeric("32")) as.octmode(as.numeric("20"))
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
Maintain the same structure and functionality when rewriting this code in C.
#lang racket (list 123 #x7B #o173 #b1111011) (list (string->number "123") (string->number "123" 10) (string->number "7B" 16) (string->number "83" 15) (string->number "96" 13) (string->number "173" 8) (string->number "11120" 3) (string->number...
#include <stdio.h> int main() { int num; sscanf("0123459", "%d", &num); printf("%d\n", num); sscanf("abcf123", "%x", &num); printf("%d\n", num); sscanf("7651", "%o", &num); printf("%d\n", num); return 0; }
Transform the following Racket implementation into C#, maintaining the same output and logic.
#lang racket (list 123 #x7B #o173 #b1111011) (list (string->number "123") (string->number "123" 10) (string->number "7B" 16) (string->number "83" 15) (string->number "96" 13) (string->number "173" 8) (string->number "11120" 3) (string->number...
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
Please provide an equivalent version of this Racket code in C++.
#lang racket (list 123 #x7B #o173 #b1111011) (list (string->number "123") (string->number "123" 10) (string->number "7B" 16) (string->number "83" 15) (string->number "96" 13) (string->number "173" 8) (string->number "11120" 3) (string->number...
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
Port the following code from Racket to Java with equivalent syntax and logic.
#lang racket (list 123 #x7B #o173 #b1111011) (list (string->number "123") (string->number "123" 10) (string->number "7B" 16) (string->number "83" 15) (string->number "96" 13) (string->number "173" 8) (string->number "11120" 3) (string->number...
Scanner sc = new Scanner(System.in); sc.useRadix(base); sc.nextInt();
Port the following code from Racket to Python with equivalent syntax and logic.
#lang racket (list 123 #x7B #o173 #b1111011) (list (string->number "123") (string->number "123" 10) (string->number "7B" 16) (string->number "83" 15) (string->number "96" 13) (string->number "173" 8) (string->number "11120" 3) (string->number...
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Port the following code from Racket to Go with equivalent syntax and logic.
#lang racket (list 123 #x7B #o173 #b1111011) (list (string->number "123") (string->number "123" 10) (string->number "7B" 16) (string->number "83" 15) (string->number "96" 13) (string->number "173" 8) (string->number "11120" 3) (string->number...
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
Rewrite the snippet below in C so it works the same as the original REXX code.
a=123 b='123' c='1' || "2" || '3' d= 1 || 2 || 3 e= 12 || 3 f=120 + 3 g=substr(9912388,3,3) h=left(123456,3) i=right(777.123,3) j=120 + ' 3 ' k=0000000123.0000/1 ...
#include <stdio.h> int main() { int num; sscanf("0123459", "%d", &num); printf("%d\n", num); sscanf("abcf123", "%x", &num); printf("%d\n", num); sscanf("7651", "%o", &num); printf("%d\n", num); return 0; }
Write a version of this REXX function in C# with identical behavior.
a=123 b='123' c='1' || "2" || '3' d= 1 || 2 || 3 e= 12 || 3 f=120 + 3 g=substr(9912388,3,3) h=left(123456,3) i=right(777.123,3) j=120 + ' 3 ' k=0000000123.0000/1 ...
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
Port the provided REXX code into C++ while preserving the original functionality.
a=123 b='123' c='1' || "2" || '3' d= 1 || 2 || 3 e= 12 || 3 f=120 + 3 g=substr(9912388,3,3) h=left(123456,3) i=right(777.123,3) j=120 + ' 3 ' k=0000000123.0000/1 ...
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
Please provide an equivalent version of this REXX code in Java.
a=123 b='123' c='1' || "2" || '3' d= 1 || 2 || 3 e= 12 || 3 f=120 + 3 g=substr(9912388,3,3) h=left(123456,3) i=right(777.123,3) j=120 + ' 3 ' k=0000000123.0000/1 ...
Scanner sc = new Scanner(System.in); sc.useRadix(base); sc.nextInt();
Please provide an equivalent version of this REXX code in Python.
a=123 b='123' c='1' || "2" || '3' d= 1 || 2 || 3 e= 12 || 3 f=120 + 3 g=substr(9912388,3,3) h=left(123456,3) i=right(777.123,3) j=120 + ' 3 ' k=0000000123.0000/1 ...
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Rewrite the snippet below in Go so it works the same as the original REXX code.
a=123 b='123' c='1' || "2" || '3' d= 1 || 2 || 3 e= 12 || 3 f=120 + 3 g=substr(9912388,3,3) h=left(123456,3) i=right(777.123,3) j=120 + ' 3 ' k=0000000123.0000/1 ...
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
Write the same algorithm in C as shown in this Ruby implementation.
dec1 = "0123459" hex2 = "abcf123" oct3 = "7651" bin4 = "101011001" p dec1.to_i p hex2.hex p oct3.oct
#include <stdio.h> int main() { int num; sscanf("0123459", "%d", &num); printf("%d\n", num); sscanf("abcf123", "%x", &num); printf("%d\n", num); sscanf("7651", "%o", &num); printf("%d\n", num); return 0; }
Change the following Ruby code into C# without altering its purpose.
dec1 = "0123459" hex2 = "abcf123" oct3 = "7651" bin4 = "101011001" p dec1.to_i p hex2.hex p oct3.oct
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
Transform the following Ruby implementation into C++, maintaining the same output and logic.
dec1 = "0123459" hex2 = "abcf123" oct3 = "7651" bin4 = "101011001" p dec1.to_i p hex2.hex p oct3.oct
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
Rewrite this program in Python while keeping its functionality equivalent to the Ruby version.
dec1 = "0123459" hex2 = "abcf123" oct3 = "7651" bin4 = "101011001" p dec1.to_i p hex2.hex p oct3.oct
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Change the following Ruby code into Go without altering its purpose.
dec1 = "0123459" hex2 = "abcf123" oct3 = "7651" bin4 = "101011001" p dec1.to_i p hex2.hex p oct3.oct
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
Port the provided Scala code into C while preserving the original functionality.
fun main(args: Array<String>) { val s = "100" val bases = intArrayOf(2, 8, 10, 16, 19, 36) for (base in bases) println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}") }
#include <stdio.h> int main() { int num; sscanf("0123459", "%d", &num); printf("%d\n", num); sscanf("abcf123", "%x", &num); printf("%d\n", num); sscanf("7651", "%o", &num); printf("%d\n", num); return 0; }
Port the following code from Scala to C# with equivalent syntax and logic.
fun main(args: Array<String>) { val s = "100" val bases = intArrayOf(2, 8, 10, 16, 19, 36) for (base in bases) println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}") }
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
Generate a C++ translation of this Scala snippet without changing its computational steps.
fun main(args: Array<String>) { val s = "100" val bases = intArrayOf(2, 8, 10, 16, 19, 36) for (base in bases) println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}") }
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
Change the following Scala code into Java without altering its purpose.
fun main(args: Array<String>) { val s = "100" val bases = intArrayOf(2, 8, 10, 16, 19, 36) for (base in bases) println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}") }
Scanner sc = new Scanner(System.in); sc.useRadix(base); sc.nextInt();
Convert the following code from Scala to Python, ensuring the logic remains intact.
fun main(args: Array<String>) { val s = "100" val bases = intArrayOf(2, 8, 10, 16, 19, 36) for (base in bases) println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}") }
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Write a version of this Scala function in Go with identical behavior.
fun main(args: Array<String>) { val s = "100" val bases = intArrayOf(2, 8, 10, 16, 19, 36) for (base in bases) println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}") }
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
Port the following code from Tcl to C with equivalent syntax and logic.
package require Tcl 8.6; set dec1 "0123459" set hex2 "abcf123" set oct3 "7651" set bin4 "101011001" scan $dec1 "%d" v1 scan $hex2 "%x" v2 scan $oct3 "%o" v3 scan $bin4 "%b" v4; puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
#include <stdio.h> int main() { int num; sscanf("0123459", "%d", &num); printf("%d\n", num); sscanf("abcf123", "%x", &num); printf("%d\n", num); sscanf("7651", "%o", &num); printf("%d\n", num); return 0; }
Generate a C# translation of this Tcl snippet without changing its computational steps.
package require Tcl 8.6; set dec1 "0123459" set hex2 "abcf123" set oct3 "7651" set bin4 "101011001" scan $dec1 "%d" v1 scan $hex2 "%x" v2 scan $oct3 "%o" v3 scan $bin4 "%b" v4; puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
Change the programming language of this snippet from Tcl to C++ without modifying what it does.
package require Tcl 8.6; set dec1 "0123459" set hex2 "abcf123" set oct3 "7651" set bin4 "101011001" scan $dec1 "%d" v1 scan $hex2 "%x" v2 scan $oct3 "%o" v3 scan $bin4 "%b" v4; puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
Can you help me rewrite this code in Java instead of Tcl, keeping it the same logically?
package require Tcl 8.6; set dec1 "0123459" set hex2 "abcf123" set oct3 "7651" set bin4 "101011001" scan $dec1 "%d" v1 scan $hex2 "%x" v2 scan $oct3 "%o" v3 scan $bin4 "%b" v4; puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
Scanner sc = new Scanner(System.in); sc.useRadix(base); sc.nextInt();
Write a version of this Tcl function in Python with identical behavior.
package require Tcl 8.6; set dec1 "0123459" set hex2 "abcf123" set oct3 "7651" set bin4 "101011001" scan $dec1 "%d" v1 scan $hex2 "%x" v2 scan $oct3 "%o" v3 scan $bin4 "%b" v4; puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Preserve the algorithm and functionality while converting the code from Tcl to Go.
package require Tcl 8.6; set dec1 "0123459" set hex2 "abcf123" set oct3 "7651" set bin4 "101011001" scan $dec1 "%d" v1 scan $hex2 "%x" v2 scan $oct3 "%o" v3 scan $bin4 "%b" v4; puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
Produce a language-to-language conversion: from Rust to PHP, same semantics.
fn main() { println!( "Parse from plain decimal: {}", "123".parse::<u32>().unwrap() ); println!( "Parse with a given radix (2-36 supported): {}", u32::from_str_radix("deadbeef", 16).unwrap() ); }
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Maintain the same structure and functionality when rewriting this code in PHP.
with Ada.Text_IO; procedure Numbers is package Int_IO is new Ada.Text_IO.Integer_IO (Integer); package Float_IO is new Ada.Text_IO.Float_IO (Float); begin Int_IO.Put (Integer'Value ("16#ABCF123#")); Ada.Text_IO.New_Line; Int_IO.Put (Integer'Value ("8#7651#")); Ada.Text_IO.New_Line; Int_IO.Put (Inte...
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Translate this program into PHP but keep the logic exactly as in Arturo.
print to :integer "10"   print from.hex "10"   print from.octal "120"   print from.binary "10101"  
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Port the following code from BBC_Basic to PHP with equivalent syntax and logic.
PRINT VAL("0") PRINT VAL("123456789") PRINT VAL("-987654321") PRINT EVAL("%10101010") PRINT EVAL("%1111111111") PRINT EVAL("&ABCD") PRINT EVAL("&FFFFFFFF")
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Keep all operations the same but rewrite the snippet in PHP.
(parse-integer "abc" :radix 20 :junk-allowed t)
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Can you help me rewrite this code in PHP instead of D, keeping it the same logically?
import std.stdio, std.conv; void main() { immutable text = "100"; foreach (base; 2 .. 21) writefln("String '%s' in base %d is %d in base 10" , text, base, to!int(text, base)); }
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Keep all operations the same but rewrite the snippet in PHP.
function InputByRadix(S: string; Radix: integer): integer; var I,B: integer; begin Result:=0; S:=UpperCase(S); for I:=1 to Length(S) do begin if S[I] in ['0'..'9'] then B:=byte(S[I])-$30 else if S[I] in ['A'..'Z'] then B:=byte(S[I])-$41; Result:=Result * Radix + B; end; end; procedure ShowRadixInput(Memo: TMemo...
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Convert this Elixir snippet to PHP and keep its semantics consistent.
iex(1)> String.to_integer("1000") 1000 iex(2)> String.to_integer("1000",2) 8 iex(3)> String.to_integer("1000",8) 512 iex(4)> String.to_integer("1000",16) 4096 iex(5)> String.to_integer("ffff",16) 65535
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Generate a PHP translation of this F# snippet without changing its computational steps.
let value = "100" let fromBases = [ 2; 8; 10; 16 ] let values = Seq.initInfinite (fun i -> value) Seq.zip fromBases (Seq.zip values fromBases |> Seq.map (System.Convert.ToInt32)) |> Seq.iter ( fun (fromBase, valueFromBaseX) -> printfn "%s in base %i is %i in base 10" value fromBase valueFromBaseX)
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Write the same code in PHP as shown below in Factor.
IN: math.parser : oct> ( str -- n/f ) 8 base> ; inline
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Rewrite this program in PHP while keeping its functionality equivalent to the Forth version.
: parse# 0. 2SWAP DUP >R >NUMBER NIP NIP R> <> DUP 0= IF NIP THEN ; : base# BASE @ >R BASE ! parse# R> BASE ! ;
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Preserve the algorithm and functionality while converting the code from Fortran to PHP.
program Example implicit none integer :: num character(32) :: str str = "0123459" read(str, "(i10)") num write(*,*) num str = "abcf123" read(str, "(z8)") num write(*,*) num str = "7651" read(str, "(o11)") num write(*,*) num str = "1010011010" r...
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Rewrite the snippet below in PHP so it works the same as the original Haskell code.
Prelude> read "123459" :: Integer 123459 Prelude> read "0xabcf123" :: Integer 180154659 Prelude> read "0o7651" :: Integer 4009
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Maintain the same structure and functionality when rewriting this code in PHP.
procedure convert (str) write (left(str, 10) || " = " || integer(str)) end procedure main () convert (" 2r1001") convert (" 8r7135") convert ("16rABC1234") convert ("36r1Z") write ("2r1001" + "36r1Z") end
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Generate a PHP translation of this J snippet without changing its computational steps.
baseN=: (, 'b'&,)&.":
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Keep all operations the same but rewrite the snippet in PHP.
txt = "100" for base = 2:21 base10 = parse(Int, txt, base) println("String $txt in base $base is $base10 in base 10") end
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Generate a PHP translation of this Lua snippet without changing its computational steps.
print( tonumber("123") ) print( tonumber("a5b0", 16) ) print( tonumber("011101", 2) ) print( tonumber("za3r", 36) )
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Rewrite this program in PHP while keeping its functionality equivalent to the Mathematica version.
19^^91g5dcg2h6da7260a9f3c4a 2^^11110001001000000
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Rewrite the snippet below in PHP so it works the same as the original MATLAB code.
val = sscanf('11 11 11','
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Keep all operations the same but rewrite the snippet in PHP.
import strutils echo parseInt "10" echo parseHexInt "0x10" echo parseHexInt "10" echo parseOctInt "0o120" echo parseOctInt "120"
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Transform the following OCaml implementation into PHP, maintaining the same output and logic.
# int_of_string "123459";; - : int = 123459 # int_of_string "0xabcf123";; - : int = 180154659 # int_of_string "0o7651";; - : int = 4009 # int_of_string "0b101011001";; - : int = 345
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Translate the given Pascal code snippet into PHP without altering its behavior.
program readIntegers(input, output); var i: aluSInt; begin while not EOF(input) do begin readLn(i); writeLn(i:24); end; end.
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Port the provided Perl code into PHP while preserving the original functionality.
my $dec = "0123459"; my $hex_noprefix = "abcf123"; my $hex_withprefix = "0xabcf123"; my $oct_noprefix = "7651"; my $oct_withprefix = "07651"; my $bin_withprefix = "0b101011001"; print 0 + $dec, "\n"; print hex($hex_noprefix), "\n"; print hex($hex_withprefix), "\n"; print oct($hex_withprefix), "\n"; prin...
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Produce a language-to-language conversion: from PowerShell to PHP, same semantics.
function Select-NumberFromString { [CmdletBinding(DefaultParameterSetName="Decimal")] [OutputType([PSCustomObject])] Param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [...
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Produce a language-to-language conversion: from R to PHP, same semantics.
as.numeric("20") as.numeric("0x20") as.hexmode(as.numeric("32")) as.octmode(as.numeric("20"))
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Convert this Racket block to PHP, preserving its control flow and logic.
#lang racket (list 123 #x7B #o173 #b1111011) (list (string->number "123") (string->number "123" 10) (string->number "7B" 16) (string->number "83" 15) (string->number "96" 13) (string->number "173" 8) (string->number "11120" 3) (string->number...
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Preserve the algorithm and functionality while converting the code from REXX to PHP.
a=123 b='123' c='1' || "2" || '3' d= 1 || 2 || 3 e= 12 || 3 f=120 + 3 g=substr(9912388,3,3) h=left(123456,3) i=right(777.123,3) j=120 + ' 3 ' k=0000000123.0000/1 ...
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Rewrite the snippet below in PHP so it works the same as the original Ruby code.
dec1 = "0123459" hex2 = "abcf123" oct3 = "7651" bin4 = "101011001" p dec1.to_i p hex2.hex p oct3.oct
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Ensure the translated PHP code behaves exactly like the original Scala snippet.
fun main(args: Array<String>) { val s = "100" val bases = intArrayOf(2, 8, 10, 16, 19, 36) for (base in bases) println("$s in base ${"%2d".format(base)} is ${s.toInt(base)}") }
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Preserve the algorithm and functionality while converting the code from Tcl to PHP.
package require Tcl 8.6; set dec1 "0123459" set hex2 "abcf123" set oct3 "7651" set bin4 "101011001" scan $dec1 "%d" v1 scan $hex2 "%x" v2 scan $oct3 "%o" v3 scan $bin4 "%b" v4; puts "$dec1->$v1 $hex2->$v2 $oct3->$v3 $bin4->$v4"
<?php echo +"0123459", "\n"; // prints 123459 echo intval("0123459"), "\n"; // prints 123459 echo hexdec("abcf123"), "\n"; // prints 180154659 echo octdec("7651"), "\n"; // prints 4009 echo bindec("101011001"), "\n"; // prints 345 ?>
Ensure the translated Rust code behaves exactly like the original C snippet.
#include <stdio.h> int main() { int num; sscanf("0123459", "%d", &num); printf("%d\n", num); sscanf("abcf123", "%x", &num); printf("%d\n", num); sscanf("7651", "%o", &num); printf("%d\n", num); return 0; }
fn main() { println!( "Parse from plain decimal: {}", "123".parse::<u32>().unwrap() ); println!( "Parse with a given radix (2-36 supported): {}", u32::from_str_radix("deadbeef", 16).unwrap() ); }
Port the following code from C++ to Rust with equivalent syntax and logic.
#include <iostream> #include <sstream> int main() { int num; std::istringstream("0123459") >> num; std::cout << num << std::endl; std::istringstream("0123459") >> std::dec >> num; std::cout << num << std::endl; std::istringstream("abcf123") >> std::hex >> num; std::cout << num << std::endl; std:...
fn main() { println!( "Parse from plain decimal: {}", "123".parse::<u32>().unwrap() ); println!( "Parse with a given radix (2-36 supported): {}", u32::from_str_radix("deadbeef", 16).unwrap() ); }
Produce a functionally identical Rust code for the snippet given in C#.
using System; class Program { static void Main() { var value = "100"; var fromBases = new[] { 2, 8, 10, 16 }; var toBase = 10; foreach (var fromBase in fromBases) { Console.WriteLine("{0} in base {1} is {2} in base {3}", value, fromBase, Conve...
fn main() { println!( "Parse from plain decimal: {}", "123".parse::<u32>().unwrap() ); println!( "Parse with a given radix (2-36 supported): {}", u32::from_str_radix("deadbeef", 16).unwrap() ); }
Translate this program into Rust but keep the logic exactly as in Java.
Scanner sc = new Scanner(System.in); sc.useRadix(base); sc.nextInt();
fn main() { println!( "Parse from plain decimal: {}", "123".parse::<u32>().unwrap() ); println!( "Parse with a given radix (2-36 supported): {}", u32::from_str_radix("deadbeef", 16).unwrap() ); }
Can you help me rewrite this code in Rust instead of Go, keeping it the same logically?
package main import ( "fmt" "math/big" "strconv" ) func main() { x, _ := strconv.Atoi("13") fmt.Println(x) x64, _ := strconv.ParseInt("3c2", 19, 64) fmt.Println(x64) fmt.Sscanf("1101", "%b", &x) fmt.Println(x) fmt.S...
fn main() { println!( "Parse from plain decimal: {}", "123".parse::<u32>().unwrap() ); println!( "Parse with a given radix (2-36 supported): {}", u32::from_str_radix("deadbeef", 16).unwrap() ); }
Ensure the translated Python code behaves exactly like the original Rust snippet.
fn main() { println!( "Parse from plain decimal: {}", "123".parse::<u32>().unwrap() ); println!( "Parse with a given radix (2-36 supported): {}", u32::from_str_radix("deadbeef", 16).unwrap() ); }
>>> text = '100' >>> for base in range(2,21): print ("String '%s' in base %i is %i in base 10" % (text, base, int(text, base))) String '100' in base 2 is 4 in base 10 String '100' in base 3 is 9 in base 10 String '100' in base 4 is 16 in base 10 String '100' in base 5 is 25 in base 10 String '1...
Generate an equivalent C# version of this Ada code.
package Random_57 is type Mod_7 is mod 7; function Random7 return Mod_7; function Simple_Random7 return Mod_7; end Random_57;
using System; public class SevenSidedDice { Random random = new Random(); static void Main(string[] args) { SevenSidedDice sevenDice = new SevenSidedDice(); Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven()); Console.Read(); } int seven() { int v=21; w...
Transform the following Ada implementation into C, maintaining the same output and logic.
package Random_57 is type Mod_7 is mod 7; function Random7 return Mod_7; function Simple_Random7 return Mod_7; end Random_57;
int rand5() { int r, rand_max = RAND_MAX - (RAND_MAX % 5); while ((r = rand()) >= rand_max); return r / (rand_max / 5) + 1; } int rand5_7() { int r; while ((r = rand5() * 5 + rand5()) >= 27); return r / 3 - 1; } int main() { printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n"); printf(check(rand7,...
Transform the following Ada implementation into C++, maintaining the same output and logic.
package Random_57 is type Mod_7 is mod 7; function Random7 return Mod_7; function Simple_Random7 return Mod_7; end Random_57;
template<typename F> class fivetoseven { public: fivetoseven(F f): d5(f), rem(0), max(1) {} int operator()(); private: F d5; int rem, max; }; template<typename F> int fivetoseven<F>::operator()() { while (rem/7 == max/7) { while (max < 7) { int rand5 = d5()-1; max *= 5; rem = 5*r...
Convert this Ada snippet to Go and keep its semantics consistent.
package Random_57 is type Mod_7 is mod 7; function Random7 return Mod_7; function Simple_Random7 return Mod_7; end Random_57;
package main import ( "fmt" "math" "math/rand" "time" ) func dice5() int { return rand.Intn(5) + 1 } func dice7() (i int) { for { i = 5*dice5() + dice5() if i < 27 { break } } return (i / 3) - 1 } func distCheck(f func() int, n int, ...
Transform the following Ada implementation into Java, maintaining the same output and logic.
package Random_57 is type Mod_7 is mod 7; function Random7 return Mod_7; function Simple_Random7 return Mod_7; end Random_57;
import java.util.Random; public class SevenSidedDice { private static final Random rnd = new Random(); public static void main(String[] args) { SevenSidedDice now=new SevenSidedDice(); System.out.println("Random number from 1 to 7: "+now.seven()); } int seven() { int v=21; while(v>20) v=five()+five()*...
Keep all operations the same but rewrite the snippet in Python.
package Random_57 is type Mod_7 is mod 7; function Random7 return Mod_7; function Simple_Random7 return Mod_7; end Random_57;
from random import randint def dice5(): return randint(1, 5) def dice7(): r = dice5() + dice5() * 5 - 6 return (r % 7) + 1 if r < 21 else dice7()
Transform the following Ada implementation into VB, maintaining the same output and logic.
package Random_57 is type Mod_7 is mod 7; function Random7 return Mod_7; function Simple_Random7 return Mod_7; end Random_57;
Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean Dim Total As Long, Ei As Long, i As Integer Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double Debug.Print "[1] ""Data set:"" "; For i = LBound(Observation...
Convert this AutoHotKey snippet to C and keep its semantics consistent.
dice5() { Random, v, 1, 5 Return, v } dice7() { Loop { v := 5 * dice5() + dice5() - 6 IfLess v, 21, Return, (v // 3) + 1 } }
int rand5() { int r, rand_max = RAND_MAX - (RAND_MAX % 5); while ((r = rand()) >= rand_max); return r / (rand_max / 5) + 1; } int rand5_7() { int r; while ((r = rand5() * 5 + rand5()) >= 27); return r / 3 - 1; } int main() { printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n"); printf(check(rand7,...
Convert this AutoHotKey snippet to C# and keep its semantics consistent.
dice5() { Random, v, 1, 5 Return, v } dice7() { Loop { v := 5 * dice5() + dice5() - 6 IfLess v, 21, Return, (v // 3) + 1 } }
using System; public class SevenSidedDice { Random random = new Random(); static void Main(string[] args) { SevenSidedDice sevenDice = new SevenSidedDice(); Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven()); Console.Read(); } int seven() { int v=21; w...
Write the same code in C++ as shown below in AutoHotKey.
dice5() { Random, v, 1, 5 Return, v } dice7() { Loop { v := 5 * dice5() + dice5() - 6 IfLess v, 21, Return, (v // 3) + 1 } }
template<typename F> class fivetoseven { public: fivetoseven(F f): d5(f), rem(0), max(1) {} int operator()(); private: F d5; int rem, max; }; template<typename F> int fivetoseven<F>::operator()() { while (rem/7 == max/7) { while (max < 7) { int rand5 = d5()-1; max *= 5; rem = 5*r...
Convert this AutoHotKey block to Java, preserving its control flow and logic.
dice5() { Random, v, 1, 5 Return, v } dice7() { Loop { v := 5 * dice5() + dice5() - 6 IfLess v, 21, Return, (v // 3) + 1 } }
import java.util.Random; public class SevenSidedDice { private static final Random rnd = new Random(); public static void main(String[] args) { SevenSidedDice now=new SevenSidedDice(); System.out.println("Random number from 1 to 7: "+now.seven()); } int seven() { int v=21; while(v>20) v=five()+five()*...
Rewrite this program in Python while keeping its functionality equivalent to the AutoHotKey version.
dice5() { Random, v, 1, 5 Return, v } dice7() { Loop { v := 5 * dice5() + dice5() - 6 IfLess v, 21, Return, (v // 3) + 1 } }
from random import randint def dice5(): return randint(1, 5) def dice7(): r = dice5() + dice5() * 5 - 6 return (r % 7) + 1 if r < 21 else dice7()
Produce a functionally identical VB code for the snippet given in AutoHotKey.
dice5() { Random, v, 1, 5 Return, v } dice7() { Loop { v := 5 * dice5() + dice5() - 6 IfLess v, 21, Return, (v // 3) + 1 } }
Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean Dim Total As Long, Ei As Long, i As Integer Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double Debug.Print "[1] ""Data set:"" "; For i = LBound(Observation...
Preserve the algorithm and functionality while converting the code from AutoHotKey to Go.
dice5() { Random, v, 1, 5 Return, v } dice7() { Loop { v := 5 * dice5() + dice5() - 6 IfLess v, 21, Return, (v // 3) + 1 } }
package main import ( "fmt" "math" "math/rand" "time" ) func dice5() int { return rand.Intn(5) + 1 } func dice7() (i int) { for { i = 5*dice5() + dice5() if i < 27 { break } } return (i / 3) - 1 } func distCheck(f func() int, n int, ...
Port the provided BBC_Basic code into C while preserving the original functionality.
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice7, 10^r%, 0.1) PRINT "Over "; 10^r% " runs dice7 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT ...
int rand5() { int r, rand_max = RAND_MAX - (RAND_MAX % 5); while ((r = rand()) >= rand_max); return r / (rand_max / 5) + 1; } int rand5_7() { int r; while ((r = rand5() * 5 + rand5()) >= 27); return r / 3 - 1; } int main() { printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n"); printf(check(rand7,...
Convert this BBC_Basic block to C#, preserving its control flow and logic.
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice7, 10^r%, 0.1) PRINT "Over "; 10^r% " runs dice7 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT ...
using System; public class SevenSidedDice { Random random = new Random(); static void Main(string[] args) { SevenSidedDice sevenDice = new SevenSidedDice(); Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven()); Console.Read(); } int seven() { int v=21; w...
Write a version of this BBC_Basic function in C++ with identical behavior.
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice7, 10^r%, 0.1) PRINT "Over "; 10^r% " runs dice7 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT ...
template<typename F> class fivetoseven { public: fivetoseven(F f): d5(f), rem(0), max(1) {} int operator()(); private: F d5; int rem, max; }; template<typename F> int fivetoseven<F>::operator()() { while (rem/7 == max/7) { while (max < 7) { int rand5 = d5()-1; max *= 5; rem = 5*r...
Change the following BBC_Basic code into Java without altering its purpose.
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice7, 10^r%, 0.1) PRINT "Over "; 10^r% " runs dice7 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT ...
import java.util.Random; public class SevenSidedDice { private static final Random rnd = new Random(); public static void main(String[] args) { SevenSidedDice now=new SevenSidedDice(); System.out.println("Random number from 1 to 7: "+now.seven()); } int seven() { int v=21; while(v>20) v=five()+five()*...
Ensure the translated Python code behaves exactly like the original BBC_Basic snippet.
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice7, 10^r%, 0.1) PRINT "Over "; 10^r% " runs dice7 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT ...
from random import randint def dice5(): return randint(1, 5) def dice7(): r = dice5() + dice5() * 5 - 6 return (r % 7) + 1 if r < 21 else dice7()
Ensure the translated VB code behaves exactly like the original BBC_Basic snippet.
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice7, 10^r%, 0.1) PRINT "Over "; 10^r% " runs dice7 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT ...
Private Function Test4DiscreteUniformDistribution(ObservationFrequencies() As Variant, Significance As Single) As Boolean Dim Total As Long, Ei As Long, i As Integer Dim ChiSquared As Double, DegreesOfFreedom As Integer, p_value As Double Debug.Print "[1] ""Data set:"" "; For i = LBound(Observation...
Convert the following code from BBC_Basic to Go, ensuring the logic remains intact.
MAXRND = 7 FOR r% = 2 TO 5 check% = FNdistcheck(FNdice7, 10^r%, 0.1) PRINT "Over "; 10^r% " runs dice7 "; IF check% THEN PRINT "failed distribution check with "; check% " bin(s) out of range" ELSE PRINT "passed distribution check" ENDIF NEXT ...
package main import ( "fmt" "math" "math/rand" "time" ) func dice5() int { return rand.Intn(5) + 1 } func dice7() (i int) { for { i = 5*dice5() + dice5() if i < 27 { break } } return (i / 3) - 1 } func distCheck(f func() int, n int, ...
Convert the following code from Clojure to C, ensuring the logic remains intact.
(def dice5 #(rand-int 5)) (defn dice7 [] (quot (->> dice5 (repeatedly 2) (apply #(+ %1 (* 5 %2))) #() repeatedly (drop-while #(> % 20)) first) ...
int rand5() { int r, rand_max = RAND_MAX - (RAND_MAX % 5); while ((r = rand()) >= rand_max); return r / (rand_max / 5) + 1; } int rand5_7() { int r; while ((r = rand5() * 5 + rand5()) >= 27); return r / 3 - 1; } int main() { printf(check(rand5, 5, 1000000, .05) ? "flat\n" : "not flat\n"); printf(check(rand7,...
Write the same code in C# as shown below in Clojure.
(def dice5 #(rand-int 5)) (defn dice7 [] (quot (->> dice5 (repeatedly 2) (apply #(+ %1 (* 5 %2))) #() repeatedly (drop-while #(> % 20)) first) ...
using System; public class SevenSidedDice { Random random = new Random(); static void Main(string[] args) { SevenSidedDice sevenDice = new SevenSidedDice(); Console.WriteLine("Random number from 1 to 7: "+ sevenDice.seven()); Console.Read(); } int seven() { int v=21; w...
Change the programming language of this snippet from Clojure to C++ without modifying what it does.
(def dice5 #(rand-int 5)) (defn dice7 [] (quot (->> dice5 (repeatedly 2) (apply #(+ %1 (* 5 %2))) #() repeatedly (drop-while #(> % 20)) first) ...
template<typename F> class fivetoseven { public: fivetoseven(F f): d5(f), rem(0), max(1) {} int operator()(); private: F d5; int rem, max; }; template<typename F> int fivetoseven<F>::operator()() { while (rem/7 == max/7) { while (max < 7) { int rand5 = d5()-1; max *= 5; rem = 5*r...