Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Write a version of this J function in Go with identical behavior.
stem =: <.@(%&10) leaf =: 10&| stemleaf =: (stem@{. ; leaf)/.~ stem expandStems =: <./ ([ + i.@>:@-~) >./ expandLeaves=: (expandStems e. ])@[ #inv ] showStemLeaf=: (":@,.@expandStems@[ ; ":&>@expandLeaves)&>/@(>@{. ; <@{:)@|:@stemleaf@/:~
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Convert this Julia snippet to C and keep its semantics consistent.
function stemleaf{T<:Real}(a::Array{T,1}, leafsize=1) ls = 10^int(log10(leafsize)) (stem, leaf) = divrem(sort(int(a/ls)), 10) leaf[sign(stem) .== -1] *= -1 negzero = leaf .< 0 if any(negzero) leaf[negzero] *= -1 nz = @sprintf "%10s | " "-0" nz *= join(map(string, leaf[negzero...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Rewrite this program in C# while keeping its functionality equivalent to the Julia version.
function stemleaf{T<:Real}(a::Array{T,1}, leafsize=1) ls = 10^int(log10(leafsize)) (stem, leaf) = divrem(sort(int(a/ls)), 10) leaf[sign(stem) .== -1] *= -1 negzero = leaf .< 0 if any(negzero) leaf[negzero] *= -1 nz = @sprintf "%10s | " "-0" nz *= join(map(string, leaf[negzero...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Change the following Julia code into C++ without altering its purpose.
function stemleaf{T<:Real}(a::Array{T,1}, leafsize=1) ls = 10^int(log10(leafsize)) (stem, leaf) = divrem(sort(int(a/ls)), 10) leaf[sign(stem) .== -1] *= -1 negzero = leaf .< 0 if any(negzero) leaf[negzero] *= -1 nz = @sprintf "%10s | " "-0" nz *= join(map(string, leaf[negzero...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Transform the following Julia implementation into Java, maintaining the same output and logic.
function stemleaf{T<:Real}(a::Array{T,1}, leafsize=1) ls = 10^int(log10(leafsize)) (stem, leaf) = divrem(sort(int(a/ls)), 10) leaf[sign(stem) .== -1] *= -1 negzero = leaf .< 0 if any(negzero) leaf[negzero] *= -1 nz = @sprintf "%10s | " "-0" nz *= join(map(string, leaf[negzero...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Rewrite the snippet below in Python so it works the same as the original Julia code.
function stemleaf{T<:Real}(a::Array{T,1}, leafsize=1) ls = 10^int(log10(leafsize)) (stem, leaf) = divrem(sort(int(a/ls)), 10) leaf[sign(stem) .== -1] *= -1 negzero = leaf .< 0 if any(negzero) leaf[negzero] *= -1 nz = @sprintf "%10s | " "-0" nz *= join(map(string, leaf[negzero...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Maintain the same structure and functionality when rewriting this code in Go.
function stemleaf{T<:Real}(a::Array{T,1}, leafsize=1) ls = 10^int(log10(leafsize)) (stem, leaf) = divrem(sort(int(a/ls)), 10) leaf[sign(stem) .== -1] *= -1 negzero = leaf .< 0 if any(negzero) leaf[negzero] *= -1 nz = @sprintf "%10s | " "-0" nz *= join(map(string, leaf[negzero...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Port the following code from Lua to C# with equivalent syntax and logic.
data = { 12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, 63,27,44,105,99,41,128,121,116,125,32,61,37,127,29,113,121,58,114,126, 53,114,96,25,109,7,31,141,46,13,27,43,117,116,27,7,68,40,31,115,124,42, 128,52,...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Convert this Lua block to C++, preserving its control flow and logic.
data = { 12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, 63,27,44,105,99,41,128,121,116,125,32,61,37,127,29,113,121,58,114,126, 53,114,96,25,109,7,31,141,46,13,27,43,117,116,27,7,68,40,31,115,124,42, 128,52,...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Write the same code in Java as shown below in Lua.
data = { 12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, 63,27,44,105,99,41,128,121,116,125,32,61,37,127,29,113,121,58,114,126, 53,114,96,25,109,7,31,141,46,13,27,43,117,116,27,7,68,40,31,115,124,42, 128,52,...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Write a version of this Lua function in Python with identical behavior.
data = { 12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, 63,27,44,105,99,41,128,121,116,125,32,61,37,127,29,113,121,58,114,126, 53,114,96,25,109,7,31,141,46,13,27,43,117,116,27,7,68,40,31,115,124,42, 128,52,...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Write a version of this Lua function in Go with identical behavior.
data = { 12,127,28,42,39,113, 42,18,44,118,44,37,113,124,37,48,127,36,29,31, 125,139,131,115,105,132,104,123,35,113,122,42,117,119,58,109,23,105, 63,27,44,105,99,41,128,121,116,125,32,61,37,127,29,113,121,58,114,126, 53,114,96,25,109,7,31,141,46,13,27,43,117,116,27,7,68,40,31,115,124,42, 128,52,...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Convert the following code from Mathematica to C, ensuring the logic remains intact.
len[n_] := RealDigits[n][[2]]; padding = len[Max@ Quotient[inputdata, 10]]; For[i = Min@ Quotient[inputdata, 10],i <= Max@ Quotient[inputdata, 10], i++, (Print[i, If[(padding - len[i]) > 0, (padding - len[i])*" " <> " |", " |"] , StringJoin[(" " <> #) & /@ Map[ToString, #]]])&@ Select[{Quotient[#, 10], Mod[#, 10]} ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Produce a language-to-language conversion: from Mathematica to C#, same semantics.
len[n_] := RealDigits[n][[2]]; padding = len[Max@ Quotient[inputdata, 10]]; For[i = Min@ Quotient[inputdata, 10],i <= Max@ Quotient[inputdata, 10], i++, (Print[i, If[(padding - len[i]) > 0, (padding - len[i])*" " <> " |", " |"] , StringJoin[(" " <> #) & /@ Map[ToString, #]]])&@ Select[{Quotient[#, 10], Mod[#, 10]} ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Ensure the translated C++ code behaves exactly like the original Mathematica snippet.
len[n_] := RealDigits[n][[2]]; padding = len[Max@ Quotient[inputdata, 10]]; For[i = Min@ Quotient[inputdata, 10],i <= Max@ Quotient[inputdata, 10], i++, (Print[i, If[(padding - len[i]) > 0, (padding - len[i])*" " <> " |", " |"] , StringJoin[(" " <> #) & /@ Map[ToString, #]]])&@ Select[{Quotient[#, 10], Mod[#, 10]} ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Transform the following Mathematica implementation into Java, maintaining the same output and logic.
len[n_] := RealDigits[n][[2]]; padding = len[Max@ Quotient[inputdata, 10]]; For[i = Min@ Quotient[inputdata, 10],i <= Max@ Quotient[inputdata, 10], i++, (Print[i, If[(padding - len[i]) > 0, (padding - len[i])*" " <> " |", " |"] , StringJoin[(" " <> #) & /@ Map[ToString, #]]])&@ Select[{Quotient[#, 10], Mod[#, 10]} ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Can you help me rewrite this code in Python instead of Mathematica, keeping it the same logically?
len[n_] := RealDigits[n][[2]]; padding = len[Max@ Quotient[inputdata, 10]]; For[i = Min@ Quotient[inputdata, 10],i <= Max@ Quotient[inputdata, 10], i++, (Print[i, If[(padding - len[i]) > 0, (padding - len[i])*" " <> " |", " |"] , StringJoin[(" " <> #) & /@ Map[ToString, #]]])&@ Select[{Quotient[#, 10], Mod[#, 10]} ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Produce a functionally identical Go code for the snippet given in Mathematica.
len[n_] := RealDigits[n][[2]]; padding = len[Max@ Quotient[inputdata, 10]]; For[i = Min@ Quotient[inputdata, 10],i <= Max@ Quotient[inputdata, 10], i++, (Print[i, If[(padding - len[i]) > 0, (padding - len[i])*" " <> " |", " |"] , StringJoin[(" " <> #) & /@ Map[ToString, #]]])&@ Select[{Quotient[#, 10], Mod[#, 10]} ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Rewrite this program in C while keeping its functionality equivalent to the MATLAB version.
function stem_and_leaf_plot(x,stem_unit,leaf_unit) if nargin < 2, stem_unit = 10; end; if nargin < 3, leaf_unit = 1; else x = leaf_unit*round(x/leaf_unit); end; stem = floor(x/stem_unit); leaf = mod(x,stem_unit); for k = min(stem):max(stem) printf('\n printf(' end; printf('\n...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Transform the following MATLAB implementation into C#, maintaining the same output and logic.
function stem_and_leaf_plot(x,stem_unit,leaf_unit) if nargin < 2, stem_unit = 10; end; if nargin < 3, leaf_unit = 1; else x = leaf_unit*round(x/leaf_unit); end; stem = floor(x/stem_unit); leaf = mod(x,stem_unit); for k = min(stem):max(stem) printf('\n printf(' end; printf('\n...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Rewrite the snippet below in C++ so it works the same as the original MATLAB code.
function stem_and_leaf_plot(x,stem_unit,leaf_unit) if nargin < 2, stem_unit = 10; end; if nargin < 3, leaf_unit = 1; else x = leaf_unit*round(x/leaf_unit); end; stem = floor(x/stem_unit); leaf = mod(x,stem_unit); for k = min(stem):max(stem) printf('\n printf(' end; printf('\n...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Produce a functionally identical Java code for the snippet given in MATLAB.
function stem_and_leaf_plot(x,stem_unit,leaf_unit) if nargin < 2, stem_unit = 10; end; if nargin < 3, leaf_unit = 1; else x = leaf_unit*round(x/leaf_unit); end; stem = floor(x/stem_unit); leaf = mod(x,stem_unit); for k = min(stem):max(stem) printf('\n printf(' end; printf('\n...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Transform the following MATLAB implementation into Python, maintaining the same output and logic.
function stem_and_leaf_plot(x,stem_unit,leaf_unit) if nargin < 2, stem_unit = 10; end; if nargin < 3, leaf_unit = 1; else x = leaf_unit*round(x/leaf_unit); end; stem = floor(x/stem_unit); leaf = mod(x,stem_unit); for k = min(stem):max(stem) printf('\n printf(' end; printf('\n...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Rewrite this program in Go while keeping its functionality equivalent to the MATLAB version.
function stem_and_leaf_plot(x,stem_unit,leaf_unit) if nargin < 2, stem_unit = 10; end; if nargin < 3, leaf_unit = 1; else x = leaf_unit*round(x/leaf_unit); end; stem = floor(x/stem_unit); leaf = mod(x,stem_unit); for k = min(stem):max(stem) printf('\n printf(' end; printf('\n...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Can you help me rewrite this code in C instead of Nim, keeping it the same logically?
import tables import math import strutils import algorithm type StemLeafPlot = ref object leafDigits: int multiplier: int plot: TableRef[int, seq[int]] proc `$`(s: seq[int]): string = result = "" for item in s: result &= $item & " " proc `$`(self: StemLeafPlot): string = result = "" var key...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Please provide an equivalent version of this Nim code in C#.
import tables import math import strutils import algorithm type StemLeafPlot = ref object leafDigits: int multiplier: int plot: TableRef[int, seq[int]] proc `$`(s: seq[int]): string = result = "" for item in s: result &= $item & " " proc `$`(self: StemLeafPlot): string = result = "" var key...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Produce a language-to-language conversion: from Nim to C++, same semantics.
import tables import math import strutils import algorithm type StemLeafPlot = ref object leafDigits: int multiplier: int plot: TableRef[int, seq[int]] proc `$`(s: seq[int]): string = result = "" for item in s: result &= $item & " " proc `$`(self: StemLeafPlot): string = result = "" var key...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Port the provided Nim code into Java while preserving the original functionality.
import tables import math import strutils import algorithm type StemLeafPlot = ref object leafDigits: int multiplier: int plot: TableRef[int, seq[int]] proc `$`(s: seq[int]): string = result = "" for item in s: result &= $item & " " proc `$`(self: StemLeafPlot): string = result = "" var key...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Port the following code from Nim to Python with equivalent syntax and logic.
import tables import math import strutils import algorithm type StemLeafPlot = ref object leafDigits: int multiplier: int plot: TableRef[int, seq[int]] proc `$`(s: seq[int]): string = result = "" for item in s: result &= $item & " " proc `$`(self: StemLeafPlot): string = result = "" var key...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Convert the following code from Nim to Go, ensuring the logic remains intact.
import tables import math import strutils import algorithm type StemLeafPlot = ref object leafDigits: int multiplier: int plot: TableRef[int, seq[int]] proc `$`(s: seq[int]): string = result = "" for item in s: result &= $item & " " proc `$`(self: StemLeafPlot): string = result = "" var key...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Produce a functionally identical C code for the snippet given in OCaml.
let unique li = let rec aux acc = function | [] -> (List.rev acc) | x::xs -> if List.mem x acc then aux acc xs else aux (x::acc) xs in aux [] li
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Port the provided OCaml code into C# while preserving the original functionality.
let unique li = let rec aux acc = function | [] -> (List.rev acc) | x::xs -> if List.mem x acc then aux acc xs else aux (x::acc) xs in aux [] li
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Convert this OCaml snippet to C++ and keep its semantics consistent.
let unique li = let rec aux acc = function | [] -> (List.rev acc) | x::xs -> if List.mem x acc then aux acc xs else aux (x::acc) xs in aux [] li
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Write a version of this OCaml function in Java with identical behavior.
let unique li = let rec aux acc = function | [] -> (List.rev acc) | x::xs -> if List.mem x acc then aux acc xs else aux (x::acc) xs in aux [] li
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Produce a functionally identical Python code for the snippet given in OCaml.
let unique li = let rec aux acc = function | [] -> (List.rev acc) | x::xs -> if List.mem x acc then aux acc xs else aux (x::acc) xs in aux [] li
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Port the following code from OCaml to Go with equivalent syntax and logic.
let unique li = let rec aux acc = function | [] -> (List.rev acc) | x::xs -> if List.mem x acc then aux acc xs else aux (x::acc) xs in aux [] li
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Port the following code from Perl to C with equivalent syntax and logic.
my @data = sort {$a <=> $b} qw( 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Generate a C# translation of this Perl snippet without changing its computational steps.
my @data = sort {$a <=> $b} qw( 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Convert this Perl snippet to C++ and keep its semantics consistent.
my @data = sort {$a <=> $b} qw( 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Maintain the same structure and functionality when rewriting this code in Java.
my @data = sort {$a <=> $b} qw( 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Port the provided Perl code into Python while preserving the original functionality.
my @data = sort {$a <=> $b} qw( 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Generate an equivalent Go version of this Perl code.
my @data = sort {$a <=> $b} qw( 12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Translate this program into C but keep the logic exactly as in PowerShell.
$Set = -split '12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Convert this PowerShell snippet to C# and keep its semantics consistent.
$Set = -split '12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Port the provided PowerShell code into C++ while preserving the original functionality.
$Set = -split '12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Translate this program into Java but keep the logic exactly as in PowerShell.
$Set = -split '12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Rewrite the snippet below in Python so it works the same as the original PowerShell code.
$Set = -split '12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Preserve the algorithm and functionality while converting the code from PowerShell to Go.
$Set = -split '12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 117 116 27 7 68 40 31 115 124 42 128 52 71 118 117 38 27 106 33...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Produce a functionally identical C code for the snippet given in R.
x <- c(12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121, 58, 114, 126, 53, 114, 96, 25, 109, 7, 31, 141, 46, 13, 27, 43...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Ensure the translated C# code behaves exactly like the original R snippet.
x <- c(12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121, 58, 114, 126, 53, 114, 96, 25, 109, 7, 31, 141, 46, 13, 27, 43...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Maintain the same structure and functionality when rewriting this code in C++.
x <- c(12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121, 58, 114, 126, 53, 114, 96, 25, 109, 7, 31, 141, 46, 13, 27, 43...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Rewrite the snippet below in Java so it works the same as the original R code.
x <- c(12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121, 58, 114, 126, 53, 114, 96, 25, 109, 7, 31, 141, 46, 13, 27, 43...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Transform the following R implementation into Python, maintaining the same output and logic.
x <- c(12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121, 58, 114, 126, 53, 114, 96, 25, 109, 7, 31, 141, 46, 13, 27, 43...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Maintain the same structure and functionality when rewriting this code in Go.
x <- c(12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, 42, 117, 119, 58, 109, 23, 105, 63, 27, 44, 105, 99, 41, 128, 121, 116, 125, 32, 61, 37, 127, 29, 113, 121, 58, 114, 126, 53, 114, 96, 25, 109, 7, 31, 141, 46, 13, 27, 43...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Write a version of this Racket function in C with identical behavior.
#lang racket (define (show-stem+leaf data) (define xs (sort data <)) (for ([stem (add1 (floor (/ (last xs) 10)))]) (printf "~a|" (~a #:width 2 #:align 'right stem)) (for ([i xs]) (define-values [q r] (quotient/remainder i 10)) (when (= q stem) (printf " ~a" r))) (newline))) (show-stem+leaf (...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Can you help me rewrite this code in C# instead of Racket, keeping it the same logically?
#lang racket (define (show-stem+leaf data) (define xs (sort data <)) (for ([stem (add1 (floor (/ (last xs) 10)))]) (printf "~a|" (~a #:width 2 #:align 'right stem)) (for ([i xs]) (define-values [q r] (quotient/remainder i 10)) (when (= q stem) (printf " ~a" r))) (newline))) (show-stem+leaf (...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Rewrite this program in C++ while keeping its functionality equivalent to the Racket version.
#lang racket (define (show-stem+leaf data) (define xs (sort data <)) (for ([stem (add1 (floor (/ (last xs) 10)))]) (printf "~a|" (~a #:width 2 #:align 'right stem)) (for ([i xs]) (define-values [q r] (quotient/remainder i 10)) (when (= q stem) (printf " ~a" r))) (newline))) (show-stem+leaf (...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Port the provided Racket code into Java while preserving the original functionality.
#lang racket (define (show-stem+leaf data) (define xs (sort data <)) (for ([stem (add1 (floor (/ (last xs) 10)))]) (printf "~a|" (~a #:width 2 #:align 'right stem)) (for ([i xs]) (define-values [q r] (quotient/remainder i 10)) (when (= q stem) (printf " ~a" r))) (newline))) (show-stem+leaf (...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Convert the following code from Racket to Python, ensuring the logic remains intact.
#lang racket (define (show-stem+leaf data) (define xs (sort data <)) (for ([stem (add1 (floor (/ (last xs) 10)))]) (printf "~a|" (~a #:width 2 #:align 'right stem)) (for ([i xs]) (define-values [q r] (quotient/remainder i 10)) (when (= q stem) (printf " ~a" r))) (newline))) (show-stem+leaf (...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Generate an equivalent Go version of this Racket code.
#lang racket (define (show-stem+leaf data) (define xs (sort data <)) (for ([stem (add1 (floor (/ (last xs) 10)))]) (printf "~a|" (~a #:width 2 #:align 'right stem)) (for ([i xs]) (define-values [q r] (quotient/remainder i 10)) (when (= q stem) (printf " ~a" r))) (newline))) (show-stem+leaf (...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Generate a C translation of this REXX snippet without changing its computational steps.
parse arg @ if @='' then @=12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139, 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121, 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 1...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Port the following code from REXX to C# with equivalent syntax and logic.
parse arg @ if @='' then @=12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139, 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121, 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 1...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Rewrite this program in C++ while keeping its functionality equivalent to the REXX version.
parse arg @ if @='' then @=12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139, 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121, 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 1...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Please provide an equivalent version of this REXX code in Java.
parse arg @ if @='' then @=12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139, 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121, 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 1...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Keep all operations the same but rewrite the snippet in Python.
parse arg @ if @='' then @=12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139, 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121, 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 1...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Preserve the algorithm and functionality while converting the code from REXX to Go.
parse arg @ if @='' then @=12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 125 139, 131 115 105 132 104 123 35 113 122 42 117 119 58 109 23 105 63 27 44 105 99 41 128 121, 116 125 32 61 37 127 29 113 121 58 114 126 53 114 96 25 109 7 31 141 46 13 27 43 1...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Rewrite this program in C while keeping its functionality equivalent to the Ruby version.
class StemLeafPlot def initialize(data, options = {}) opts = {:leaf_digits => 1}.merge(options) @leaf_digits = opts[:leaf_digits] @multiplier = 10 ** @leaf_digits @plot = generate_structure(data) end private def generate_structure(data) plot = Hash.new {|h,k| h[k] = []} data.sort.each ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Convert the following code from Ruby to C#, ensuring the logic remains intact.
class StemLeafPlot def initialize(data, options = {}) opts = {:leaf_digits => 1}.merge(options) @leaf_digits = opts[:leaf_digits] @multiplier = 10 ** @leaf_digits @plot = generate_structure(data) end private def generate_structure(data) plot = Hash.new {|h,k| h[k] = []} data.sort.each ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Produce a functionally identical C++ code for the snippet given in Ruby.
class StemLeafPlot def initialize(data, options = {}) opts = {:leaf_digits => 1}.merge(options) @leaf_digits = opts[:leaf_digits] @multiplier = 10 ** @leaf_digits @plot = generate_structure(data) end private def generate_structure(data) plot = Hash.new {|h,k| h[k] = []} data.sort.each ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Convert the following code from Ruby to Java, ensuring the logic remains intact.
class StemLeafPlot def initialize(data, options = {}) opts = {:leaf_digits => 1}.merge(options) @leaf_digits = opts[:leaf_digits] @multiplier = 10 ** @leaf_digits @plot = generate_structure(data) end private def generate_structure(data) plot = Hash.new {|h,k| h[k] = []} data.sort.each ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Generate an equivalent Python version of this Ruby code.
class StemLeafPlot def initialize(data, options = {}) opts = {:leaf_digits => 1}.merge(options) @leaf_digits = opts[:leaf_digits] @multiplier = 10 ** @leaf_digits @plot = generate_structure(data) end private def generate_structure(data) plot = Hash.new {|h,k| h[k] = []} data.sort.each ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Convert this Ruby snippet to Go and keep its semantics consistent.
class StemLeafPlot def initialize(data, options = {}) opts = {:leaf_digits => 1}.merge(options) @leaf_digits = opts[:leaf_digits] @multiplier = 10 ** @leaf_digits @plot = generate_structure(data) end private def generate_structure(data) plot = Hash.new {|h,k| h[k] = []} data.sort.each ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Translate this program into C but keep the logic exactly as in Scala.
fun leafPlot(x: IntArray) { x.sort() var i = x[0] / 10 - 1 for (j in 0 until x.size) { val d = x[j] / 10 while (d > i) print("%s%3d |".format(if (j != 0) "\n" else "", ++i)) print(" ${x[j] % 10}") } println() } fun main(args: Array<String>) { val data = intArrayOf( ...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Translate the given Scala code snippet into C# without altering its behavior.
fun leafPlot(x: IntArray) { x.sort() var i = x[0] / 10 - 1 for (j in 0 until x.size) { val d = x[j] / 10 while (d > i) print("%s%3d |".format(if (j != 0) "\n" else "", ++i)) print(" ${x[j] % 10}") } println() } fun main(args: Array<String>) { val data = intArrayOf( ...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Keep all operations the same but rewrite the snippet in C++.
fun leafPlot(x: IntArray) { x.sort() var i = x[0] / 10 - 1 for (j in 0 until x.size) { val d = x[j] / 10 while (d > i) print("%s%3d |".format(if (j != 0) "\n" else "", ++i)) print(" ${x[j] % 10}") } println() } fun main(args: Array<String>) { val data = intArrayOf( ...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Ensure the translated Java code behaves exactly like the original Scala snippet.
fun leafPlot(x: IntArray) { x.sort() var i = x[0] / 10 - 1 for (j in 0 until x.size) { val d = x[j] / 10 while (d > i) print("%s%3d |".format(if (j != 0) "\n" else "", ++i)) print(" ${x[j] % 10}") } println() } fun main(args: Array<String>) { val data = intArrayOf( ...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Produce a functionally identical Python code for the snippet given in Scala.
fun leafPlot(x: IntArray) { x.sort() var i = x[0] / 10 - 1 for (j in 0 until x.size) { val d = x[j] / 10 while (d > i) print("%s%3d |".format(if (j != 0) "\n" else "", ++i)) print(" ${x[j] % 10}") } println() } fun main(args: Array<String>) { val data = intArrayOf( ...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Produce a functionally identical Go code for the snippet given in Scala.
fun leafPlot(x: IntArray) { x.sort() var i = x[0] / 10 - 1 for (j in 0 until x.size) { val d = x[j] / 10 while (d > i) print("%s%3d |".format(if (j != 0) "\n" else "", ++i)) print(" ${x[j] % 10}") } println() } fun main(args: Array<String>) { val data = intArrayOf( ...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Please provide an equivalent version of this Tcl code in C.
package require Tcl 8.5 proc addSLValue {tblName value {splitFactor 10}} { upvar 1 $tblName tbl if {$value < 0} { set value [expr {round(-$value)}] set stem -[expr {$value / $splitFactor}] } else { set value [expr {round($value)}] set stem [expr {$value / $splitFactor}] } if {![info exis...
#include <stdio.h> #include <stdlib.h> int icmp(const void *a, const void *b) { return *(const int*)a < *(const int*)b ? -1 : *(const int*)a > *(const int*)b; } void leaf_plot(int *x, int len) { int i, j, d; qsort(x, len, sizeof(int), icmp); i = x[0] / 10 - 1; for (j = 0; j < len; j++) { d = x[j] / 10; whi...
Ensure the translated C# code behaves exactly like the original Tcl snippet.
package require Tcl 8.5 proc addSLValue {tblName value {splitFactor 10}} { upvar 1 $tblName tbl if {$value < 0} { set value [expr {round(-$value)}] set stem -[expr {$value / $splitFactor}] } else { set value [expr {round($value)}] set stem [expr {$value / $splitFactor}] } if {![info exis...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static void Main() { const string data = "12 127 28 42 39 113 42 18 44 118 44 37 113 124 37 48 127 36 29 31 " + "125 139 131 115 105 132 104 123 35 113 122...
Convert this Tcl snippet to C++ and keep its semantics consistent.
package require Tcl 8.5 proc addSLValue {tblName value {splitFactor 10}} { upvar 1 $tblName tbl if {$value < 0} { set value [expr {round(-$value)}] set stem -[expr {$value / $splitFactor}] } else { set value [expr {round($value)}] set stem [expr {$value / $splitFactor}] } if {![info exis...
#include <algorithm> #include <iomanip> #include <iostream> #include <vector> const int dataset[] = { 12,127, 28, 42, 39,113, 42, 18, 44,118, 44, 37,113,124, 37, 48,127, 36, 29, 31,125,139,131,115,105,132,104,123, 35,113,122, 42,117,119, 58,109, 23,105, 63, 27, 44,105, 99, 41,128,121,116,125, 32, 61, 37...
Convert this Tcl snippet to Java and keep its semantics consistent.
package require Tcl 8.5 proc addSLValue {tblName value {splitFactor 10}} { upvar 1 $tblName tbl if {$value < 0} { set value [expr {round(-$value)}] set stem -[expr {$value / $splitFactor}] } else { set value [expr {round($value)}] set stem [expr {$value / $splitFactor}] } if {![info exis...
import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class StemAndLeaf { private static int[] data = { 12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123,...
Produce a functionally identical Python code for the snippet given in Tcl.
package require Tcl 8.5 proc addSLValue {tblName value {splitFactor 10}} { upvar 1 $tblName tbl if {$value < 0} { set value [expr {round(-$value)}] set stem -[expr {$value / $splitFactor}] } else { set value [expr {round($value)}] set stem [expr {$value / $splitFactor}] } if {![info exis...
from collections import namedtuple from pprint import pprint as pp from math import floor Stem = namedtuple('Stem', 'data, leafdigits') data0 = Stem((12, 127, 28, 42, 39, 113, 42, 18, 44, 118, 44, 37, 113, 124, 37, 48, 127, 36, 29, 31, 125, 139, 131, 115, 105, 132, 104, 123, 35, 113, 122, ...
Generate an equivalent Go version of this Tcl code.
package require Tcl 8.5 proc addSLValue {tblName value {splitFactor 10}} { upvar 1 $tblName tbl if {$value < 0} { set value [expr {round(-$value)}] set stem -[expr {$value / $splitFactor}] } else { set value [expr {round($value)}] set stem [expr {$value / $splitFactor}] } if {![info exis...
package main import ( "fmt" "sort" "strconv" "strings" ) var data = `12 127 28 42` func main() { m := make(map[int][]string) for _, s := range strings.Fields(data) { if len(s) == 1 { m[0] = append(m[0], s) } else if i, err := strconv.Atoi(s[:len(s)-1]); err =...
Translate the given Ada code snippet into C# without altering its behavior.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
using System; using System.Collections; using System.Linq; namespace RosettaCodeTasks { static class FlattenList { public static ArrayList Flatten(this ArrayList List) { ArrayList NewList = new ArrayList ( ); NewList.AddRange ( List ); while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 ) { int...
Convert the following code from Ada to C#, ensuring the logic remains intact.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
using System; using System.Collections; using System.Linq; namespace RosettaCodeTasks { static class FlattenList { public static ArrayList Flatten(this ArrayList List) { ArrayList NewList = new ArrayList ( ); NewList.AddRange ( List ); while ( NewList.OfType<ArrayList> ( ).Count ( ) > 0 ) { int...
Write the same code in C as shown below in Ada.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct list_t list_t, *list; struct list_t{ int is_list, ival; list *lst; }; list new_list() { list x = malloc(sizeof(list_t)); x->ival = 0; x->is_list = 1; x->lst = 0; return x; } void append(list parent, list child) { parent->lst = realloc...
Produce a functionally identical C code for the snippet given in Ada.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct list_t list_t, *list; struct list_t{ int is_list, ival; list *lst; }; list new_list() { list x = malloc(sizeof(list_t)); x->ival = 0; x->is_list = 1; x->lst = 0; return x; } void append(list parent, list child) { parent->lst = realloc...
Translate this program into C++ but keep the logic exactly as in Ada.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
#include <list> #include <boost/any.hpp> typedef std::list<boost::any> anylist; void flatten(std::list<boost::any>& list) { typedef anylist::iterator iterator; iterator current = list.begin(); while (current != list.end()) { if (current->type() == typeid(anylist)) { iterator next = current; ...
Rewrite this program in C++ while keeping its functionality equivalent to the Ada version.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
#include <list> #include <boost/any.hpp> typedef std::list<boost::any> anylist; void flatten(std::list<boost::any>& list) { typedef anylist::iterator iterator; iterator current = list.begin(); while (current != list.end()) { if (current->type() == typeid(anylist)) { iterator next = current; ...
Change the programming language of this snippet from Ada to Go without modifying what it does.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
package main import "fmt" func list(s ...interface{}) []interface{} { return s } func main() { s := list(list(1), 2, list(list(3, 4), 5), list(list(list())), list(list(list(6))), 7, 8, list(), ) fmt.Println(s) fmt.Println(flatten(s)) } func...
Maintain the same structure and functionality when rewriting this code in Go.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
package main import "fmt" func list(s ...interface{}) []interface{} { return s } func main() { s := list(list(1), 2, list(list(3, 4), 5), list(list(list())), list(list(list(6))), 7, 8, list(), ) fmt.Println(s) fmt.Println(flatten(s)) } func...
Keep all operations the same but rewrite the snippet in Java.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
import java.util.LinkedList; import java.util.List; public final class FlattenUtil { public static List<Object> flatten(List<?> list) { List<Object> retVal = new LinkedList<Object>(); flatten(list, retVal); return retVal; } public static void flatten(List<?> fromTreeList, List<Object> toFlatList) { for (...
Preserve the algorithm and functionality while converting the code from Ada to Java.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
import java.util.LinkedList; import java.util.List; public final class FlattenUtil { public static List<Object> flatten(List<?> list) { List<Object> retVal = new LinkedList<Object>(); flatten(list, retVal); return retVal; } public static void flatten(List<?> fromTreeList, List<Object> toFlatList) { for (...
Maintain the same structure and functionality when rewriting this code in Python.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
>>> def flatten(lst): return sum( ([x] if not isinstance(x, list) else flatten(x) for x in lst), [] ) >>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []] >>> flatten(lst) [1, 2, 3, 4, 5, 6, 7, 8]
Port the provided Ada code into Python while preserving the original functionality.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
>>> def flatten(lst): return sum( ([x] if not isinstance(x, list) else flatten(x) for x in lst), [] ) >>> lst = [[1], 2, [[3,4], 5], [[[]]], [[[6]]], 7, 8, []] >>> flatten(lst) [1, 2, 3, 4, 5, 6, 7, 8]
Port the provided Ada code into VB while preserving the original functionality.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
class flattener dim separator sub class_initialize separator = "," end sub private function makeflat( a ) dim i dim res for i = lbound( a ) to ubound( a ) if isarray( a( i ) ) then res = res & makeflat( a( i ) ) else res = res & a( i ) & separator end if next makeflat = res end f...
Change the programming language of this snippet from Ada to VB without modifying what it does.
generic type Element_Type is private; with function To_String (E : Element_Type) return String is <>; package Nestable_Lists is type Node_Kind is (Data_Node, List_Node); type Node (Kind : Node_Kind); type List is access Node; type Node (Kind : Node_Kind) is record Next : List; ...
class flattener dim separator sub class_initialize separator = "," end sub private function makeflat( a ) dim i dim res for i = lbound( a ) to ubound( a ) if isarray( a( i ) ) then res = res & makeflat( a( i ) ) else res = res & a( i ) & separator end if next makeflat = res end f...
Convert this Arturo block to C, preserving its control flow and logic.
print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct list_t list_t, *list; struct list_t{ int is_list, ival; list *lst; }; list new_list() { list x = malloc(sizeof(list_t)); x->ival = 0; x->is_list = 1; x->lst = 0; return x; } void append(list parent, list child) { parent->lst = realloc...
Change the following Arturo code into C without altering its purpose.
print flatten [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []]
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct list_t list_t, *list; struct list_t{ int is_list, ival; list *lst; }; list new_list() { list x = malloc(sizeof(list_t)); x->ival = 0; x->is_list = 1; x->lst = 0; return x; } void append(list parent, list child) { parent->lst = realloc...