Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Change the following REXX code into Python without altering its purpose. |
parse arg target stopAt chunkette .
if target=='' | target=="," then target= 0
if stopAt=='' | stopAt=="," then stopAt= 1
y= 0
zz= 'archbishop -915 covariate 590 mycenae 183 brute 870 balm 397 fiat 170' ,
'smokescreen 423 eradicate 376 efferent 54 bonnet 452 vein ... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Write the same algorithm in Python as shown in this REXX implementation. |
parse arg target stopAt chunkette .
if target=='' | target=="," then target= 0
if stopAt=='' | stopAt=="," then stopAt= 1
y= 0
zz= 'archbishop -915 covariate 590 mycenae 183 brute 870 balm 397 fiat 170' ,
'smokescreen 423 eradicate 376 efferent 54 bonnet 452 vein ... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Transform the following REXX implementation into Go, maintaining the same output and logic. |
parse arg target stopAt chunkette .
if target=='' | target=="," then target= 0
if stopAt=='' | stopAt=="," then stopAt= 1
y= 0
zz= 'archbishop -915 covariate 590 mycenae 183 brute 870 balm 397 fiat 170' ,
'smokescreen 423 eradicate 376 efferent 54 bonnet 452 vein ... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Translate the given REXX code snippet into Go without altering its behavior. |
parse arg target stopAt chunkette .
if target=='' | target=="," then target= 0
if stopAt=='' | stopAt=="," then stopAt= 1
y= 0
zz= 'archbishop -915 covariate 590 mycenae 183 brute 870 balm 397 fiat 170' ,
'smokescreen 423 eradicate 376 efferent 54 bonnet 452 vein ... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Rewrite the snippet below in C so it works the same as the original Ruby code. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | #include <stdio.h>
#include <stdlib.h>
typedef struct {
char *word;
int weight;
} item_t;
item_t items[] = {
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{... |
Change the programming language of this snippet from Ruby to C without modifying what it does. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | #include <stdio.h>
#include <stdlib.h>
typedef struct {
char *word;
int weight;
} item_t;
item_t items[] = {
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{... |
Generate a C# translation of this Ruby snippet without changing its computational steps. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | using System;
using System.Collections.Generic;
namespace SubsetSum {
class Item {
public Item(string word, int weight) {
Word = word;
Weight = weight;
}
public string Word { get; set; }
public int Weight { get; set; }
public override string ToStrin... |
Translate this program into C# but keep the logic exactly as in Ruby. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | using System;
using System.Collections.Generic;
namespace SubsetSum {
class Item {
public Item(string word, int weight) {
Word = word;
Weight = weight;
}
public string Word { get; set; }
public int Weight { get; set; }
public override string ToStrin... |
Maintain the same structure and functionality when rewriting this code in C++. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | #include <iostream>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string& str) {
return out << str.c_str();
}
std::vector<std::pair<std::string, int>> items{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", ... |
Port the provided Ruby code into C++ while preserving the original functionality. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | #include <iostream>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string& str) {
return out << str.c_str();
}
std::vector<std::pair<std::string, int>> items{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", ... |
Translate this program into Java but keep the logic exactly as in Ruby. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | public class SubsetSum {
private static class Item {
private String word;
private int weight;
public Item(String word, int weight) {
this.word = word;
this.weight = weight;
}
@Override
public String toString() {
return String.form... |
Generate an equivalent Java version of this Ruby code. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | public class SubsetSum {
private static class Item {
private String word;
private int weight;
public Item(String word, int weight) {
this.word = word;
this.weight = weight;
}
@Override
public String toString() {
return String.form... |
Generate a Python translation of this Ruby snippet without changing its computational steps. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Preserve the algorithm and functionality while converting the code from Ruby to Python. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Please provide an equivalent version of this Ruby code in Go. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Change the programming language of this snippet from Ruby to Go without modifying what it does. | weights = {
'alliance' =>-624, 'archbishop'=>-915, 'balm' => 397, 'bonnet' => 452,
'brute' => 870, 'centipede' =>-658, 'cobol' => 362, 'covariate'=> 590,
'departure' => 952, 'deploy' => 44, 'diophantine'=> 645, 'efferent' => 54,
'elysee' =>-326, 'eradicate' => 376, 'escritoire' => ... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Port the provided Scala code into C while preserving the original functionality. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | #include <stdio.h>
#include <stdlib.h>
typedef struct {
char *word;
int weight;
} item_t;
item_t items[] = {
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{... |
Translate this program into C but keep the logic exactly as in Scala. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | #include <stdio.h>
#include <stdlib.h>
typedef struct {
char *word;
int weight;
} item_t;
item_t items[] = {
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{... |
Convert this Scala snippet to C# and keep its semantics consistent. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | using System;
using System.Collections.Generic;
namespace SubsetSum {
class Item {
public Item(string word, int weight) {
Word = word;
Weight = weight;
}
public string Word { get; set; }
public int Weight { get; set; }
public override string ToStrin... |
Generate an equivalent C# version of this Scala code. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | using System;
using System.Collections.Generic;
namespace SubsetSum {
class Item {
public Item(string word, int weight) {
Word = word;
Weight = weight;
}
public string Word { get; set; }
public int Weight { get; set; }
public override string ToStrin... |
Transform the following Scala implementation into C++, maintaining the same output and logic. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | #include <iostream>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string& str) {
return out << str.c_str();
}
std::vector<std::pair<std::string, int>> items{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", ... |
Generate a C++ translation of this Scala snippet without changing its computational steps. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | #include <iostream>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string& str) {
return out << str.c_str();
}
std::vector<std::pair<std::string, int>> items{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", ... |
Port the following code from Scala to Java with equivalent syntax and logic. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | public class SubsetSum {
private static class Item {
private String word;
private int weight;
public Item(String word, int weight) {
this.word = word;
this.weight = weight;
}
@Override
public String toString() {
return String.form... |
Convert the following code from Scala to Java, ensuring the logic remains intact. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | public class SubsetSum {
private static class Item {
private String word;
private int weight;
public Item(String word, int weight) {
this.word = word;
this.weight = weight;
}
@Override
public String toString() {
return String.form... |
Write the same algorithm in Python as shown in this Scala implementation. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Convert the following code from Scala to Python, ensuring the logic remains intact. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Port the provided Scala code into Go while preserving the original functionality. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Convert this Scala block to Go, preserving its control flow and logic. |
class Item(val word: String, val weight: Int) {
override fun toString() = "($word $weight)"
}
val items = arrayOf(
Item("alliance", -624),
Item("archbishop", -915),
Item("balm", 397),
Item("bonnet", 452),
Item("brute", 870),
Item("centipede", -658),
Item("cobol",... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Preserve the algorithm and functionality while converting the code from Tcl to C. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | #include <stdio.h>
#include <stdlib.h>
typedef struct {
char *word;
int weight;
} item_t;
item_t items[] = {
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{... |
Port the following code from Tcl to C with equivalent syntax and logic. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | #include <stdio.h>
#include <stdlib.h>
typedef struct {
char *word;
int weight;
} item_t;
item_t items[] = {
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{... |
Can you help me rewrite this code in C# instead of Tcl, keeping it the same logically? | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | using System;
using System.Collections.Generic;
namespace SubsetSum {
class Item {
public Item(string word, int weight) {
Word = word;
Weight = weight;
}
public string Word { get; set; }
public int Weight { get; set; }
public override string ToStrin... |
Ensure the translated C# code behaves exactly like the original Tcl snippet. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | using System;
using System.Collections.Generic;
namespace SubsetSum {
class Item {
public Item(string word, int weight) {
Word = word;
Weight = weight;
}
public string Word { get; set; }
public int Weight { get; set; }
public override string ToStrin... |
Translate the given Tcl code snippet into C++ without altering its behavior. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | #include <iostream>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string& str) {
return out << str.c_str();
}
std::vector<std::pair<std::string, int>> items{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", ... |
Convert the following code from Tcl to C++, ensuring the logic remains intact. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | #include <iostream>
#include <vector>
std::ostream& operator<<(std::ostream& out, const std::string& str) {
return out << str.c_str();
}
std::vector<std::pair<std::string, int>> items{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", ... |
Convert this Tcl block to Java, preserving its control flow and logic. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | public class SubsetSum {
private static class Item {
private String word;
private int weight;
public Item(String word, int weight) {
this.word = word;
this.weight = weight;
}
@Override
public String toString() {
return String.form... |
Please provide an equivalent version of this Tcl code in Java. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | public class SubsetSum {
private static class Item {
private String word;
private int weight;
public Item(String word, int weight) {
this.word = word;
this.weight = weight;
}
@Override
public String toString() {
return String.form... |
Port the provided Tcl code into Python while preserving the original functionality. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Generate an equivalent Python version of this Tcl code. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | words = {
"alliance": -624, "archbishop": -925, "balm": 397,
"bonnet": 452, "brute": 870, "centipede": -658,
"cobol": 362, "covariate": 590, "departure": 952,
"deploy": 44, "diophantine": 645, "efferent": 54,
"elysee": -326, "eradicate": 376, "escritoire": 856,
"exorcism": -983, "fiat": 170, "filmy": -874,... |
Preserve the algorithm and functionality while converting the code from Tcl to Go. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Convert this Tcl block to Go, preserving its control flow and logic. | proc subsetsOfSize {set size} {
if {$size <= 0} {
return
} elseif {$size == 1} {
foreach elem $set {lappend result [list $elem]}
} else {
incr size [set i -1]
foreach elem $set {
foreach sub [subsetsOfSize [lreplace $set [incr i] $i] $size] {
lappend result [lappend sub $elem]
}
}
}
... | package main
import "fmt"
type ww struct {
word string
weight int
}
var input = []*ww{
{"alliance", -624},
{"archbishop", -915},
{"balm", 397},
{"bonnet", 452},
{"brute", 870},
{"centipede", -658},
{"cobol", 362},
{"covariate", 590},
{"departure", 952},
{"deploy", 44... |
Port the following code from Ada to C# with equivalent syntax and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure Man_Or_Boy is
function Zero return Integer is begin return 0; end Zero;
function One return Integer is begin return 1; end One;
function Neg return Integer is begin return -1; end Neg;
function A
( K : Integer;
X1, X2, X3, X4, X... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Produce a functionally identical C code for the snippet given in Ada. | with Ada.Text_IO; use Ada.Text_IO;
procedure Man_Or_Boy is
function Zero return Integer is begin return 0; end Zero;
function One return Integer is begin return 1; end One;
function Neg return Integer is begin return -1; end Neg;
function A
( K : Integer;
X1, X2, X3, X4, X... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Please provide an equivalent version of this Ada code in C++. | with Ada.Text_IO; use Ada.Text_IO;
procedure Man_Or_Boy is
function Zero return Integer is begin return 0; end Zero;
function One return Integer is begin return 1; end One;
function Neg return Integer is begin return -1; end Neg;
function A
( K : Integer;
X1, X2, X3, X4, X... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Change the programming language of this snippet from Ada to Go without modifying what it does. | with Ada.Text_IO; use Ada.Text_IO;
procedure Man_Or_Boy is
function Zero return Integer is begin return 0; end Zero;
function One return Integer is begin return 1; end One;
function Neg return Integer is begin return -1; end Neg;
function A
( K : Integer;
X1, X2, X3, X4, X... | package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Produce a language-to-language conversion: from Ada to Java, same semantics. | with Ada.Text_IO; use Ada.Text_IO;
procedure Man_Or_Boy is
function Zero return Integer is begin return 0; end Zero;
function One return Integer is begin return 1; end One;
function Neg return Integer is begin return -1; end Neg;
function A
( K : Integer;
X1, X2, X3, X4, X... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Write the same algorithm in Python as shown in this Ada implementation. | with Ada.Text_IO; use Ada.Text_IO;
procedure Man_Or_Boy is
function Zero return Integer is begin return 0; end Zero;
function One return Integer is begin return 1; end One;
function Neg return Integer is begin return -1; end Neg;
function A
( K : Integer;
X1, X2, X3, X4, X... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Write the same code in C as shown below in BBC_Basic. | HIMEM = PAGE + 200000000 :
FOR k% = 0 TO 20
PRINT FNA(k%, ^FN1(), ^FN_1(), ^FN_1(), ^FN1(), ^FN0())
NEXT
END
DEF FNA(k%, x1%, x2%, x3%, x4%, x5%)
IF k% <= 0 THEN = FN(x4%)(x4%) + FN(x5%)(x5%)
LOCAL b{}
DIM b{fn%, k%, x1%, x2%, x3%, x4%, x5%}
b... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Produce a functionally identical C# code for the snippet given in BBC_Basic. | HIMEM = PAGE + 200000000 :
FOR k% = 0 TO 20
PRINT FNA(k%, ^FN1(), ^FN_1(), ^FN_1(), ^FN1(), ^FN0())
NEXT
END
DEF FNA(k%, x1%, x2%, x3%, x4%, x5%)
IF k% <= 0 THEN = FN(x4%)(x4%) + FN(x5%)(x5%)
LOCAL b{}
DIM b{fn%, k%, x1%, x2%, x3%, x4%, x5%}
b... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Translate the given BBC_Basic code snippet into C++ without altering its behavior. | HIMEM = PAGE + 200000000 :
FOR k% = 0 TO 20
PRINT FNA(k%, ^FN1(), ^FN_1(), ^FN_1(), ^FN1(), ^FN0())
NEXT
END
DEF FNA(k%, x1%, x2%, x3%, x4%, x5%)
IF k% <= 0 THEN = FN(x4%)(x4%) + FN(x5%)(x5%)
LOCAL b{}
DIM b{fn%, k%, x1%, x2%, x3%, x4%, x5%}
b... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Translate the given BBC_Basic code snippet into Java without altering its behavior. | HIMEM = PAGE + 200000000 :
FOR k% = 0 TO 20
PRINT FNA(k%, ^FN1(), ^FN_1(), ^FN_1(), ^FN1(), ^FN0())
NEXT
END
DEF FNA(k%, x1%, x2%, x3%, x4%, x5%)
IF k% <= 0 THEN = FN(x4%)(x4%) + FN(x5%)(x5%)
LOCAL b{}
DIM b{fn%, k%, x1%, x2%, x3%, x4%, x5%}
b... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Rewrite the snippet below in Python so it works the same as the original BBC_Basic code. | HIMEM = PAGE + 200000000 :
FOR k% = 0 TO 20
PRINT FNA(k%, ^FN1(), ^FN_1(), ^FN_1(), ^FN1(), ^FN0())
NEXT
END
DEF FNA(k%, x1%, x2%, x3%, x4%, x5%)
IF k% <= 0 THEN = FN(x4%)(x4%) + FN(x5%)(x5%)
LOCAL b{}
DIM b{fn%, k%, x1%, x2%, x3%, x4%, x5%}
b... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Translate the given BBC_Basic code snippet into Go without altering its behavior. | HIMEM = PAGE + 200000000 :
FOR k% = 0 TO 20
PRINT FNA(k%, ^FN1(), ^FN_1(), ^FN_1(), ^FN1(), ^FN0())
NEXT
END
DEF FNA(k%, x1%, x2%, x3%, x4%, x5%)
IF k% <= 0 THEN = FN(x4%)(x4%) + FN(x5%)(x5%)
LOCAL b{}
DIM b{fn%, k%, x1%, x2%, x3%, x4%, x5%}
b... | package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Change the following Common_Lisp code into C without altering its purpose. | (declare a)
(defn man-or-boy
"Man or boy test for Clojure"
[k]
(let [k (atom k)]
(a k
(fn [] 1)
(fn [] -1)
(fn [] -1)
(fn [] 1)
(fn [] 0))))
(defn a
[k x1 x2 x3 x4 x5]
(let [k (atom @k)]
(letfn [(b []
(swap! k dec)
(a k b x1 x2 x3 x4))... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Keep all operations the same but rewrite the snippet in C#. | (declare a)
(defn man-or-boy
"Man or boy test for Clojure"
[k]
(let [k (atom k)]
(a k
(fn [] 1)
(fn [] -1)
(fn [] -1)
(fn [] 1)
(fn [] 0))))
(defn a
[k x1 x2 x3 x4 x5]
(let [k (atom @k)]
(letfn [(b []
(swap! k dec)
(a k b x1 x2 x3 x4))... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Translate this program into C++ but keep the logic exactly as in Common_Lisp. | (declare a)
(defn man-or-boy
"Man or boy test for Clojure"
[k]
(let [k (atom k)]
(a k
(fn [] 1)
(fn [] -1)
(fn [] -1)
(fn [] 1)
(fn [] 0))))
(defn a
[k x1 x2 x3 x4 x5]
(let [k (atom @k)]
(letfn [(b []
(swap! k dec)
(a k b x1 x2 x3 x4))... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Ensure the translated Java code behaves exactly like the original Common_Lisp snippet. | (declare a)
(defn man-or-boy
"Man or boy test for Clojure"
[k]
(let [k (atom k)]
(a k
(fn [] 1)
(fn [] -1)
(fn [] -1)
(fn [] 1)
(fn [] 0))))
(defn a
[k x1 x2 x3 x4 x5]
(let [k (atom @k)]
(letfn [(b []
(swap! k dec)
(a k b x1 x2 x3 x4))... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Produce a language-to-language conversion: from Common_Lisp to Python, same semantics. | (declare a)
(defn man-or-boy
"Man or boy test for Clojure"
[k]
(let [k (atom k)]
(a k
(fn [] 1)
(fn [] -1)
(fn [] -1)
(fn [] 1)
(fn [] 0))))
(defn a
[k x1 x2 x3 x4 x5]
(let [k (atom @k)]
(letfn [(b []
(swap! k dec)
(a k b x1 x2 x3 x4))... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Change the programming language of this snippet from Common_Lisp to Go without modifying what it does. | (declare a)
(defn man-or-boy
"Man or boy test for Clojure"
[k]
(let [k (atom k)]
(a k
(fn [] 1)
(fn [] -1)
(fn [] -1)
(fn [] 1)
(fn [] 0))))
(defn a
[k x1 x2 x3 x4 x5]
(let [k (atom @k)]
(letfn [(b []
(swap! k dec)
(a k b x1 x2 x3 x4))... | package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Translate this program into C but keep the logic exactly as in D. | import core.stdc.stdio: printf;
int a(int k, const lazy int x1, const lazy int x2, const lazy int x3,
const lazy int x4, const lazy int x5) pure {
int b() {
k--;
return a(k, b(), x1, x2, x3, x4);
}
return k <= 0 ? x4 + x5 : b();
}
void main() {
printf("%d\n", a(10, 1, -1, -1, 1, ... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Translate this program into C# but keep the logic exactly as in D. | import core.stdc.stdio: printf;
int a(int k, const lazy int x1, const lazy int x2, const lazy int x3,
const lazy int x4, const lazy int x5) pure {
int b() {
k--;
return a(k, b(), x1, x2, x3, x4);
}
return k <= 0 ? x4 + x5 : b();
}
void main() {
printf("%d\n", a(10, 1, -1, -1, 1, ... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Write a version of this D function in C++ with identical behavior. | import core.stdc.stdio: printf;
int a(int k, const lazy int x1, const lazy int x2, const lazy int x3,
const lazy int x4, const lazy int x5) pure {
int b() {
k--;
return a(k, b(), x1, x2, x3, x4);
}
return k <= 0 ? x4 + x5 : b();
}
void main() {
printf("%d\n", a(10, 1, -1, -1, 1, ... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Convert this D block to Java, preserving its control flow and logic. | import core.stdc.stdio: printf;
int a(int k, const lazy int x1, const lazy int x2, const lazy int x3,
const lazy int x4, const lazy int x5) pure {
int b() {
k--;
return a(k, b(), x1, x2, x3, x4);
}
return k <= 0 ? x4 + x5 : b();
}
void main() {
printf("%d\n", a(10, 1, -1, -1, 1, ... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Port the provided D code into Python while preserving the original functionality. | import core.stdc.stdio: printf;
int a(int k, const lazy int x1, const lazy int x2, const lazy int x3,
const lazy int x4, const lazy int x5) pure {
int b() {
k--;
return a(k, b(), x1, x2, x3, x4);
}
return k <= 0 ? x4 + x5 : b();
}
void main() {
printf("%d\n", a(10, 1, -1, -1, 1, ... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Write a version of this D function in Go with identical behavior. | import core.stdc.stdio: printf;
int a(int k, const lazy int x1, const lazy int x2, const lazy int x3,
const lazy int x4, const lazy int x5) pure {
int b() {
k--;
return a(k, b(), x1, x2, x3, x4);
}
return k <= 0 ? x4 + x5 : b();
}
void main() {
printf("%d\n", a(10, 1, -1, -1, 1, ... | package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Change the following Delphi code into C without altering its purpose. | type
TFunc<T> = reference to function: T;
function C(x: Integer): TFunc<Integer>;
begin
Result := function: Integer
begin
Result := x;
end;
end;
function A(k: Integer; x1, x2, x3, x4, x5: TFunc<Integer>): Integer;
var
b: TFunc<Integer>;
begin
b := function: Integer
begin
Dec(k);
Result := ... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Please provide an equivalent version of this Delphi code in C#. | type
TFunc<T> = reference to function: T;
function C(x: Integer): TFunc<Integer>;
begin
Result := function: Integer
begin
Result := x;
end;
end;
function A(k: Integer; x1, x2, x3, x4, x5: TFunc<Integer>): Integer;
var
b: TFunc<Integer>;
begin
b := function: Integer
begin
Dec(k);
Result := ... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Convert the following code from Delphi to C++, ensuring the logic remains intact. | type
TFunc<T> = reference to function: T;
function C(x: Integer): TFunc<Integer>;
begin
Result := function: Integer
begin
Result := x;
end;
end;
function A(k: Integer; x1, x2, x3, x4, x5: TFunc<Integer>): Integer;
var
b: TFunc<Integer>;
begin
b := function: Integer
begin
Dec(k);
Result := ... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Write a version of this Delphi function in Java with identical behavior. | type
TFunc<T> = reference to function: T;
function C(x: Integer): TFunc<Integer>;
begin
Result := function: Integer
begin
Result := x;
end;
end;
function A(k: Integer; x1, x2, x3, x4, x5: TFunc<Integer>): Integer;
var
b: TFunc<Integer>;
begin
b := function: Integer
begin
Dec(k);
Result := ... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Keep all operations the same but rewrite the snippet in Python. | type
TFunc<T> = reference to function: T;
function C(x: Integer): TFunc<Integer>;
begin
Result := function: Integer
begin
Result := x;
end;
end;
function A(k: Integer; x1, x2, x3, x4, x5: TFunc<Integer>): Integer;
var
b: TFunc<Integer>;
begin
b := function: Integer
begin
Dec(k);
Result := ... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Port the following code from Delphi to Go with equivalent syntax and logic. | type
TFunc<T> = reference to function: T;
function C(x: Integer): TFunc<Integer>;
begin
Result := function: Integer
begin
Result := x;
end;
end;
function A(k: Integer; x1, x2, x3, x4, x5: TFunc<Integer>): Integer;
var
b: TFunc<Integer>;
begin
b := function: Integer
begin
Dec(k);
Result := ... | package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Keep all operations the same but rewrite the snippet in C. | [<EntryPoint>]
let main (args : string[]) =
let k = int(args.[0])
let l x = fun() -> x
let rec a k x1 x2 x3 x4 x5 =
if k <= 0 then
x4() + x5()
else
let k = ref k
let rec b() =
k := !k - 1
a !k b x1 x2 x3 x4
b()... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Produce a functionally identical C# code for the snippet given in F#. | [<EntryPoint>]
let main (args : string[]) =
let k = int(args.[0])
let l x = fun() -> x
let rec a k x1 x2 x3 x4 x5 =
if k <= 0 then
x4() + x5()
else
let k = ref k
let rec b() =
k := !k - 1
a !k b x1 x2 x3 x4
b()... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Can you help me rewrite this code in C++ instead of F#, keeping it the same logically? | [<EntryPoint>]
let main (args : string[]) =
let k = int(args.[0])
let l x = fun() -> x
let rec a k x1 x2 x3 x4 x5 =
if k <= 0 then
x4() + x5()
else
let k = ref k
let rec b() =
k := !k - 1
a !k b x1 x2 x3 x4
b()... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Generate an equivalent Java version of this F# code. | [<EntryPoint>]
let main (args : string[]) =
let k = int(args.[0])
let l x = fun() -> x
let rec a k x1 x2 x3 x4 x5 =
if k <= 0 then
x4() + x5()
else
let k = ref k
let rec b() =
k := !k - 1
a !k b x1 x2 x3 x4
b()... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Please provide an equivalent version of this F# code in Python. | [<EntryPoint>]
let main (args : string[]) =
let k = int(args.[0])
let l x = fun() -> x
let rec a k x1 x2 x3 x4 x5 =
if k <= 0 then
x4() + x5()
else
let k = ref k
let rec b() =
k := !k - 1
a !k b x1 x2 x3 x4
b()... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Produce a functionally identical Go code for the snippet given in F#. | [<EntryPoint>]
let main (args : string[]) =
let k = int(args.[0])
let l x = fun() -> x
let rec a k x1 x2 x3 x4 x5 =
if k <= 0 then
x4() + x5()
else
let k = ref k
let rec b() =
k := !k - 1
a !k b x1 x2 x3 x4
b()... | package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Produce a functionally identical C code for the snippet given in Forth. | : A {: w^ k x1 x2 x3 xt: x4 xt: x5 | w^ B :} recursive
k @ 0<= IF x4 x5 f+ ELSE
B k x1 x2 x3 action-of x4 [{: B k x1 x2 x3 x4 :}L
-1 k +!
k @ B @ x1 x2 x3 x4 A ;] dup B !
execute THEN ;
10 [: 1e ;] [: -1e ;] 2dup swap [: 0e ;] A f.
|
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Write the same code in C# as shown below in Forth. | : A {: w^ k x1 x2 x3 xt: x4 xt: x5 | w^ B :} recursive
k @ 0<= IF x4 x5 f+ ELSE
B k x1 x2 x3 action-of x4 [{: B k x1 x2 x3 x4 :}L
-1 k +!
k @ B @ x1 x2 x3 x4 A ;] dup B !
execute THEN ;
10 [: 1e ;] [: -1e ;] 2dup swap [: 0e ;] A f.
| using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Ensure the translated C++ code behaves exactly like the original Forth snippet. | : A {: w^ k x1 x2 x3 xt: x4 xt: x5 | w^ B :} recursive
k @ 0<= IF x4 x5 f+ ELSE
B k x1 x2 x3 action-of x4 [{: B k x1 x2 x3 x4 :}L
-1 k +!
k @ B @ x1 x2 x3 x4 A ;] dup B !
execute THEN ;
10 [: 1e ;] [: -1e ;] 2dup swap [: 0e ;] A f.
| #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Produce a functionally identical Java code for the snippet given in Forth. | : A {: w^ k x1 x2 x3 xt: x4 xt: x5 | w^ B :} recursive
k @ 0<= IF x4 x5 f+ ELSE
B k x1 x2 x3 action-of x4 [{: B k x1 x2 x3 x4 :}L
-1 k +!
k @ B @ x1 x2 x3 x4 A ;] dup B !
execute THEN ;
10 [: 1e ;] [: -1e ;] 2dup swap [: 0e ;] A f.
| import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Convert this Forth snippet to Python and keep its semantics consistent. | : A {: w^ k x1 x2 x3 xt: x4 xt: x5 | w^ B :} recursive
k @ 0<= IF x4 x5 f+ ELSE
B k x1 x2 x3 action-of x4 [{: B k x1 x2 x3 x4 :}L
-1 k +!
k @ B @ x1 x2 x3 x4 A ;] dup B !
execute THEN ;
10 [: 1e ;] [: -1e ;] 2dup swap [: 0e ;] A f.
|
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Produce a language-to-language conversion: from Forth to Go, same semantics. | : A {: w^ k x1 x2 x3 xt: x4 xt: x5 | w^ B :} recursive
k @ 0<= IF x4 x5 f+ ELSE
B k x1 x2 x3 action-of x4 [{: B k x1 x2 x3 x4 :}L
-1 k +!
k @ B @ x1 x2 x3 x4 A ;] dup B !
execute THEN ;
10 [: 1e ;] [: -1e ;] 2dup swap [: 0e ;] A f.
| package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Produce a language-to-language conversion: from Fortran to C#, same semantics. | module man_or_boy
implicit none
contains
recursive integer function A(k,x1,x2,x3,x4,x5) result(res)
integer, intent(in) :: k
interface
recursive integer function x1()
end function
recursive integer function x2()
end function
recursive integer function x3()
end function
... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Translate the given Fortran code snippet into C++ without altering its behavior. | module man_or_boy
implicit none
contains
recursive integer function A(k,x1,x2,x3,x4,x5) result(res)
integer, intent(in) :: k
interface
recursive integer function x1()
end function
recursive integer function x2()
end function
recursive integer function x3()
end function
... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Write the same algorithm in C as shown in this Fortran implementation. | module man_or_boy
implicit none
contains
recursive integer function A(k,x1,x2,x3,x4,x5) result(res)
integer, intent(in) :: k
interface
recursive integer function x1()
end function
recursive integer function x2()
end function
recursive integer function x3()
end function
... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Rewrite this program in Java while keeping its functionality equivalent to the Fortran version. | module man_or_boy
implicit none
contains
recursive integer function A(k,x1,x2,x3,x4,x5) result(res)
integer, intent(in) :: k
interface
recursive integer function x1()
end function
recursive integer function x2()
end function
recursive integer function x3()
end function
... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Can you help me rewrite this code in Python instead of Fortran, keeping it the same logically? | module man_or_boy
implicit none
contains
recursive integer function A(k,x1,x2,x3,x4,x5) result(res)
integer, intent(in) :: k
interface
recursive integer function x1()
end function
recursive integer function x2()
end function
recursive integer function x3()
end function
... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Change the programming language of this snippet from Fortran to PHP without modifying what it does. | module man_or_boy
implicit none
contains
recursive integer function A(k,x1,x2,x3,x4,x5) result(res)
integer, intent(in) :: k
interface
recursive integer function x1()
end function
recursive integer function x2()
end function
recursive integer function x3()
end function
... | <?php
function A($k,$x1,$x2,$x3,$x4,$x5) {
$b = function () use (&$b,&$k,$x1,$x2,$x3,$x4) {
return A(--$k,$b,$x1,$x2,$x3,$x4);
};
return $k <= 0 ? $x4() + $x5() : $b();
}
echo A(10, function () { return 1; },
function () { return -1; },
function () { return -1; },
... |
Produce a language-to-language conversion: from Groovy to C, same semantics. | def a; a = { k, x1, x2, x3, x4, x5 ->
def b; b = {
a (--k, b, x1, x2, x3, x4)
}
k <= 0 ? x4() + x5() : b()
}
def x = { n -> { it -> n } }
|
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Produce a functionally identical C# code for the snippet given in Groovy. | def a; a = { k, x1, x2, x3, x4, x5 ->
def b; b = {
a (--k, b, x1, x2, x3, x4)
}
k <= 0 ? x4() + x5() : b()
}
def x = { n -> { it -> n } }
| using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Translate the given Groovy code snippet into C++ without altering its behavior. | def a; a = { k, x1, x2, x3, x4, x5 ->
def b; b = {
a (--k, b, x1, x2, x3, x4)
}
k <= 0 ? x4() + x5() : b()
}
def x = { n -> { it -> n } }
| #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Write the same algorithm in Java as shown in this Groovy implementation. | def a; a = { k, x1, x2, x3, x4, x5 ->
def b; b = {
a (--k, b, x1, x2, x3, x4)
}
k <= 0 ? x4() + x5() : b()
}
def x = { n -> { it -> n } }
| import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Change the programming language of this snippet from Groovy to Python without modifying what it does. | def a; a = { k, x1, x2, x3, x4, x5 ->
def b; b = {
a (--k, b, x1, x2, x3, x4)
}
k <= 0 ? x4() + x5() : b()
}
def x = { n -> { it -> n } }
|
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Transform the following Groovy implementation into Go, maintaining the same output and logic. | def a; a = { k, x1, x2, x3, x4, x5 ->
def b; b = {
a (--k, b, x1, x2, x3, x4)
}
k <= 0 ? x4() + x5() : b()
}
def x = { n -> { it -> n } }
| package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Translate this program into C but keep the logic exactly as in Haskell. | import Data.IORef (modifyIORef, newIORef, readIORef)
a
:: (Enum a, Num b, Num a, Ord a)
=> a -> IO b -> IO b -> IO b -> IO b -> IO b -> IO b
a k x1 x2 x3 x4 x5 = do
r <- newIORef k
let b = do
k <- pred ! r
a k b x1 x2 x3 x4
if k <= 0
then (+) <$> x4 <*> x5
else b
where
f !r = mo... |
#include <stdio.h>
#include <stdlib.h>
typedef struct arg
{
int (*fn)(struct arg*);
int *k;
struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;
int f_1 (ARG* _) { return -1; }
int f0 (ARG* _) { return 0; }
int f1 (ARG* _) { return 1; }
int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(... |
Translate this program into C# but keep the logic exactly as in Haskell. | import Data.IORef (modifyIORef, newIORef, readIORef)
a
:: (Enum a, Num b, Num a, Ord a)
=> a -> IO b -> IO b -> IO b -> IO b -> IO b -> IO b
a k x1 x2 x3 x4 x5 = do
r <- newIORef k
let b = do
k <- pred ! r
a k b x1 x2 x3 x4
if k <= 0
then (+) <$> x4 <*> x5
else b
where
f !r = mo... | using System;
delegate T Func<T>();
class ManOrBoy
{
static void Main()
{
Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
}
static Func<int> C(int i)
{
return delegate { return i; };
}
static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x... |
Translate this program into C++ but keep the logic exactly as in Haskell. | import Data.IORef (modifyIORef, newIORef, readIORef)
a
:: (Enum a, Num b, Num a, Ord a)
=> a -> IO b -> IO b -> IO b -> IO b -> IO b -> IO b
a k x1 x2 x3 x4 x5 = do
r <- newIORef k
let b = do
k <- pred ! r
a k b x1 x2 x3 x4
if k <= 0
then (+) <$> x4 <*> x5
else b
where
f !r = mo... | #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;
struct Arg {
virtual int run() = 0;
virtual ~Arg() { };
};
int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
shared_ptr<Arg>, shared_ptr<Arg>);
class B : public Arg, public enable_shar... |
Convert this Haskell snippet to Java and keep its semantics consistent. | import Data.IORef (modifyIORef, newIORef, readIORef)
a
:: (Enum a, Num b, Num a, Ord a)
=> a -> IO b -> IO b -> IO b -> IO b -> IO b -> IO b
a k x1 x2 x3 x4 x5 = do
r <- newIORef k
let b = do
k <- pred ! r
a k b x1 x2 x3 x4
if k <= 0
then (+) <$> x4 <*> x5
else b
where
f !r = mo... | import java.util.function.DoubleSupplier;
public class ManOrBoy {
static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
DoubleSupplier B = new DoubleSupplier() {
int m = k;
public double... |
Produce a language-to-language conversion: from Haskell to Python, same semantics. | import Data.IORef (modifyIORef, newIORef, readIORef)
a
:: (Enum a, Num b, Num a, Ord a)
=> a -> IO b -> IO b -> IO b -> IO b -> IO b -> IO b
a k x1 x2 x3 x4 x5 = do
r <- newIORef k
let b = do
k <- pred ! r
a k b x1 x2 x3 x4
if k <= 0
then (+) <$> x4 <*> x5
else b
where
f !r = mo... |
import sys
sys.setrecursionlimit(1025)
def a(in_k, x1, x2, x3, x4, x5):
k = [in_k]
def b():
k[0] -= 1
return a(k[0], b, x1, x2, x3, x4)
return x4() + x5() if k[0] <= 0 else b()
x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))
|
Port the provided Haskell code into Go while preserving the original functionality. | import Data.IORef (modifyIORef, newIORef, readIORef)
a
:: (Enum a, Num b, Num a, Ord a)
=> a -> IO b -> IO b -> IO b -> IO b -> IO b -> IO b
a k x1 x2 x3 x4 x5 = do
r <- newIORef k
let b = do
k <- pred ! r
a k b x1 x2 x3 x4
if k <= 0
then (+) <$> x4 <*> x5
else b
where
f !r = mo... | package main
import "fmt"
func a(k int, x1, x2, x3, x4, x5 func() int) int {
var b func() int
b = func() int {
k--
return a(k, b, x1, x2, x3, x4)
}
if k <= 0 {
return x4() + x5()
}
return b()
}
func main() {
x := func(i int) func() int { return func() int { return i } }
fmt.Println(a(10, x(1), x(-1), x(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.