Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Translate this program into Python but keep the logic exactly as in Mathematica. | Extra = "little";
StringReplace["Mary had a X lamb.", {"X" -> Extra}]
->"Mary had a little lamb."
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Port the provided Mathematica code into VB while preserving the original functionality. | Extra = "little";
StringReplace["Mary had a X lamb.", {"X" -> Extra}]
->"Mary had a little lamb."
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Convert this Mathematica block to Go, preserving its control flow and logic. | Extra = "little";
StringReplace["Mary had a X lamb.", {"X" -> Extra}]
->"Mary had a little lamb."
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Maintain the same structure and functionality when rewriting this code in C. | import strutils
var str = "little"
echo "Mary had a $
echo "Mary had a $
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Translate this program into C# but keep the logic exactly as in Nim. | import strutils
var str = "little"
echo "Mary had a $
echo "Mary had a $
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Produce a functionally identical C++ code for the snippet given in Nim. | import strutils
var str = "little"
echo "Mary had a $
echo "Mary had a $
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Maintain the same structure and functionality when rewriting this code in Java. | import strutils
var str = "little"
echo "Mary had a $
echo "Mary had a $
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Produce a functionally identical Python code for the snippet given in Nim. | import strutils
var str = "little"
echo "Mary had a $
echo "Mary had a $
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Ensure the translated VB code behaves exactly like the original Nim snippet. | import strutils
var str = "little"
echo "Mary had a $
echo "Mary had a $
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Transform the following Nim implementation into Go, maintaining the same output and logic. | import strutils
var str = "little"
echo "Mary had a $
echo "Mary had a $
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Port the provided OCaml code into C while preserving the original functionality. | let extra = "little" in
Printf.printf "Mary had a %s lamb." extra
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Preserve the algorithm and functionality while converting the code from OCaml to C#. | let extra = "little" in
Printf.printf "Mary had a %s lamb." extra
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Rewrite the snippet below in C++ so it works the same as the original OCaml code. | let extra = "little" in
Printf.printf "Mary had a %s lamb." extra
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Rewrite the snippet below in Java so it works the same as the original OCaml code. | let extra = "little" in
Printf.printf "Mary had a %s lamb." extra
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Can you help me rewrite this code in Python instead of OCaml, keeping it the same logically? | let extra = "little" in
Printf.printf "Mary had a %s lamb." extra
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Can you help me rewrite this code in VB instead of OCaml, keeping it the same logically? | let extra = "little" in
Printf.printf "Mary had a %s lamb." extra
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Generate a Go translation of this OCaml snippet without changing its computational steps. | let extra = "little" in
Printf.printf "Mary had a %s lamb." extra
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Rewrite the snippet below in C so it works the same as the original Perl code. | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Translate this program into C# but keep the logic exactly as in Perl. | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Convert the following code from Perl to C++, ensuring the logic remains intact. | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Maintain the same structure and functionality when rewriting this code in Java. | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Change the following Perl code into Python without altering its purpose. | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Can you help me rewrite this code in VB instead of Perl, keeping it the same logically? | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Write the same code in Go as shown below in Perl. | $extra = "little";
print "Mary had a $extra lamb.\n";
printf "Mary had a %s lamb.\n", $extra;
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Convert this PowerShell snippet to C and keep its semantics consistent. | $extra = "little"
"Mary had a {0} lamb." -f $extra
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Write the same algorithm in C# as shown in this PowerShell implementation. | $extra = "little"
"Mary had a {0} lamb." -f $extra
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Preserve the algorithm and functionality while converting the code from PowerShell to C++. | $extra = "little"
"Mary had a {0} lamb." -f $extra
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Convert this PowerShell block to Java, preserving its control flow and logic. | $extra = "little"
"Mary had a {0} lamb." -f $extra
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Generate a Python translation of this PowerShell snippet without changing its computational steps. | $extra = "little"
"Mary had a {0} lamb." -f $extra
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Rewrite this program in VB while keeping its functionality equivalent to the PowerShell version. | $extra = "little"
"Mary had a {0} lamb." -f $extra
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Generate a Go translation of this PowerShell snippet without changing its computational steps. | $extra = "little"
"Mary had a {0} lamb." -f $extra
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Translate the given Racket code snippet into C without altering its behavior. | #lang racket
(format "Mary had a ~a lamb" "little")
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Write a version of this Racket function in C# with identical behavior. | #lang racket
(format "Mary had a ~a lamb" "little")
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Produce a functionally identical C++ code for the snippet given in Racket. | #lang racket
(format "Mary had a ~a lamb" "little")
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Transform the following Racket implementation into Java, maintaining the same output and logic. | #lang racket
(format "Mary had a ~a lamb" "little")
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Port the following code from Racket to Python with equivalent syntax and logic. | #lang racket
(format "Mary had a ~a lamb" "little")
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Translate this program into VB but keep the logic exactly as in Racket. | #lang racket
(format "Mary had a ~a lamb" "little")
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Change the following Racket code into Go without altering its purpose. | #lang racket
(format "Mary had a ~a lamb" "little")
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Write the same code in C as shown below in COBOL. | IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Write a version of this COBOL function in C# with identical behavior. | IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Change the programming language of this snippet from COBOL to C++ without modifying what it does. | IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Generate a Java translation of this COBOL snippet without changing its computational steps. | IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Ensure the translated Python code behaves exactly like the original COBOL snippet. | IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Produce a language-to-language conversion: from COBOL to VB, same semantics. | IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Generate a Go translation of this COBOL snippet without changing its computational steps. | IDENTIFICATION DIVISION.
PROGRAM-ID. interpolation-included.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 extra PIC X(6) VALUE "little".
PROCEDURE DIVISION.
DISPLAY FUNCTION SUBSTITUTE("Mary had a X lamb.", "X", extra)
GOBACK
.
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Port the provided REXX code into C while preserving the original functionality. |
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Produce a functionally identical C# code for the snippet given in REXX. |
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Write the same code in C++ as shown below in REXX. |
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Transform the following REXX implementation into Java, maintaining the same output and logic. |
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Port the provided REXX code into Python while preserving the original functionality. |
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Rewrite this program in VB while keeping its functionality equivalent to the REXX version. |
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Write the same code in Go as shown below in REXX. |
options replace format comments java crossref savelog symbols
import java.text.MessageFormat
import java.text.FieldPosition
useBif()
useMessageFormat()
return
method useBif public static
st = "Mary had a %1$ lamb."
si = 'little'
say st.changestr('%1$', si)
return
method useMessageFormat public static
result = StringBuffer('')
args = Object [ -
Object Integer(7), -
Object Date(), -
Object 'a disturbance in the Force' -
]
msgfmt = MessageFormat('At {1, time} on {1, date}, there was {2} on planet {0, number, integer}.')
result = msgfmt.format(args, result, FieldPosition(0))
say result
return
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Keep all operations the same but rewrite the snippet in C. | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little lamb."
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Write a version of this Ruby function in C# with identical behavior. | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little lamb."
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Write the same algorithm in C++ as shown in this Ruby implementation. | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little lamb."
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Write the same code in Java as shown below in Ruby. | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little lamb."
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Rewrite this program in Python while keeping its functionality equivalent to the Ruby version. | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little lamb."
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Translate the given Ruby code snippet into VB without altering its behavior. | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little lamb."
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Transform the following Ruby implementation into Go, maintaining the same output and logic. | irb(main):001:0> extra = 'little'
=> "little"
irb(main):002:0> "Mary had a
=> "Mary had a little lamb."
irb(main):003:0> "Mary had a %s lamb." % extra
=> "Mary had a little lamb."
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Please provide an equivalent version of this Scala code in C. |
fun main(args: Array<String>) {
val s = "little"
println("Mary had a $s lamb")
println("Mary had a ${s.toUpperCase()} lamb")
println("Mary had a ${s}r lamb")
}
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Generate a C# translation of this Scala snippet without changing its computational steps. |
fun main(args: Array<String>) {
val s = "little"
println("Mary had a $s lamb")
println("Mary had a ${s.toUpperCase()} lamb")
println("Mary had a ${s}r lamb")
}
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Can you help me rewrite this code in C++ instead of Scala, keeping it the same logically? |
fun main(args: Array<String>) {
val s = "little"
println("Mary had a $s lamb")
println("Mary had a ${s.toUpperCase()} lamb")
println("Mary had a ${s}r lamb")
}
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Produce a language-to-language conversion: from Scala to Java, same semantics. |
fun main(args: Array<String>) {
val s = "little"
println("Mary had a $s lamb")
println("Mary had a ${s.toUpperCase()} lamb")
println("Mary had a ${s}r lamb")
}
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Generate a Python translation of this Scala snippet without changing its computational steps. |
fun main(args: Array<String>) {
val s = "little"
println("Mary had a $s lamb")
println("Mary had a ${s.toUpperCase()} lamb")
println("Mary had a ${s}r lamb")
}
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Translate this program into VB but keep the logic exactly as in Scala. |
fun main(args: Array<String>) {
val s = "little"
println("Mary had a $s lamb")
println("Mary had a ${s.toUpperCase()} lamb")
println("Mary had a ${s}r lamb")
}
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Change the programming language of this snippet from Scala to Go without modifying what it does. |
fun main(args: Array<String>) {
val s = "little"
println("Mary had a $s lamb")
println("Mary had a ${s.toUpperCase()} lamb")
println("Mary had a ${s}r lamb")
}
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Generate an equivalent C version of this Swift code. | let extra = "little"
println("Mary had a \(extra) lamb.")
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Rewrite the snippet below in C# so it works the same as the original Swift code. | let extra = "little"
println("Mary had a \(extra) lamb.")
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Keep all operations the same but rewrite the snippet in C++. | let extra = "little"
println("Mary had a \(extra) lamb.")
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Generate a Java translation of this Swift snippet without changing its computational steps. | let extra = "little"
println("Mary had a \(extra) lamb.")
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Port the following code from Swift to Python with equivalent syntax and logic. | let extra = "little"
println("Mary had a \(extra) lamb.")
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Convert this Swift snippet to VB and keep its semantics consistent. | let extra = "little"
println("Mary had a \(extra) lamb.")
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Can you help me rewrite this code in Go instead of Swift, keeping it the same logically? | let extra = "little"
println("Mary had a \(extra) lamb.")
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Keep all operations the same but rewrite the snippet in C. | set size "little"
puts "Mary had a $size lamb."
proc RandomWord {args} {
lindex $args [expr {int(rand()*[llength $args])}]
}
puts "Mary had a [RandomWord little big] lamb."
| #include <stdio.h>
int main() {
const char *extra = "little";
printf("Mary had a %s lamb.\n", extra);
return 0;
}
|
Port the following code from Tcl to C# with equivalent syntax and logic. | set size "little"
puts "Mary had a $size lamb."
proc RandomWord {args} {
lindex $args [expr {int(rand()*[llength $args])}]
}
puts "Mary had a [RandomWord little big] lamb."
| class Program
{
static void Main()
{
string extra = "little";
string formatted = $"Mary had a {extra} lamb.";
System.Console.WriteLine(formatted);
}
}
|
Generate an equivalent C++ version of this Tcl code. | set size "little"
puts "Mary had a $size lamb."
proc RandomWord {args} {
lindex $args [expr {int(rand()*[llength $args])}]
}
puts "Mary had a [RandomWord little big] lamb."
| #include <string>
#include <iostream>
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
}
|
Maintain the same structure and functionality when rewriting this code in Java. | set size "little"
puts "Mary had a $size lamb."
proc RandomWord {args} {
lindex $args [expr {int(rand()*[llength $args])}]
}
puts "Mary had a [RandomWord little big] lamb."
| String original = "Mary had a X lamb";
String little = "little";
String replaced = original.replace("X", little);
System.out.println(replaced);
System.out.printf("Mary had a %s lamb.", little);
String formatted = String.format("Mary had a %s lamb.", little);
System.out.println(formatted);
|
Change the programming language of this snippet from Tcl to Python without modifying what it does. | set size "little"
puts "Mary had a $size lamb."
proc RandomWord {args} {
lindex $args [expr {int(rand()*[llength $args])}]
}
puts "Mary had a [RandomWord little big] lamb."
| >>> original = 'Mary had a %s lamb.'
>>> extra = 'little'
>>> original % extra
'Mary had a little lamb.'
|
Write the same code in VB as shown below in Tcl. | set size "little"
puts "Mary had a $size lamb."
proc RandomWord {args} {
lindex $args [expr {int(rand()*[llength $args])}]
}
puts "Mary had a [RandomWord little big] lamb."
| Dim name as String = "J. Doe"
Dim balance as Double = 123.45
Dim prompt as String = String.Format("Hello {0}, your balance is {1}.", name, balance)
Console.WriteLine(prompt)
|
Convert this Tcl snippet to Go and keep its semantics consistent. | set size "little"
puts "Mary had a $size lamb."
proc RandomWord {args} {
lindex $args [expr {int(rand()*[llength $args])}]
}
puts "Mary had a [RandomWord little big] lamb."
| package main
import (
"fmt"
)
func main() {
str := "Mary had a %s lamb"
txt := "little"
out := fmt.Sprintf(str, txt)
fmt.Println(out)
}
|
Port the following code from Rust to PHP with equivalent syntax and logic. | fn main() {
println!("Mary had a {} lamb", "little");
println!("{1} had a {0} lamb", "little", "Mary");
println!("{name} had a {adj} lamb", adj="little", name="Mary");
}
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Generate a PHP translation of this Ada snippet without changing its computational steps. | with Ada.Strings.Fixed, Ada.Text_IO;
use Ada.Strings, Ada.Text_IO;
procedure String_Replace is
Original : constant String := "Mary had a @__@ lamb.";
Tbr : constant String := "@__@";
New_Str : constant String := "little";
Index : Natural := Fixed.Index (Original, Tbr);
begin
Put_Line (Fixed.Replace_Slice (
Original, Index, Index + Tbr'Length - 1, New_Str));
end String_Replace;
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Translate this program into PHP but keep the logic exactly as in Arturo. | sizeOfLamb: "little"
print ~"Mary had a |sizeOfLamb| lamb."
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Ensure the translated PHP code behaves exactly like the original AutoHotKey snippet. |
LIT = little
string = Mary had a %LIT% lamb.
LIT := "little"
string := "Mary had a" LIT " lamb."
MsgBox %string%
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Port the provided AWK code into PHP while preserving the original functionality. |
BEGIN {
str="Mary had a
gsub(/
print str
}
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Convert this Common_Lisp block to PHP, preserving its control flow and logic. | (let [little "little"]
(println (format "Mary had a %s lamb." little)))
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Port the provided D code into PHP while preserving the original functionality. | void main() {
import std.stdio, std.string;
"Mary had a %s lamb.".format("little").writeln;
"Mary had a %2$s %1$s lamb.".format("little", "white").writeln;
}
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Transform the following Delphi implementation into PHP, maintaining the same output and logic. | program Project1;
uses
System.SysUtils;
var
Template : string;
Marker : string;
Description : string;
Value : integer;
Output : string;
begin
Template := 'Mary had a X lamb.';
Marker := 'X';
Description := 'little';
Output := StringReplace(Template, Marker, Description, [rfReplaceAll, rfIgnoreCase]);
writeln(Output);
Template := 'Mary had a %s lamb.';
Description := 'little';
Output := format(Template,[Description]);
writeln(Output);
Template := 'Mary had a %s lamb. It was worth $%d.';
Description := 'little';
Value := 20;
Output := format(Template,[Description, Value]);
writeln(Output);
end.
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Ensure the translated PHP code behaves exactly like the original Elixir snippet. | x = "little"
IO.puts "Mary had a
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Generate an equivalent PHP version of this F# code. | let lambType = "little"
printfn "Mary had a %s lamb." lambType
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Change the programming language of this snippet from Factor to PHP without modifying what it does. | USE: formatting
SYMBOL: little
"little" little set
little get "Mary had a %s lamb" sprintf
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Port the provided Forth code into PHP while preserving the original functionality. | variable 'src
variable #src
variable 'out
variable #out
: Replace~ dup [char] ~ =
if 'out @ 1+ #out @ type drop
else emit
then ;
: format 0
begin dup #src @ u<
while 1+ dup 'src @ + c@
replace~
repeat ;
Here 'src ! ," Mary had a ~ lamb" here 'src @ - #src !
page
cr ." Original : "
'src @ 1+ #src @ type
cr ." 1st Replacement : "
here 'out ! ," little" here 'out @ - #out !
format
cr ." 2nd Replacement : "
here 'out ! ," BIG" here 'out @ - #out !
format
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Change the following Fortran code into PHP without altering its purpose. | program interpolate
write (*,*) trim(inter("Mary had a X lamb.","X","little"))
contains
elemental function inter(string,place,ins) result(new)
character(len=*), intent(in) :: string,place,ins
character(len=len(string)+max(0,len(ins)-len(place))) :: new
integer :: idx
idx = index(string,place)
if ( idx == 0 ) then
new = string
else
new = string(1:idx-1)//ins//string(idx+len(place):len(string))
end if
end function inter
end program interpolate
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Rewrite this program in PHP while keeping its functionality equivalent to the Groovy version. | def adj = 'little'
assert 'Mary had a little lamb.' == "Mary had a ${adj} lamb."
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Convert this Haskell block to PHP, preserving its control flow and logic. | import Text.Printf
main = printf "Mary had a %s lamb\n" "little"
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Generate a PHP translation of this Icon snippet without changing its computational steps. | s2 := "humongous"
s3 := "little"
s1 := "Mary had a humongous lamb."
s1 ?:= tab(find(s2)) || (=s2,s3) || tab(0)
while s1 ?:= tab(find(s2)) || (=s2,s3) || tab(0)
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Generate an equivalent PHP version of this J code. | require 'printf'
'Mary had a %s lamb.' sprintf <'little'
Mary had a little lamb.
require 'strings'
('%s';'little') stringreplace 'Mary had a %s lamb.'
Mary had a little lamb.
'Mary had a %s lamb.' rplc '%s';'little'
Mary had a little lamb.
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Write the same code in PHP as shown below in Julia. | X = "little"
"Mary had a $X lamb"
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Generate an equivalent PHP version of this Lua code. | str = string.gsub( "Mary had a X lamb.", "X", "little" )
print( str )
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Transform the following Mathematica implementation into PHP, maintaining the same output and logic. | Extra = "little";
StringReplace["Mary had a X lamb.", {"X" -> Extra}]
->"Mary had a little lamb."
| <?php
$extra = 'little';
echo "Mary had a $extra lamb.\n";
printf("Mary had a %s lamb.\n", $extra);
?>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.