Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Produce a language-to-language conversion: from Mathematica to C, same semantics. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Translate the given Mathematica code snippet into C# without altering its behavior. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Keep all operations the same but rewrite the snippet in C++. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Write the same algorithm in Java as shown in this Mathematica implementation. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Port the provided Mathematica code into Python while preserving the original functionality. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Change the programming language of this snippet from Mathematica to VB without modifying what it does. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Keep all operations the same but rewrite the snippet in Go. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Ensure the translated C code behaves exactly like the original Nim snippet. | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Convert this Nim block to C#, preserving its control flow and logic. | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Can you help me rewrite this code in C++ instead of Nim, keeping it the same logically? | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Keep all operations the same but rewrite the snippet in Java. | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Transform the following Nim implementation into Python, maintaining the same output and logic. | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Rewrite the snippet below in VB so it works the same as the original Nim code. | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Keep all operations the same but rewrite the snippet in Go. | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Write a version of this Pascal function in C with identical behavior. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Convert this Pascal snippet to C# and keep its semantics consistent. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Translate the given Pascal code snippet into C++ without altering its behavior. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Generate a Java translation of this Pascal snippet without changing its computational steps. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Keep all operations the same but rewrite the snippet in Python. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Convert this Pascal snippet to VB and keep its semantics consistent. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Generate a Go translation of this Pascal snippet without changing its computational steps. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Rewrite this program in C while keeping its functionality equivalent to the Perl version. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Maintain the same structure and functionality when rewriting this code in C#. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Produce a functionally identical C++ code for the snippet given in Perl. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Translate the given Perl code snippet into Java without altering its behavior. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Transform the following Perl implementation into Python, maintaining the same output and logic. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Preserve the algorithm and functionality while converting the code from Perl to VB. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Rewrite this program in Go while keeping its functionality equivalent to the Perl version. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Transform the following Racket implementation into C, maintaining the same output and logic. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Convert this Racket block to C#, preserving its control flow and logic. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Produce a language-to-language conversion: from Racket to C++, same semantics. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Convert this Racket snippet to Java and keep its semantics consistent. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Keep all operations the same but rewrite the snippet in Python. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Produce a functionally identical VB code for the snippet given in Racket. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Change the programming language of this snippet from Racket to Go without modifying what it does. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Write the same code in C as shown below in REXX. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Port the following code from REXX to C# with equivalent syntax and logic. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Generate an equivalent C++ version of this REXX code. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Maintain the same structure and functionality when rewriting this code in Java. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Translate this program into Python but keep the logic exactly as in REXX. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Change the following REXX code into VB without altering its purpose. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Change the programming language of this snippet from REXX to Go without modifying what it does. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Keep all operations the same but rewrite the snippet in C. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Translate the given Ruby code snippet into C# without altering its behavior. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Ensure the translated C++ code behaves exactly like the original Ruby snippet. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Transform the following Ruby implementation into Java, maintaining the same output and logic. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Ensure the translated Python code behaves exactly like the original Ruby snippet. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Write a version of this Ruby function in VB with identical behavior. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Rewrite the snippet below in Go so it works the same as the original Ruby code. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Generate an equivalent C version of this Scala code. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Change the following Scala code into C# without altering its purpose. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Maintain the same structure and functionality when rewriting this code in C++. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Transform the following Scala implementation into Java, maintaining the same output and logic. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Ensure the translated Python code behaves exactly like the original Scala snippet. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Rewrite the snippet below in VB so it works the same as the original Scala code. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Convert this Scala block to Go, preserving its control flow and logic. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Write the same code in C as shown below in Swift. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Produce a functionally identical C# code for the snippet given in Swift. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Translate this program into C++ but keep the logic exactly as in Swift. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Change the following Swift code into Java without altering its purpose. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Translate this program into Python but keep the logic exactly as in Swift. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Preserve the algorithm and functionality while converting the code from Swift to VB. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Write the same algorithm in Go as shown in this Swift implementation. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Transform the following Tcl implementation into C, maintaining the same output and logic. |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
|
Ensure the translated C# code behaves exactly like the original Tcl snippet. |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
class Program
{
static void ThreadStart(object item)
{
Thread.Sleep(1000 * (int)item);
Console.WriteLine(item);
}
static void SleepSort(IEnumerable<int> items)
{
foreach (var item in ... |
Convert this Tcl snippet to C++ and keep its semantics consistent. |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... |
Ensure the translated Java code behaves exactly like the original Tcl snippet. |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| import java.util.concurrent.CountDownLatch;
public class SleepSort {
public static void sleepSortAndPrint(int[] nums) {
final CountDownLatch doneSignal = new CountDownLatch(nums.length);
for (final int num : nums) {
new Thread(new Runnable() {
public void run() {
doneSignal.countDown();
try {
... |
Rewrite the snippet below in Python so it works the same as the original Tcl code. |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| from time import sleep
from threading import Timer
def sleepsort(values):
sleepsort.result = []
def add1(x):
sleepsort.result.append(x)
mx = values[0]
for v in values:
if mx < v: mx = v
Timer(v, add1, [v]).start()
sleep(mx+1)
return sleepsort.result
if __name__ == '__ma... |
Change the programming language of this snippet from Tcl to VB without modifying what it does. |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| Imports System.Threading
Module Module1
Sub SleepSort(items As IEnumerable(Of Integer))
For Each item In items
Task.Factory.StartNew(Sub()
Thread.Sleep(1000 * item)
Console.WriteLine(item)
... |
Translate this program into Go but keep the logic exactly as in Tcl. |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| package main
import (
"fmt"
"log"
"os"
"strconv"
"time"
)
func main() {
out := make(chan uint64)
for _, a := range os.Args[1:] {
i, err := strconv.ParseUint(a, 10, 64)
if err != nil {
log.Fatal(err)
}
go func(n uint64) {
time.Sleep(time.Duration(n) * time.Millisecond)
out <- n
}(i)
}
for _... |
Convert the following code from Rust to PHP, ensuring the logic remains intact. | use std::thread;
fn sleepsort<I: Iterator<Item=u32>>(nums: I) {
let threads: Vec<_> = nums.map(|n|
thread::spawn(move || {
thread::sleep_ms(n);
println!("{}", n); })).collect();
for t in threads { t.join(); }
}
fn main() {
sleepsort(std::env::args().skip(1).map(|s| s.parse(... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Port the provided Ada code into PHP while preserving the original functionality. | with Ada.Text_IO;
with Ada.Command_Line; use Ada.Command_Line;
procedure SleepSort is
task type PrintTask (num : Integer);
task body PrintTask is begin
delay Duration (num) / 100.0;
Ada.Text_IO.Put(num'Img);
end PrintTask;
type TaskAcc is access PrintTask;
TaskList : array (1 .. Argument_Coun... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Rewrite this program in PHP while keeping its functionality equivalent to the AutoHotKey version. | items := [1,5,4,9,3,4]
for i, v in SleepSort(items)
result .= v ", "
MsgBox, 262144, , % result := "[" Trim(result, ", ") "]"
return
SleepSort(items){
global Sorted := []
slp := 50
for i, v in items{
fn := Func("PushFn").Bind(v)
SetTimer, %fn%, % v * -slp
}
Sleep % Max(items*) *... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Preserve the algorithm and functionality while converting the code from BBC_Basic to PHP. | INSTALL @lib$+"TIMERLIB"
DIM test%(9)
test%() = 4, 65, 2, 31, 0, 99, 2, 83, 782, 1
FOR i% = 0 TO DIM(test%(),1)
p% = EVAL("!^PROCtask" + STR$(i%))
tid% = FN_ontimer(100 + test%(i%), p%, 0)
NEXT
REPEAT
WAIT 0
UNTIL FALSE
... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Write a version of this Clojure function in PHP with identical behavior. | (ns sleepsort.core
(require [clojure.core.async :as async :refer [chan go <! <!! >! timeout]]))
(defn sleep-sort [l]
(let [c (chan (count l))]
(doseq [i l]
(go (<! (timeout (* 1000 i)))
(>! c i)))
(<!! (async/into [] (async/take (count l) c)))))
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Preserve the algorithm and functionality while converting the code from Common_Lisp to PHP. | (defun sleeprint(n)
(sleep (/ n 10))
(format t "~a~%" n))
(loop for arg in (cdr sb-ext:*posix-argv*) doing
(sb-thread:make-thread (lambda() (sleeprint (parse-integer arg)))))
(loop while (not (null (cdr (sb-thread:list-all-threads)))))
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Generate an equivalent PHP version of this D code. | void main(string[] args)
{
import core.thread, std;
args.drop(1).map!(a => a.to!uint).parallel.each!((a)
{
Thread.sleep(dur!"msecs"(a));
write(a, " ");
});
}
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Please provide an equivalent version of this Delphi code in PHP. | program SleepSortDemo;
uses
Windows, SysUtils, Classes;
type
TSleepThread = class(TThread)
private
FValue: Integer;
FLock: PRTLCriticalSection;
protected
constructor Create(AValue: Integer; ALock: PRTLCriticalSection);
procedure Execute; override;
end;
constructor TSleepThread.Create(AVal... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Generate a PHP translation of this Elixir snippet without changing its computational steps. | defmodule Sort do
def sleep_sort(args) do
Enum.each(args, fn(arg) -> Process.send_after(self, arg, 5 * arg) end)
loop(length(args))
end
defp loop(0), do: :ok
defp loop(n) do
receive do
num -> IO.puts num
loop(n - 1)
end
end
end
Sort.sleep_sort [2, 4, 8, 12, 35, 2, 12... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Preserve the algorithm and functionality while converting the code from Erlang to PHP. | #!/usr/bin/env escript
main(Args) ->
lists:foreach(fun(Arg) ->
timer:send_after(5 * list_to_integer(Arg), self(), Arg)
end, Args),
loop(length(Args)).
loop(0) ->
ok;
loop(N) ->
receive
Num ->
io:format("~s~n", [Num]),
loop(N... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Keep all operations the same but rewrite the snippet in PHP. | let sleepSort (values: seq<int>) =
values
|> Seq.map (fun x -> async {
do! Async.Sleep x
Console.WriteLine x
})
|> Async.Parallel
|> Async.Ignore
|> Async.RunSynchronously
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Produce a functionally identical PHP code for the snippet given in Factor. | USING: threads calendar concurrency.combinators ;
: sleep-sort ( seq -- ) [ dup seconds sleep . ] parallel-each ;
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Change the following Fortran code into PHP without altering its purpose. | program sleepSort
use omp_lib
implicit none
integer::nArgs,myid,i,stat
integer,allocatable::intArg(:)
character(len=5)::arg
nArgs=command_argument_count()
if(nArgs==0)stop ' : No argument is given
allocate(intArg(nArgs))
do i=1,nArgs
call get_command_argument(i, arg)
... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Generate a PHP translation of this Groovy snippet without changing its computational steps. | @Grab(group = 'org.codehaus.gpars', module = 'gpars', version = '1.2.1')
import groovyx.gpars.GParsPool
GParsPool.withPool args.size(), {
args.eachParallel {
sleep(it.toInteger() * 10)
println it
}
}
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Transform the following Haskell implementation into PHP, maintaining the same output and logic. | import System.Environment
import Control.Concurrent
import Control.Monad
sleepSort :: [Int] -> IO ()
sleepSort values = do
chan <- newChan
forM_ values (\time -> forkIO (threadDelay (50000 * time) >> writeChan chan time))
forM_ values (\_ -> readChan chan >>= print)
main :: IO ()
main = getArg... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Port the provided J code into PHP while preserving the original functionality. | scheduledumb=: {{
id=:'dumb',":x:6!:9''
wd 'pc ',id
(t)=: u {{u y[erase n}} t=. id,'_timer'
wd 'ptimer ',":n p.y
}}
ssort=: {{
R=: ''
poly=. 1,>./ y
poly{{ y{{R=:R,m[y}}scheduledumb m y}}"0 y
{{echo R}} scheduledumb poly"0 >:>./ y
EMPTY
}}
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Port the following code from Julia to PHP with equivalent syntax and logic. | function sleepsort(V::Vector{T}) where {T <: Real}
U = Vector{T}()
sizehint!(U, length(V))
@sync for v in V
@async begin
sleep(abs(v))
(v < 0 ? pushfirst! : push!)(U, v)
end
end
return U
end
v = rand(-10:10, 10)
println("
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Translate the given Lua code snippet into PHP without altering its behavior. | function sleeprint(n)
local t0 = os.time()
while os.time() - t0 <= n do
coroutine.yield(false)
end
print(n)
return true
end
coroutines = {}
for i=1, #arg do
wrapped = coroutine.wrap(sleeprint)
table.insert(coroutines, wrapped)
wrapped(tonumber(arg[i]))
end
done = false
while not done do
done = t... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Convert this Mathematica snippet to PHP and keep its semantics consistent. | SleepSort = RunScheduledTask[Print@#, {#, 1}] & /@ # &;
SleepSort@{1, 9, 8, 7, 6, 5, 3, 4, 5, 2, 0};
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Produce a language-to-language conversion: from Nim to PHP, same semantics. | import os, strutils
proc single(n: int) =
sleep n
echo n
proc main =
var thr = newSeq[TThread[int]](paramCount())
for i,c in commandLineParams():
thr[i].createThread(single, c.parseInt)
thr.joinThreads
main()
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Generate a PHP translation of this Pascal snippet without changing its computational steps. | program sleepsort;
uses
cthreads,
SysUtils;
const
HiLimit = 40;
type
tCombineForOneThread = record
cft_count : Uint64;
cft_ThreadID: NativeUint;
cft_ThreadHandle: NativeUint;
end;
pThreadBlock = ^tCombineForOneThread;
var
SortIdx : array of INteger;
ThreadBlocks : array of t... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Convert this Perl snippet to PHP and keep its semantics consistent. | 1 while ($_ = shift and @ARGV and !fork);
sleep $_;
print "$_\n";
wait;
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Translate the given Racket code snippet into PHP without altering its behavior. | #lang racket
(define (sleep-sort lst)
(define done (make-channel))
(for ([elem lst])
(thread
(λ ()
(sleep elem)
(channel-put done elem))))
(for/list ([_ (length lst)])
(channel-get done)))
(sleep-sort '(5 8 2 7 9 10 5))
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Generate a PHP translation of this REXX snippet without changing its computational steps. |
options replace format comments java crossref symbols nobinary
import java.util.concurrent.CountDownLatch
-- =============================================================================
class RSortingSleepsort
properties constant private
dflt = '-6 3 1 4 5 2 3 -7 1 6 001 3 -9 2 5 -009 -8 4 6 1 9 8 7 6 5 -7 3 4... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Translate the given Ruby code snippet into PHP without altering its behavior. | require 'thread'
nums = ARGV.collect(&:to_i)
sorted = []
mutex = Mutex.new
threads = nums.collect do |n|
Thread.new do
sleep 0.01 * n
mutex.synchronize {sorted << n}
end
end
threads.each {|t| t.join}
p sorted
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Keep all operations the same but rewrite the snippet in PHP. |
import kotlin.concurrent.thread
fun sleepSort(list: List<Int>, interval: Long) {
print("Sorted : ")
for (i in list) {
thread {
Thread.sleep(i * interval)
print("$i ")
}
}
thread {
Thread.sleep ((1 + list.max()!!) * interval)
println()
}
}
... | <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Write the same algorithm in PHP as shown in this Swift implementation. | import Foundation
for i in [5, 2, 4, 6, 1, 7, 20, 14] {
let time = dispatch_time(DISPATCH_TIME_NOW,
Int64(i * Int(NSEC_PER_SEC)))
dispatch_after(time, dispatch_get_main_queue()) {
print(i)
}
}
CFRunLoopRun()
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Can you help me rewrite this code in PHP instead of Tcl, keeping it the same logically? |
set count 0
proc process val {
puts $val
incr ::count
}
foreach val $argv {
after [expr {$val * 10}] [list process $val]
}
while {$count < $argc} {
vwait count
}
| <?php
$buffer = 1;
$pids = [];
for ($i = 1; $i < $argc; $i++) {
$pid = pcntl_fork();
if ($pid < 0) {
die("failed to start child process");
}
if ($pid === 0) {
sleep($argv[$i] + $buffer);
echo $argv[$i] . "\n";
exit();
}
$pids[] = $pid;
}
foreach ($pids as... |
Generate a Rust translation of this C snippet without changing its computational steps. | >>>>>,----------[++++++++
++[->+>+<<]>+>[-<<+>>]+++
+++++[-<------>]>>+>,----
------<<+[->>>>>+<<<<<]>>
]>>>[<<<<[<<<[->>+<<[->+>
[-]<<]]>[-<+>]>[-<<<.>>>>
->>>>>[>>>>>]<-<<<<[<<<<<
]+<]<<<<]>>>>>[>>>>>]<]
| use std::thread;
fn sleepsort<I: Iterator<Item=u32>>(nums: I) {
let threads: Vec<_> = nums.map(|n|
thread::spawn(move || {
thread::sleep_ms(n);
println!("{}", n); })).collect();
for t in threads { t.join(); }
}
fn main() {
sleepsort(std::env::args().skip(1).map(|s| s.parse(... |
Translate this program into Rust but keep the logic exactly as in C++. | #include <chrono>
#include <iostream>
#include <thread>
#include <vector>
int main(int argc, char* argv[]) {
std::vector<std::thread> threads;
for (int i = 1; i < argc; ++i) {
threads.emplace_back([i, &argv]() {
int arg = std::stoi(argv[i]);
std::this_thread::sleep_for(std::chrono::seconds(arg));
... | use std::thread;
fn sleepsort<I: Iterator<Item=u32>>(nums: I) {
let threads: Vec<_> = nums.map(|n|
thread::spawn(move || {
thread::sleep_ms(n);
println!("{}", n); })).collect();
for t in threads { t.join(); }
}
fn main() {
sleepsort(std::env::args().skip(1).map(|s| s.parse(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.