Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Write a version of this Common_Lisp function in C++ with identical behavior.
(let [little "little"] (println (format "Mary had a %s 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 ; }
Port the following code from Common_Lisp to Java with equivalent syntax and logic.
(let [little "little"] (println (format "Mary had a %s 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);
Write a version of this Common_Lisp function in Python with identical behavior.
(let [little "little"] (println (format "Mary had a %s lamb." little)))
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Preserve the algorithm and functionality while converting the code from Common_Lisp to VB.
(let [little "little"] (println (format "Mary had a %s 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 programming language of this snippet from Common_Lisp to Go without modifying what it does.
(let [little "little"] (println (format "Mary had a %s lamb." little)))
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Translate this program into C but keep the logic exactly as in D.
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; }
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Convert the following code from D to C#, ensuring the logic remains intact.
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; }
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Change the following D code into C++ without altering its purpose.
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; }
#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 ; }
Keep all operations the same but rewrite the snippet in Java.
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; }
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 D snippet.
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; }
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Change the following D code into VB without altering its purpose.
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; }
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)
Produce a functionally identical Go code for the snippet given in D.
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; }
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Convert this Delphi block to C, preserving its control flow 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.
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Convert this Delphi snippet to C# and keep its semantics consistent.
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.
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Write a version of this Delphi function in C++ with identical behavior.
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.
#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 ; }
Translate this program into Java but keep the logic exactly as in Delphi.
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.
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);
Maintain the same structure and functionality when rewriting this code in Python.
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.
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Change the following Delphi code into VB without altering its purpose.
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.
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 algorithm in Go as shown in this Delphi implementation.
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.
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Rewrite this program in C while keeping its functionality equivalent to the Elixir version.
x = "little" IO.puts "Mary had a
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Rewrite this program in C# while keeping its functionality equivalent to the Elixir version.
x = "little" IO.puts "Mary had a
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 Elixir code.
x = "little" IO.puts "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 ; }
Rewrite the snippet below in Java so it works the same as the original Elixir code.
x = "little" IO.puts "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);
Translate the given Elixir code snippet into Python without altering its behavior.
x = "little" IO.puts "Mary had a
>>> 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 Elixir.
x = "little" IO.puts "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)
Convert this Elixir block to Go, preserving its control flow and logic.
x = "little" IO.puts "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) }
Produce a language-to-language conversion: from F# to C, same semantics.
let lambType = "little" printfn "Mary had a %s lamb." lambType
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Convert the following code from F# to C#, ensuring the logic remains intact.
let lambType = "little" printfn "Mary had a %s lamb." lambType
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 F# to C++.
let lambType = "little" printfn "Mary had a %s lamb." lambType
#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 algorithm in Java as shown in this F# implementation.
let lambType = "little" printfn "Mary had a %s lamb." lambType
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 F# code into Python while preserving the original functionality.
let lambType = "little" printfn "Mary had a %s lamb." lambType
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Generate a VB translation of this F# snippet without changing its computational steps.
let lambType = "little" printfn "Mary had a %s lamb." lambType
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)
Ensure the translated Go code behaves exactly like the original F# snippet.
let lambType = "little" printfn "Mary had a %s lamb." lambType
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Convert the following code from Factor to C, ensuring the logic remains intact.
USE: formatting SYMBOL: little "little" little set little get "Mary had a %s lamb" sprintf
#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 Factor code.
USE: formatting SYMBOL: little "little" little set little get "Mary had a %s lamb" sprintf
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Port the following code from Factor to C++ with equivalent syntax and logic.
USE: formatting SYMBOL: little "little" little set little get "Mary had a %s lamb" sprintf
#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 ; }
Can you help me rewrite this code in Java instead of Factor, keeping it the same logically?
USE: formatting SYMBOL: little "little" little set little get "Mary had a %s lamb" sprintf
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);
Transform the following Factor implementation into Python, maintaining the same output and logic.
USE: formatting SYMBOL: little "little" little set little get "Mary had a %s lamb" sprintf
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Translate the given Factor code snippet into VB without altering its behavior.
USE: formatting SYMBOL: little "little" little set little get "Mary had a %s lamb" sprintf
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)
Translate this program into Go but keep the logic exactly as in Factor.
USE: formatting SYMBOL: little "little" little set little get "Mary had a %s lamb" sprintf
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Generate a C translation of this Forth snippet without changing its computational steps.
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
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Produce a language-to-language conversion: from Forth to C#, same semantics.
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
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 Forth.
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
#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 ; }
Port the following code from Forth to Java with equivalent syntax and logic.
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
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 Forth to Python with equivalent syntax and logic.
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
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Convert the following code from Forth to VB, ensuring the logic remains intact.
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
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 Forth snippet to Go and keep its semantics consistent.
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
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 algorithm in C# as shown in this Fortran implementation.
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
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 Fortran implementation.
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
#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 ; }
Change the following Fortran code into C 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
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Change the programming language of this snippet from Fortran to Go without modifying what it does.
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
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Convert this Fortran block to Java, preserving its control flow and logic.
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
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 the snippet below in Python so it works the same as the original Fortran code.
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
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Change the programming language of this snippet from Fortran to VB without modifying what it does.
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
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)
Rewrite the snippet below in PHP so it works the same as the original Fortran code.
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 the snippet below in C so it works the same as the original Groovy code.
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} lamb."
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Can you help me rewrite this code in C# instead of Groovy, keeping it the same logically?
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} 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++.
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} 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 ; }
Port the following code from Groovy to Java with equivalent syntax and logic.
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} 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);
Convert this Groovy snippet to Python and keep its semantics consistent.
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} lamb."
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Port the provided Groovy code into VB while preserving the original functionality.
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} 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)
Write the same algorithm in Go as shown in this Groovy implementation.
def adj = 'little' assert 'Mary had a little lamb.' == "Mary had a ${adj} lamb."
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Convert this Haskell block to C, preserving its control flow and logic.
import Text.Printf main = printf "Mary had a %s lamb\n" "little"
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Ensure the translated C# code behaves exactly like the original Haskell snippet.
import Text.Printf main = printf "Mary had a %s lamb\n" "little"
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Translate the given Haskell code snippet into C++ without altering its behavior.
import Text.Printf main = printf "Mary had a %s lamb\n" "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 ; }
Port the provided Haskell code into Java while preserving the original functionality.
import Text.Printf main = printf "Mary had a %s lamb\n" "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);
Produce a language-to-language conversion: from Haskell to Python, same semantics.
import Text.Printf main = printf "Mary had a %s lamb\n" "little"
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Please provide an equivalent version of this Haskell code in VB.
import Text.Printf main = printf "Mary had a %s lamb\n" "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)
Port the provided Haskell code into Go while preserving the original functionality.
import Text.Printf main = printf "Mary had a %s lamb\n" "little"
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 Icon code.
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)
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Ensure the translated C# code behaves exactly like the original Icon snippet.
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)
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Rewrite this program in C++ while keeping its functionality equivalent to the Icon version.
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)
#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 Icon.
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)
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);
Write a version of this Icon function in Python with identical behavior.
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)
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Change the programming language of this snippet from Icon to VB without modifying what it does.
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)
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)
Maintain the same structure and functionality when rewriting this code in Go.
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)
package main import ( "fmt" ) func main() { str := "Mary had a %s lamb" txt := "little" out := fmt.Sprintf(str, txt) fmt.Println(out) }
Can you help me rewrite this code in C instead of J, keeping it the same logically?
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.
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Produce a language-to-language conversion: from J to C#, same semantics.
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.
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Translate the given J code snippet into C++ without altering its behavior.
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.
#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 ; }
Port the provided J code into Java while preserving the original functionality.
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.
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 the snippet below in Python so it works the same as the original 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.
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Change the programming language of this snippet from J to VB without modifying what it does.
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.
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 J snippet to Go and keep its semantics consistent.
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.
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 Julia to C with equivalent syntax and logic.
X = "little" "Mary had a $X lamb"
#include <stdio.h> int main() { const char *extra = "little"; printf("Mary had a %s lamb.\n", extra); return 0; }
Produce a language-to-language conversion: from Julia to C#, same semantics.
X = "little" "Mary had a $X lamb"
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Rewrite this program in C++ while keeping its functionality equivalent to the Julia version.
X = "little" "Mary had a $X 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 algorithm in Java as shown in this Julia implementation.
X = "little" "Mary had a $X 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 Julia snippet without changing its computational steps.
X = "little" "Mary had a $X lamb"
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Convert this Julia snippet to VB and keep its semantics consistent.
X = "little" "Mary had a $X 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)
Rewrite the snippet below in Go so it works the same as the original Julia code.
X = "little" "Mary had a $X 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#.
str = string.gsub( "Mary had a X lamb.", "X", "little" ) print( str )
class Program { static void Main() { string extra = "little"; string formatted = $"Mary had a {extra} lamb."; System.Console.WriteLine(formatted); } }
Convert this Lua snippet to C++ and keep its semantics consistent.
str = string.gsub( "Mary had a X lamb.", "X", "little" ) print( str )
#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 Lua block to Java, preserving its control flow and logic.
str = string.gsub( "Mary had a X lamb.", "X", "little" ) print( str )
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);
Please provide an equivalent version of this Lua code in Python.
str = string.gsub( "Mary had a X lamb.", "X", "little" ) print( str )
>>> original = 'Mary had a %s lamb.' >>> extra = 'little' >>> original % extra 'Mary had a little lamb.'
Change the following Lua code into VB without altering its purpose.
str = string.gsub( "Mary had a X lamb.", "X", "little" ) print( str )
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)
Keep all operations the same but rewrite the snippet in Go.
str = string.gsub( "Mary had a X lamb.", "X", "little" ) print( str )
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 Mathematica code.
Extra = "little"; StringReplace["Mary had a X lamb.", {"X" -> 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 the same algorithm in C# as shown in this Mathematica implementation.
Extra = "little"; StringReplace["Mary had a X lamb.", {"X" -> 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); } }
Preserve the algorithm and functionality while converting the code from Mathematica to C++.
Extra = "little"; StringReplace["Mary had a X lamb.", {"X" -> 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 ; }
Translate the given Mathematica code snippet into Java without altering its behavior.
Extra = "little"; StringReplace["Mary had a X lamb.", {"X" -> 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);