Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Preserve the algorithm and functionality while converting the code from Ada to VB. | WITH Ada.Containers.Generic_Array_Sort, Ada.Text_IO;
USE Ada.Text_IO;
PROCEDURE Main IS
TYPE Natural_Array IS ARRAY (Positive RANGE <>) OF Natural;
FUNCTION Less (L, R : Natural) RETURN Boolean IS (L'Img < R'Img);
PROCEDURE Sort_Naturals IS NEW Ada.Containers.Generic_Array_Sort
(Positive, Natural, Natura... | Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Rewrite the snippet below in C so it works the same as the original Arturo code. | arr: 1..13
print sort map arr => [to :string &]
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Write the same algorithm in C# as shown in this Arturo implementation. | arr: 1..13
print sort map arr => [to :string &]
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Change the following Arturo code into C++ without altering its purpose. | arr: 1..13
print sort map arr => [to :string &]
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Port the following code from Arturo to Java with equivalent syntax and logic. | arr: 1..13
print sort map arr => [to :string &]
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Please provide an equivalent version of this Arturo code in Python. | arr: 1..13
print sort map arr => [to :string &]
| n=13
print(sorted(range(1,n+1), key=str))
|
Write the same algorithm in VB as shown in this Arturo implementation. | arr: 1..13
print sort map arr => [to :string &]
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Ensure the translated Go code behaves exactly like the original Arturo snippet. | arr: 1..13
print sort map arr => [to :string &]
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Produce a language-to-language conversion: from AutoHotKey to C, same semantics. | n2lexicog(n){
Arr := [], list := ""
loop % n
list .= A_Index "`n"
Sort, list
for k, v in StrSplit(Trim(list, "`n"), "`n")
Arr.Push(v)
return Arr
}
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Keep all operations the same but rewrite the snippet in C#. | n2lexicog(n){
Arr := [], list := ""
loop % n
list .= A_Index "`n"
Sort, list
for k, v in StrSplit(Trim(list, "`n"), "`n")
Arr.Push(v)
return Arr
}
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Rewrite the snippet below in C++ so it works the same as the original AutoHotKey code. | n2lexicog(n){
Arr := [], list := ""
loop % n
list .= A_Index "`n"
Sort, list
for k, v in StrSplit(Trim(list, "`n"), "`n")
Arr.Push(v)
return Arr
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Convert the following code from AutoHotKey to Java, ensuring the logic remains intact. | n2lexicog(n){
Arr := [], list := ""
loop % n
list .= A_Index "`n"
Sort, list
for k, v in StrSplit(Trim(list, "`n"), "`n")
Arr.Push(v)
return Arr
}
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Can you help me rewrite this code in Python instead of AutoHotKey, keeping it the same logically? | n2lexicog(n){
Arr := [], list := ""
loop % n
list .= A_Index "`n"
Sort, list
for k, v in StrSplit(Trim(list, "`n"), "`n")
Arr.Push(v)
return Arr
}
| n=13
print(sorted(range(1,n+1), key=str))
|
Generate an equivalent VB version of this AutoHotKey code. | n2lexicog(n){
Arr := [], list := ""
loop % n
list .= A_Index "`n"
Sort, list
for k, v in StrSplit(Trim(list, "`n"), "`n")
Arr.Push(v)
return Arr
}
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Write the same algorithm in Go as shown in this AutoHotKey implementation. | n2lexicog(n){
Arr := [], list := ""
loop % n
list .= A_Index "`n"
Sort, list
for k, v in StrSplit(Trim(list, "`n"), "`n")
Arr.Push(v)
return Arr
}
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Produce a language-to-language conversion: from AWK to C, same semantics. |
BEGIN {
prn(0)
prn(1)
prn(13)
prn(9,10)
prn(-11,+11)
prn(-21)
prn("",1)
prn(+1,-1)
exit(0)
}
function prn(n1,n2) {
if (n1 <= 0 && n2 == "") {
n2 = 1
}
if (n2 == "") {
n2 = n1
n1 = 1
}
printf("%d to %d: %s\n",n1,n2,snl(n1,n2))
}
function snl... | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Port the provided AWK code into C# while preserving the original functionality. |
BEGIN {
prn(0)
prn(1)
prn(13)
prn(9,10)
prn(-11,+11)
prn(-21)
prn("",1)
prn(+1,-1)
exit(0)
}
function prn(n1,n2) {
if (n1 <= 0 && n2 == "") {
n2 = 1
}
if (n2 == "") {
n2 = n1
n1 = 1
}
printf("%d to %d: %s\n",n1,n2,snl(n1,n2))
}
function snl... | using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Produce a language-to-language conversion: from AWK to C++, same semantics. |
BEGIN {
prn(0)
prn(1)
prn(13)
prn(9,10)
prn(-11,+11)
prn(-21)
prn("",1)
prn(+1,-1)
exit(0)
}
function prn(n1,n2) {
if (n1 <= 0 && n2 == "") {
n2 = 1
}
if (n2 == "") {
n2 = n1
n1 = 1
}
printf("%d to %d: %s\n",n1,n2,snl(n1,n2))
}
function snl... | #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Please provide an equivalent version of this AWK code in Java. |
BEGIN {
prn(0)
prn(1)
prn(13)
prn(9,10)
prn(-11,+11)
prn(-21)
prn("",1)
prn(+1,-1)
exit(0)
}
function prn(n1,n2) {
if (n1 <= 0 && n2 == "") {
n2 = 1
}
if (n2 == "") {
n2 = n1
n1 = 1
}
printf("%d to %d: %s\n",n1,n2,snl(n1,n2))
}
function snl... | import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Write a version of this AWK function in Python with identical behavior. |
BEGIN {
prn(0)
prn(1)
prn(13)
prn(9,10)
prn(-11,+11)
prn(-21)
prn("",1)
prn(+1,-1)
exit(0)
}
function prn(n1,n2) {
if (n1 <= 0 && n2 == "") {
n2 = 1
}
if (n2 == "") {
n2 = n1
n1 = 1
}
printf("%d to %d: %s\n",n1,n2,snl(n1,n2))
}
function snl... | n=13
print(sorted(range(1,n+1), key=str))
|
Convert this AWK block to VB, preserving its control flow and logic. |
BEGIN {
prn(0)
prn(1)
prn(13)
prn(9,10)
prn(-11,+11)
prn(-21)
prn("",1)
prn(+1,-1)
exit(0)
}
function prn(n1,n2) {
if (n1 <= 0 && n2 == "") {
n2 = 1
}
if (n2 == "") {
n2 = n1
n1 = 1
}
printf("%d to %d: %s\n",n1,n2,snl(n1,n2))
}
function snl... | Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Port the following code from AWK to Go with equivalent syntax and logic. |
BEGIN {
prn(0)
prn(1)
prn(13)
prn(9,10)
prn(-11,+11)
prn(-21)
prn("",1)
prn(+1,-1)
exit(0)
}
function prn(n1,n2) {
if (n1 <= 0 && n2 == "") {
n2 = 1
}
if (n2 == "") {
n2 = n1
n1 = 1
}
printf("%d to %d: %s\n",n1,n2,snl(n1,n2))
}
function snl... | package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Maintain the same structure and functionality when rewriting this code in C. | N%=13
PRINT "[" LEFT$(FNLexOrder(0)) "]"
END
DEF FNLexOrder(nr%) : LOCAL i%, s$
FOR i%=nr% TO nr% + 9
IF i% > N% EXIT FOR
IF i% > 0 s$+=STR$i% + "," + FNLexOrder(i% * 10)
NEXT
=s$
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Write the same algorithm in C# as shown in this BBC_Basic implementation. | N%=13
PRINT "[" LEFT$(FNLexOrder(0)) "]"
END
DEF FNLexOrder(nr%) : LOCAL i%, s$
FOR i%=nr% TO nr% + 9
IF i% > N% EXIT FOR
IF i% > 0 s$+=STR$i% + "," + FNLexOrder(i% * 10)
NEXT
=s$
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Change the following BBC_Basic code into C++ without altering its purpose. | N%=13
PRINT "[" LEFT$(FNLexOrder(0)) "]"
END
DEF FNLexOrder(nr%) : LOCAL i%, s$
FOR i%=nr% TO nr% + 9
IF i% > N% EXIT FOR
IF i% > 0 s$+=STR$i% + "," + FNLexOrder(i% * 10)
NEXT
=s$
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Write the same algorithm in Java as shown in this BBC_Basic implementation. | N%=13
PRINT "[" LEFT$(FNLexOrder(0)) "]"
END
DEF FNLexOrder(nr%) : LOCAL i%, s$
FOR i%=nr% TO nr% + 9
IF i% > N% EXIT FOR
IF i% > 0 s$+=STR$i% + "," + FNLexOrder(i% * 10)
NEXT
=s$
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Preserve the algorithm and functionality while converting the code from BBC_Basic to Python. | N%=13
PRINT "[" LEFT$(FNLexOrder(0)) "]"
END
DEF FNLexOrder(nr%) : LOCAL i%, s$
FOR i%=nr% TO nr% + 9
IF i% > N% EXIT FOR
IF i% > 0 s$+=STR$i% + "," + FNLexOrder(i% * 10)
NEXT
=s$
| n=13
print(sorted(range(1,n+1), key=str))
|
Ensure the translated VB code behaves exactly like the original BBC_Basic snippet. | N%=13
PRINT "[" LEFT$(FNLexOrder(0)) "]"
END
DEF FNLexOrder(nr%) : LOCAL i%, s$
FOR i%=nr% TO nr% + 9
IF i% > N% EXIT FOR
IF i% > 0 s$+=STR$i% + "," + FNLexOrder(i% * 10)
NEXT
=s$
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Convert the following code from BBC_Basic to Go, ensuring the logic remains intact. | N%=13
PRINT "[" LEFT$(FNLexOrder(0)) "]"
END
DEF FNLexOrder(nr%) : LOCAL i%, s$
FOR i%=nr% TO nr% + 9
IF i% > N% EXIT FOR
IF i% > 0 s$+=STR$i% + "," + FNLexOrder(i% * 10)
NEXT
=s$
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Produce a language-to-language conversion: from Clojure to C, same semantics. | (def n 13)
(sort-by str (range 1 (inc n)))
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Change the programming language of this snippet from Clojure to C# without modifying what it does. | (def n 13)
(sort-by str (range 1 (inc n)))
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Convert this Clojure snippet to C++ and keep its semantics consistent. | (def n 13)
(sort-by str (range 1 (inc n)))
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Translate the given Clojure code snippet into Java without altering its behavior. | (def n 13)
(sort-by str (range 1 (inc n)))
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Change the programming language of this snippet from Clojure to Python without modifying what it does. | (def n 13)
(sort-by str (range 1 (inc n)))
| n=13
print(sorted(range(1,n+1), key=str))
|
Port the following code from Clojure to VB with equivalent syntax and logic. | (def n 13)
(sort-by str (range 1 (inc n)))
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Preserve the algorithm and functionality while converting the code from Clojure to Go. | (def n 13)
(sort-by str (range 1 (inc n)))
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Keep all operations the same but rewrite the snippet in C. | (defun lexicographic-sort (n)
(sort (alexandria:iota n :start 1) #'string<= :key #'write-to-string))
(lexicographic-sort 13)
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Port the provided Common_Lisp code into C# while preserving the original functionality. | (defun lexicographic-sort (n)
(sort (alexandria:iota n :start 1) #'string<= :key #'write-to-string))
(lexicographic-sort 13)
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Maintain the same structure and functionality when rewriting this code in C++. | (defun lexicographic-sort (n)
(sort (alexandria:iota n :start 1) #'string<= :key #'write-to-string))
(lexicographic-sort 13)
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Rewrite the snippet below in Java so it works the same as the original Common_Lisp code. | (defun lexicographic-sort (n)
(sort (alexandria:iota n :start 1) #'string<= :key #'write-to-string))
(lexicographic-sort 13)
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Rewrite this program in Python while keeping its functionality equivalent to the Common_Lisp version. | (defun lexicographic-sort (n)
(sort (alexandria:iota n :start 1) #'string<= :key #'write-to-string))
(lexicographic-sort 13)
| n=13
print(sorted(range(1,n+1), key=str))
|
Port the following code from Common_Lisp to VB with equivalent syntax and logic. | (defun lexicographic-sort (n)
(sort (alexandria:iota n :start 1) #'string<= :key #'write-to-string))
(lexicographic-sort 13)
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Port the provided Common_Lisp code into Go while preserving the original functionality. | (defun lexicographic-sort (n)
(sort (alexandria:iota n :start 1) #'string<= :key #'write-to-string))
(lexicographic-sort 13)
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Convert this Factor snippet to C and keep its semantics consistent. | USING: formatting kernel math.parser math.ranges sequences
sorting ;
IN: rosetta-code.lexicographical-numbers
: lex-order ( n -- seq )
[1,b] [ number>string ] map natural-sort
[ string>number ] map ;
{ 13 21 -22 } [ dup lex-order "%3d: %[%d, %]\n" printf ] each
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Preserve the algorithm and functionality while converting the code from Factor to C#. | USING: formatting kernel math.parser math.ranges sequences
sorting ;
IN: rosetta-code.lexicographical-numbers
: lex-order ( n -- seq )
[1,b] [ number>string ] map natural-sort
[ string>number ] map ;
{ 13 21 -22 } [ dup lex-order "%3d: %[%d, %]\n" printf ] each
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Rewrite this program in C++ while keeping its functionality equivalent to the Factor version. | USING: formatting kernel math.parser math.ranges sequences
sorting ;
IN: rosetta-code.lexicographical-numbers
: lex-order ( n -- seq )
[1,b] [ number>string ] map natural-sort
[ string>number ] map ;
{ 13 21 -22 } [ dup lex-order "%3d: %[%d, %]\n" printf ] each
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Produce a language-to-language conversion: from Factor to Java, same semantics. | USING: formatting kernel math.parser math.ranges sequences
sorting ;
IN: rosetta-code.lexicographical-numbers
: lex-order ( n -- seq )
[1,b] [ number>string ] map natural-sort
[ string>number ] map ;
{ 13 21 -22 } [ dup lex-order "%3d: %[%d, %]\n" printf ] each
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Convert the following code from Factor to Python, ensuring the logic remains intact. | USING: formatting kernel math.parser math.ranges sequences
sorting ;
IN: rosetta-code.lexicographical-numbers
: lex-order ( n -- seq )
[1,b] [ number>string ] map natural-sort
[ string>number ] map ;
{ 13 21 -22 } [ dup lex-order "%3d: %[%d, %]\n" printf ] each
| n=13
print(sorted(range(1,n+1), key=str))
|
Preserve the algorithm and functionality while converting the code from Factor to VB. | USING: formatting kernel math.parser math.ranges sequences
sorting ;
IN: rosetta-code.lexicographical-numbers
: lex-order ( n -- seq )
[1,b] [ number>string ] map natural-sort
[ string>number ] map ;
{ 13 21 -22 } [ dup lex-order "%3d: %[%d, %]\n" printf ] each
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Can you help me rewrite this code in Go instead of Factor, keeping it the same logically? | USING: formatting kernel math.parser math.ranges sequences
sorting ;
IN: rosetta-code.lexicographical-numbers
: lex-order ( n -- seq )
[1,b] [ number>string ] map natural-sort
[ string>number ] map ;
{ 13 21 -22 } [ dup lex-order "%3d: %[%d, %]\n" printf ] each
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Write the same code in C as shown below in Haskell. | import Data.List (sort)
task :: (Ord b, Show b) => [b] -> [b]
task = map snd . sort . map (\i -> (show i, i))
main = print $ task [1 .. 13]
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Keep all operations the same but rewrite the snippet in C#. | import Data.List (sort)
task :: (Ord b, Show b) => [b] -> [b]
task = map snd . sort . map (\i -> (show i, i))
main = print $ task [1 .. 13]
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Produce a functionally identical Java code for the snippet given in Haskell. | import Data.List (sort)
task :: (Ord b, Show b) => [b] -> [b]
task = map snd . sort . map (\i -> (show i, i))
main = print $ task [1 .. 13]
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Convert this Haskell block to Python, preserving its control flow and logic. | import Data.List (sort)
task :: (Ord b, Show b) => [b] -> [b]
task = map snd . sort . map (\i -> (show i, i))
main = print $ task [1 .. 13]
| n=13
print(sorted(range(1,n+1), key=str))
|
Preserve the algorithm and functionality while converting the code from Haskell to VB. | import Data.List (sort)
task :: (Ord b, Show b) => [b] -> [b]
task = map snd . sort . map (\i -> (show i, i))
main = print $ task [1 .. 13]
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Write the same code in Go as shown below in Haskell. | import Data.List (sort)
task :: (Ord b, Show b) => [b] -> [b]
task = map snd . sort . map (\i -> (show i, i))
main = print $ task [1 .. 13]
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Port the provided J code into C while preserving the original functionality. | task=: [: (/: ":"0) 1 + i.
task 13
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Write the same algorithm in C# as shown in this J implementation. | task=: [: (/: ":"0) 1 + i.
task 13
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Preserve the algorithm and functionality while converting the code from J to C++. | task=: [: (/: ":"0) 1 + i.
task 13
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Write the same algorithm in Java as shown in this J implementation. | task=: [: (/: ":"0) 1 + i.
task 13
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Produce a language-to-language conversion: from J to VB, same semantics. | task=: [: (/: ":"0) 1 + i.
task 13
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Port the following code from J to Go with equivalent syntax and logic. | task=: [: (/: ":"0) 1 + i.
task 13
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Write the same code in C as shown below in Julia. | lexorderedsequence(n) = sort(collect(n > 0 ? (1:n) : n:1), lt=(a,b) -> string(a) < string(b))
for i in [0, 5, 13, 21, -32]
println(lexorderedsequence(i))
end
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Produce a language-to-language conversion: from Julia to C#, same semantics. | lexorderedsequence(n) = sort(collect(n > 0 ? (1:n) : n:1), lt=(a,b) -> string(a) < string(b))
for i in [0, 5, 13, 21, -32]
println(lexorderedsequence(i))
end
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Change the programming language of this snippet from Julia to C++ without modifying what it does. | lexorderedsequence(n) = sort(collect(n > 0 ? (1:n) : n:1), lt=(a,b) -> string(a) < string(b))
for i in [0, 5, 13, 21, -32]
println(lexorderedsequence(i))
end
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Convert the following code from Julia to Java, ensuring the logic remains intact. | lexorderedsequence(n) = sort(collect(n > 0 ? (1:n) : n:1), lt=(a,b) -> string(a) < string(b))
for i in [0, 5, 13, 21, -32]
println(lexorderedsequence(i))
end
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Convert this Julia block to Python, preserving its control flow and logic. | lexorderedsequence(n) = sort(collect(n > 0 ? (1:n) : n:1), lt=(a,b) -> string(a) < string(b))
for i in [0, 5, 13, 21, -32]
println(lexorderedsequence(i))
end
| n=13
print(sorted(range(1,n+1), key=str))
|
Generate a VB translation of this Julia snippet without changing its computational steps. | lexorderedsequence(n) = sort(collect(n > 0 ? (1:n) : n:1), lt=(a,b) -> string(a) < string(b))
for i in [0, 5, 13, 21, -32]
println(lexorderedsequence(i))
end
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Preserve the algorithm and functionality while converting the code from Julia to Go. | lexorderedsequence(n) = sort(collect(n > 0 ? (1:n) : n:1), lt=(a,b) -> string(a) < string(b))
for i in [0, 5, 13, 21, -32]
println(lexorderedsequence(i))
end
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Rewrite the snippet below in C so it works the same as the original Lua code. | function lexNums (limit)
local numbers = {}
for i = 1, limit do
table.insert(numbers, tostring(i))
end
table.sort(numbers)
return numbers
end
local numList = lexNums(13)
print(table.concat(numList, " "))
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Generate a C# translation of this Lua snippet without changing its computational steps. | function lexNums (limit)
local numbers = {}
for i = 1, limit do
table.insert(numbers, tostring(i))
end
table.sort(numbers)
return numbers
end
local numList = lexNums(13)
print(table.concat(numList, " "))
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Write the same algorithm in C++ as shown in this Lua implementation. | function lexNums (limit)
local numbers = {}
for i = 1, limit do
table.insert(numbers, tostring(i))
end
table.sort(numbers)
return numbers
end
local numList = lexNums(13)
print(table.concat(numList, " "))
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Keep all operations the same but rewrite the snippet in Java. | function lexNums (limit)
local numbers = {}
for i = 1, limit do
table.insert(numbers, tostring(i))
end
table.sort(numbers)
return numbers
end
local numList = lexNums(13)
print(table.concat(numList, " "))
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Keep all operations the same but rewrite the snippet in Python. | function lexNums (limit)
local numbers = {}
for i = 1, limit do
table.insert(numbers, tostring(i))
end
table.sort(numbers)
return numbers
end
local numList = lexNums(13)
print(table.concat(numList, " "))
| n=13
print(sorted(range(1,n+1), key=str))
|
Produce a functionally identical VB code for the snippet given in Lua. | function lexNums (limit)
local numbers = {}
for i = 1, limit do
table.insert(numbers, tostring(i))
end
table.sort(numbers)
return numbers
end
local numList = lexNums(13)
print(table.concat(numList, " "))
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Keep all operations the same but rewrite the snippet in Go. | function lexNums (limit)
local numbers = {}
for i = 1, limit do
table.insert(numbers, tostring(i))
end
table.sort(numbers)
return numbers
end
local numList = lexNums(13)
print(table.concat(numList, " "))
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Write the same algorithm in C as shown in this Mathematica implementation. | SortBy[Range[13],ToString]
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Write the same code in C# as shown below in Mathematica. | SortBy[Range[13],ToString]
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Keep all operations the same but rewrite the snippet in C++. | SortBy[Range[13],ToString]
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Can you help me rewrite this code in Java instead of Mathematica, keeping it the same logically? | SortBy[Range[13],ToString]
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Keep all operations the same but rewrite the snippet in VB. | SortBy[Range[13],ToString]
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Keep all operations the same but rewrite the snippet in Go. | SortBy[Range[13],ToString]
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Translate the given Nim code snippet into C without altering its behavior. | import algorithm, sequtils
for n in [0, 5, 13, 21, -22]:
let s = if n > 1: toSeq(1..n) else: toSeq(countdown(1, n))
echo s.sortedByIt($it)
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Can you help me rewrite this code in C# instead of Nim, keeping it the same logically? | import algorithm, sequtils
for n in [0, 5, 13, 21, -22]:
let s = if n > 1: toSeq(1..n) else: toSeq(countdown(1, n))
echo s.sortedByIt($it)
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Convert this Nim block to C++, preserving its control flow and logic. | import algorithm, sequtils
for n in [0, 5, 13, 21, -22]:
let s = if n > 1: toSeq(1..n) else: toSeq(countdown(1, n))
echo s.sortedByIt($it)
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Change the programming language of this snippet from Nim to Java without modifying what it does. | import algorithm, sequtils
for n in [0, 5, 13, 21, -22]:
let s = if n > 1: toSeq(1..n) else: toSeq(countdown(1, n))
echo s.sortedByIt($it)
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Transform the following Nim implementation into Python, maintaining the same output and logic. | import algorithm, sequtils
for n in [0, 5, 13, 21, -22]:
let s = if n > 1: toSeq(1..n) else: toSeq(countdown(1, n))
echo s.sortedByIt($it)
| n=13
print(sorted(range(1,n+1), key=str))
|
Port the provided Nim code into VB while preserving the original functionality. | import algorithm, sequtils
for n in [0, 5, 13, 21, -22]:
let s = if n > 1: toSeq(1..n) else: toSeq(countdown(1, n))
echo s.sortedByIt($it)
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Produce a functionally identical Go code for the snippet given in Nim. | import algorithm, sequtils
for n in [0, 5, 13, 21, -22]:
let s = if n > 1: toSeq(1..n) else: toSeq(countdown(1, n))
echo s.sortedByIt($it)
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Generate an equivalent C version of this Perl code. | printf("%4d: [%s]\n", $_, join ',', sort $_ > 0 ? 1..$_ : $_..1) for 13, 21, -22
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Port the following code from Perl to C# with equivalent syntax and logic. | printf("%4d: [%s]\n", $_, join ',', sort $_ > 0 ? 1..$_ : $_..1) for 13, 21, -22
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Convert the following code from Perl to C++, ensuring the logic remains intact. | printf("%4d: [%s]\n", $_, join ',', sort $_ > 0 ? 1..$_ : $_..1) for 13, 21, -22
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Generate an equivalent Java version of this Perl code. | printf("%4d: [%s]\n", $_, join ',', sort $_ > 0 ? 1..$_ : $_..1) for 13, 21, -22
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Write the same code in Python as shown below in Perl. | printf("%4d: [%s]\n", $_, join ',', sort $_ > 0 ? 1..$_ : $_..1) for 13, 21, -22
| n=13
print(sorted(range(1,n+1), key=str))
|
Change the following Perl code into VB without altering its purpose. | printf("%4d: [%s]\n", $_, join ',', sort $_ > 0 ? 1..$_ : $_..1) for 13, 21, -22
| Public Function sortlexicographically(N As Integer)
Dim arrList As Object
Set arrList = CreateObject("System.Collections.ArrayList")
For i = 1 To N
arrList.Add CStr(i)
Next i
arrList.Sort
Dim item As Variant
For Each item In arrList
Debug.Print item & ", ";
Next
End Funct... |
Generate an equivalent Go version of this Perl code. | printf("%4d: [%s]\n", $_, join ',', sort $_ > 0 ? 1..$_ : $_..1) for 13, 21, -22
| package main
import (
"fmt"
"sort"
"strconv"
)
func lexOrder(n int) []int {
first, last, k := 1, n, n
if n < 1 {
first, last, k = n, 1, 2-n
}
strs := make([]string, k)
for i := first; i <= last; i++ {
strs[i-first] = strconv.Itoa(i)
}
sort.Strings(strs)
ints... |
Please provide an equivalent version of this Racket code in C. | #lang racket
(define (lex-sort n) (sort (if (< 0 n) (range 1 (add1 n)) (range n 2))
string<? #:key number->string))
(define (show n) (printf "~a: ~a\n" n (lex-sort n)))
(show 0)
(show 1)
(show 5)
(show 13)
(show 21)
(show -22)
| #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compareStrings(const void *a, const void *b) {
const char **aa = (const char **)a;
const char **bb = (const char **)b;
return strcmp(*aa, *bb);
}
void lexOrder(int n, int *ints) {
char **strs;
int i, first = 1, last =... |
Convert the following code from Racket to C#, ensuring the logic remains intact. | #lang racket
(define (lex-sort n) (sort (if (< 0 n) (range 1 (add1 n)) (range n 2))
string<? #:key number->string))
(define (show n) (printf "~a: ~a\n" n (lex-sort n)))
(show 0)
(show 1)
(show 5)
(show 13)
(show 21)
(show -22)
| using static System.Console;
using static System.Linq.Enumerable;
public class Program
{
public static void Main() {
foreach (int n in new [] { 0, 5, 13, 21, -22 }) WriteLine($"{n}: {string.Join(", ", LexOrder(n))}");
}
public static IEnumerable<int> LexOrder(int n) => (n < 1 ? Range(n, 2 - n) : R... |
Write the same code in C++ as shown below in Racket. | #lang racket
(define (lex-sort n) (sort (if (< 0 n) (range 1 (add1 n)) (range n 2))
string<? #:key number->string))
(define (show n) (printf "~a: ~a\n" n (lex-sort n)))
(show 0)
(show 1)
(show 5)
(show 13)
(show 21)
(show -22)
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
void lexicographical_sort(std::vector<int>& numbers) {
std::vector<std::string> strings(numbers.size());
std::transform(numbers.begin(), numbers.end(), strings.begin(),
[](int i) { return std::to_... |
Rewrite the snippet below in Java so it works the same as the original Racket code. | #lang racket
(define (lex-sort n) (sort (if (< 0 n) (range 1 (add1 n)) (range n 2))
string<? #:key number->string))
(define (show n) (printf "~a: ~a\n" n (lex-sort n)))
(show 0)
(show 1)
(show 5)
(show 13)
(show 21)
(show -22)
| import java.util.List;
import java.util.stream.*;
public class LexicographicalNumbers {
static List<Integer> lexOrder(int n) {
int first = 1, last = n;
if (n < 1) {
first = n;
last = 1;
}
return IntStream.rangeClosed(first, last)
.map... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.