Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Can you help me rewrite this code in C# instead of Tcl, keeping it the same logically? | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| using System;
using System.Collections.Generic;
namespace PriorityQueueExample
{
class Program
{
static void Main(string[] args)
{
var p = new PriorityQueue<string, int>();
p.Enqueue("Clear drains", 3);
p.Enqueue("Feed cat", 4);
p.Enqueue("Make tea", 5);
p.Enqueue("Solve RC tasks", 1);
p.En... |
Convert this Tcl snippet to C++ and keep its semantics consistent. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| #include <iostream>
#include <string>
#include <queue>
#include <utility>
int main() {
std::priority_queue<std::pair<int, std::string> > pq;
pq.push(std::make_pair(3, "Clear drains"));
pq.push(std::make_pair(4, "Feed cat"));
pq.push(std::make_pair(5, "Make tea"));
pq.push(std::make_pair(1, "Solve RC tasks"))... |
Produce a language-to-language conversion: from Tcl to C++, same semantics. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| #include <iostream>
#include <string>
#include <queue>
#include <utility>
int main() {
std::priority_queue<std::pair<int, std::string> > pq;
pq.push(std::make_pair(3, "Clear drains"));
pq.push(std::make_pair(4, "Feed cat"));
pq.push(std::make_pair(5, "Make tea"));
pq.push(std::make_pair(1, "Solve RC tasks"))... |
Ensure the translated Java code behaves exactly like the original Tcl snippet. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| import java.util.PriorityQueue;
class Task implements Comparable<Task> {
final int priority;
final String name;
public Task(int p, String n) {
priority = p;
name = n;
}
public String toString() {
return priority + ", " + name;
}
public int compareTo(Task other) {
... |
Produce a functionally identical Java code for the snippet given in Tcl. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| import java.util.PriorityQueue;
class Task implements Comparable<Task> {
final int priority;
final String name;
public Task(int p, String n) {
priority = p;
name = n;
}
public String toString() {
return priority + ", " + name;
}
public int compareTo(Task other) {
... |
Write a version of this Tcl function in Python with identical behavior. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| >>> import queue
>>> pq = queue.PriorityQueue()
>>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")):
pq.put(item)
>>> while not pq.empty():
print(pq.get_nowait())
(1, 'Solve RC tasks')
(2, 'Tax return')
(3, 'Clear drains')
(4, 'Feed cat')
(5, 'Ma... |
Write a version of this Tcl function in Python with identical behavior. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| >>> import queue
>>> pq = queue.PriorityQueue()
>>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")):
pq.put(item)
>>> while not pq.empty():
print(pq.get_nowait())
(1, 'Solve RC tasks')
(2, 'Tax return')
(3, 'Clear drains')
(4, 'Feed cat')
(5, 'Ma... |
Change the programming language of this snippet from Tcl to VB without modifying what it does. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| Type Tuple
Priority As Integer
Data As String
End Type
Dim a() As Tuple
Dim n As Integer
Private Function Left(i As Integer) As Integer
Left = 2 * i + 1
End Function
Private Function Right(i As Integer) As Integer
Right = 2 * i + 2
End Function
Private Function Parent(i As Integer) As Integer
Paren... |
Change the following Tcl code into VB without altering its purpose. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| Type Tuple
Priority As Integer
Data As String
End Type
Dim a() As Tuple
Dim n As Integer
Private Function Left(i As Integer) As Integer
Left = 2 * i + 1
End Function
Private Function Right(i As Integer) As Integer
Right = 2 * i + 2
End Function
Private Function Parent(i As Integer) As Integer
Paren... |
Keep all operations the same but rewrite the snippet in Go. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| package main
import (
"fmt"
"container/heap"
)
type Task struct {
priority int
name string
}
type TaskPQ []Task
func (self TaskPQ) Len() int { return len(self) }
func (self TaskPQ) Less(i, j int) bool {
return self[i].priority < self[j].priority
}
func (self TaskPQ) Swap(i, j int) { self[i],... |
Rewrite the snippet below in Go so it works the same as the original Tcl code. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| package main
import (
"fmt"
"container/heap"
)
type Task struct {
priority int
name string
}
type TaskPQ []Task
func (self TaskPQ) Len() int { return len(self) }
func (self TaskPQ) Less(i, j int) bool {
return self[i].priority < self[j].priority
}
func (self TaskPQ) Swap(i, j int) { self[i],... |
Rewrite the snippet below in PHP so it works the same as the original Rust code. | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Ensure the translated PHP code behaves exactly like the original Rust snippet. | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Keep all operations the same but rewrite the snippet in PHP. | with Ada.Containers.Synchronized_Queue_Interfaces;
with Ada.Containers.Unbounded_Priority_Queues;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Priority_Queues is
use Ada.Containers;
use Ada.Strings.Unbounded;
type Queue_Element is record
Priority : Natural;
Content : Unbounded_String;
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Rewrite the snippet below in PHP so it works the same as the original Ada code. | with Ada.Containers.Synchronized_Queue_Interfaces;
with Ada.Containers.Unbounded_Priority_Queues;
with Ada.Strings.Unbounded;
with Ada.Text_IO;
procedure Priority_Queues is
use Ada.Containers;
use Ada.Strings.Unbounded;
type Queue_Element is record
Priority : Natural;
Content : Unbounded_String;
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. |
PQ_TopItem(Queue,Task:=""){
TopPriority := PQ_TopPriority(Queue)
for T, P in Queue
if (P = TopPriority) && ((T=Task)||!Task)
return T , Queue.Remove(T)
return 0
}
PQ_AddTask(Queue,Task,Priority){
for T, P in Queue
if (T=Task) || !(Priority && Task)
return 0
return Task, Queue[Task] := Priority... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Generate an equivalent PHP version of this AutoHotKey code. |
PQ_TopItem(Queue,Task:=""){
TopPriority := PQ_TopPriority(Queue)
for T, P in Queue
if (P = TopPriority) && ((T=Task)||!Task)
return T , Queue.Remove(T)
return 0
}
PQ_AddTask(Queue,Task,Priority){
for T, P in Queue
if (T=Task) || !(Priority && Task)
return 0
return Task, Queue[Task] := Priority... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Can you help me rewrite this code in PHP instead of Clojure, keeping it the same logically? | user=> (use 'clojure.data.priority-map)
user=> (def p (priority-map "Clear drains" 3, "Feed cat" 4, "Make tea" 5, "Solve RC tasks" 1))
#'user/p
user=> p
{"Solve RC tasks" 1, "Clear drains" 3, "Feed cat" 4, "Make tea" 5}
user=> (assoc p "Tax return" 2)
{"Solve RC tasks" 1, "Tax return" 2, "Clear drains" 3, "Feed cat... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Convert this Clojure snippet to PHP and keep its semantics consistent. | user=> (use 'clojure.data.priority-map)
user=> (def p (priority-map "Clear drains" 3, "Feed cat" 4, "Make tea" 5, "Solve RC tasks" 1))
#'user/p
user=> p
{"Solve RC tasks" 1, "Clear drains" 3, "Feed cat" 4, "Make tea" 5}
user=> (assoc p "Tax return" 2)
{"Solve RC tasks" 1, "Tax return" 2, "Clear drains" 3, "Feed cat... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Convert this Common_Lisp snippet to PHP and keep its semantics consistent. |
(defun make-pq (alist)
(sort (copy-alist alist) (lambda (a b) (< (car a) (car b)))))
(define-modify-macro insert-pq (pair)
(lambda (pq pair) (sort-alist (cons pair pq))))
(define-modify-macro remove-pq-aux () cdr)
(defmacro remove-pq (pq)
`(let ((aux (copy-alist ,pq)))
(REMOVE-PQ-AUX... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Port the following code from Common_Lisp to PHP with equivalent syntax and logic. |
(defun make-pq (alist)
(sort (copy-alist alist) (lambda (a b) (< (car a) (car b)))))
(define-modify-macro insert-pq (pair)
(lambda (pq pair) (sort-alist (cons pair pq))))
(define-modify-macro remove-pq-aux () cdr)
(defmacro remove-pq (pq)
`(let ((aux (copy-alist ,pq)))
(REMOVE-PQ-AUX... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Preserve the algorithm and functionality while converting the code from D to PHP. | import std.stdio, std.container, std.array, std.typecons;
void main() {
alias tuple T;
auto heap = heapify([T(3, "Clear drains"),
T(4, "Feed cat"),
T(5, "Make tea"),
T(1, "Solve RC tasks"),
T(2, "Tax return")]);... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Produce a functionally identical PHP code for the snippet given in D. | import std.stdio, std.container, std.array, std.typecons;
void main() {
alias tuple T;
auto heap = heapify([T(3, "Clear drains"),
T(4, "Feed cat"),
T(5, "Make tea"),
T(1, "Solve RC tasks"),
T(2, "Tax return")]);... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Transform the following Delphi implementation into PHP, maintaining the same output and logic. | program Priority_queue;
uses
System.SysUtils, Boost.Generics.Collection;
var
Queue: TPriorityQueue<String>;
begin
Queue := TPriorityQueue<String>.Create(['Clear drains', 'Feed cat',
'Make tea', 'Solve RC tasks', 'Tax return'], [3, 4, 5, 1, 2]);
while not Queue.IsEmpty do
with Queue.DequeueEx do
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Convert this Delphi block to PHP, preserving its control flow and logic. | program Priority_queue;
uses
System.SysUtils, Boost.Generics.Collection;
var
Queue: TPriorityQueue<String>;
begin
Queue := TPriorityQueue<String>.Create(['Clear drains', 'Feed cat',
'Make tea', 'Solve RC tasks', 'Tax return'], [3, 4, 5, 1, 2]);
while not Queue.IsEmpty do
with Queue.DequeueEx do
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Rewrite this program in PHP while keeping its functionality equivalent to the Elixir version. | defmodule Priority do
def create, do: :gb_trees.empty
def insert( element, priority, queue ), do: :gb_trees.enter( priority, element, queue )
def peek( queue ) do
{_priority, element, _new_queue} = :gb_trees.take_smallest( queue )
element
end
def task do
items = [{3, "Clear drains"}, {4, "F... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Produce a functionally identical PHP code for the snippet given in Elixir. | defmodule Priority do
def create, do: :gb_trees.empty
def insert( element, priority, queue ), do: :gb_trees.enter( priority, element, queue )
def peek( queue ) do
{_priority, element, _new_queue} = :gb_trees.take_smallest( queue )
element
end
def task do
items = [{3, "Clear drains"}, {4, "F... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Preserve the algorithm and functionality while converting the code from Erlang to PHP. | -module( priority_queue ).
-export( [create/0, insert/3, peek/1, task/0, top/1] ).
create() -> gb_trees:empty().
insert( Element, Priority, Queue ) -> gb_trees:enter( Priority, Element, Queue ).
peek( Queue ) ->
{_Priority, Element, _New_queue} = gb_trees:take_smallest( Queue ),
Element.
task() ->
Items = [{... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Translate the given Erlang code snippet into PHP without altering its behavior. | -module( priority_queue ).
-export( [create/0, insert/3, peek/1, task/0, top/1] ).
create() -> gb_trees:empty().
insert( Element, Priority, Queue ) -> gb_trees:enter( Priority, Element, Queue ).
peek( Queue ) ->
{_Priority, Element, _New_queue} = gb_trees:take_smallest( Queue ),
Element.
task() ->
Items = [{... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Keep all operations the same but rewrite the snippet in PHP. | [<RequireQualifiedAccess>]
module PriorityQ =
type 'a treeElement = struct val k:uint32 val v:'a new(k,v) = { k=k;v=v } end
type 'a tree = Node of uint32 * 'a treeElement * 'a tree list
type 'a heap = 'a tree list
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
[<NoEquali... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Ensure the translated PHP code behaves exactly like the original F# snippet. | [<RequireQualifiedAccess>]
module PriorityQ =
type 'a treeElement = struct val k:uint32 val v:'a new(k,v) = { k=k;v=v } end
type 'a tree = Node of uint32 * 'a treeElement * 'a tree list
type 'a heap = 'a tree list
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
[<NoEquali... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Convert this Factor block to PHP, preserving its control flow and logic. | <min-heap> [ {
{ 3 "Clear drains" }
{ 4 "Feed cat" }
{ 5 "Make tea" }
{ 1 "Solve RC tasks" }
{ 2 "Tax return" }
} swap heap-push-all
] [
[ print ] slurp-heap
] bi
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Rewrite the snippet below in PHP so it works the same as the original Factor code. | <min-heap> [ {
{ 3 "Clear drains" }
{ 4 "Feed cat" }
{ 5 "Make tea" }
{ 1 "Solve RC tasks" }
{ 2 "Tax return" }
} swap heap-push-all
] [
[ print ] slurp-heap
] bi
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Ensure the translated PHP code behaves exactly like the original Forth snippet. | #! /usr/bin/gforth
10 CONSTANT INITIAL-CAPACITY
: new-queue
2 INITIAL-CAPACITY 3 * + cells allocate throw
INITIAL-CAPACITY over !
0 over cell + !
;
: delete-queue
free throw
;
: queue-capacity
@
;
: queue-size
cell + @
;
: resize-queue
dup queue-capacity 2 * dup >r 3 * 2 + ce... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. | #! /usr/bin/gforth
10 CONSTANT INITIAL-CAPACITY
: new-queue
2 INITIAL-CAPACITY 3 * + cells allocate throw
INITIAL-CAPACITY over !
0 over cell + !
;
: delete-queue
free throw
;
: queue-capacity
@
;
: queue-size
cell + @
;
: resize-queue
dup queue-capacity 2 * dup >r 3 * 2 + ce... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Write the same algorithm in PHP as shown in this Fortran implementation. | module priority_queue_mod
implicit none
type node
character (len=100) :: task
integer :: priority
end type
type queue
type(node), allocatable :: buf(:)
integer :: n = 0
contains
procedure :: top
procedure :: enqueue
procedure :: siftdown
end type
co... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Preserve the algorithm and functionality while converting the code from Fortran to PHP. | module priority_queue_mod
implicit none
type node
character (len=100) :: task
integer :: priority
end type
type queue
type(node), allocatable :: buf(:)
integer :: n = 0
contains
procedure :: top
procedure :: enqueue
procedure :: siftdown
end type
co... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Produce a language-to-language conversion: from Groovy to PHP, same semantics. | import groovy.transform.Canonical
@Canonical
class Task implements Comparable<Task> {
int priority
String name
int compareTo(Task o) { priority <=> o?.priority }
}
new PriorityQueue<Task>().with {
add new Task(priority: 3, name: 'Clear drains')
add new Task(priority: 4, name: 'Feed cat')
add n... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Produce a language-to-language conversion: from Groovy to PHP, same semantics. | import groovy.transform.Canonical
@Canonical
class Task implements Comparable<Task> {
int priority
String name
int compareTo(Task o) { priority <=> o?.priority }
}
new PriorityQueue<Task>().with {
add new Task(priority: 3, name: 'Clear drains')
add new Task(priority: 4, name: 'Feed cat')
add n... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Ensure the translated PHP code behaves exactly like the original Haskell snippet. | import Data.PQueue.Prio.Min
main = print (toList (fromList [(3, "Clear drains"),(4, "Feed cat"),(5, "Make tea"),(1, "Solve RC tasks"), (2, "Tax return")]))
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Change the programming language of this snippet from Haskell to PHP without modifying what it does. | import Data.PQueue.Prio.Min
main = print (toList (fromList [(3, "Clear drains"),(4, "Feed cat"),(5, "Make tea"),(1, "Solve RC tasks"), (2, "Tax return")]))
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Keep all operations the same but rewrite the snippet in PHP. | coclass 'priorityQueue'
PRI=: ''
QUE=: ''
insert=:4 :0
p=. PRI,x
q=. QUE,y
assert. p -:&$ q
assert. 1 = #$q
ord=: \: p
QUE=: ord { q
PRI=: ord { p
i.0 0
)
topN=:3 :0
assert y<:#PRI
r=. y{.QUE
PRI=: y}.PRI
QUE=: y}.QUE
r
)
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Please provide an equivalent version of this J code in PHP. | coclass 'priorityQueue'
PRI=: ''
QUE=: ''
insert=:4 :0
p=. PRI,x
q=. QUE,y
assert. p -:&$ q
assert. 1 = #$q
ord=: \: p
QUE=: ord { q
PRI=: ord { p
i.0 0
)
topN=:3 :0
assert y<:#PRI
r=. y{.QUE
PRI=: y}.PRI
QUE=: y}.QUE
r
)
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Keep all operations the same but rewrite the snippet in PHP. | using Base.Collections
test = ["Clear drains" 3;
"Feed cat" 4;
"Make tea" 5;
"Solve RC tasks" 1;
"Tax return" 2]
task = PriorityQueue(Base.Order.Reverse)
for i in 1:size(test)[1]
enqueue!(task, test[i,1], test[i,2])
end
println("Tasks, completed according to priority:")
while !ise... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Change the programming language of this snippet from Julia to PHP without modifying what it does. | using Base.Collections
test = ["Clear drains" 3;
"Feed cat" 4;
"Make tea" 5;
"Solve RC tasks" 1;
"Tax return" 2]
task = PriorityQueue(Base.Order.Reverse)
for i in 1:size(test)[1]
enqueue!(task, test[i,1], test[i,2])
end
println("Tasks, completed according to priority:")
while !ise... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Translate this program into PHP but keep the logic exactly as in Lua. | PriorityQueue = {
__index = {
put = function(self, p, v)
local q = self[p]
if not q then
q = {first = 1, last = 0}
self[p] = q
end
q.last = q.last + 1
q[q.last] = v
end,
pop = function(self)
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Write the same algorithm in PHP as shown in this Lua implementation. | PriorityQueue = {
__index = {
put = function(self, p, v)
local q = self[p]
if not q then
q = {first = 1, last = 0}
self[p] = q
end
q.last = q.last + 1
q[q.last] = v
end,
pop = function(self)
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Please provide an equivalent version of this Mathematica code in PHP. | push = Function[{queue, priority, item},
queue = SortBy[Append[queue, {priority, item}], First], HoldFirst];
pop = Function[queue,
If[Length@queue == 0, Null,
With[{item = queue[[-1, 2]]}, queue = Most@queue; item]],
HoldFirst];
peek = Function[queue,
If[Length@queue == 0, Null, Max[queue[[All, 1]]... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Convert this Mathematica block to PHP, preserving its control flow and logic. | push = Function[{queue, priority, item},
queue = SortBy[Append[queue, {priority, item}], First], HoldFirst];
pop = Function[queue,
If[Length@queue == 0, Null,
With[{item = queue[[-1, 2]]}, queue = Most@queue; item]],
HoldFirst];
peek = Function[queue,
If[Length@queue == 0, Null, Max[queue[[All, 1]]... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Port the provided Nim code into PHP while preserving the original functionality. | type
PriElem[T] = tuple
data: T
pri: int
PriQueue[T] = object
buf: seq[PriElem[T]]
count: int
proc initPriQueue[T](initialSize = 4): PriQueue[T] =
result.buf.newSeq(initialSize)
result.buf.setLen(1)
result.count = 0
proc add[T](q: var PriQueue[T], data: T, pri: int) =
var n = q.buf.len
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Ensure the translated PHP code behaves exactly like the original Nim snippet. | type
PriElem[T] = tuple
data: T
pri: int
PriQueue[T] = object
buf: seq[PriElem[T]]
count: int
proc initPriQueue[T](initialSize = 4): PriQueue[T] =
result.buf.newSeq(initialSize)
result.buf.setLen(1)
result.count = 0
proc add[T](q: var PriQueue[T], data: T, pri: int) =
var n = q.buf.len
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Preserve the algorithm and functionality while converting the code from OCaml to PHP. | module PQ = Base.PriorityQueue
let () =
let tasks = [
3, "Clear drains";
4, "Feed cat";
5, "Make tea";
1, "Solve RC tasks";
2, "Tax return";
] in
let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in
List.iter (PQ.add pq) tasks;
while not (PQ.is_empty pq) do
let _, task = P... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Can you help me rewrite this code in PHP instead of OCaml, keeping it the same logically? | module PQ = Base.PriorityQueue
let () =
let tasks = [
3, "Clear drains";
4, "Feed cat";
5, "Make tea";
1, "Solve RC tasks";
2, "Tax return";
] in
let pq = PQ.make (fun (prio1, _) (prio2, _) -> prio1 > prio2) in
List.iter (PQ.add pq) tasks;
while not (PQ.is_empty pq) do
let _, task = P... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Convert this Pascal block to PHP, preserving its control flow and logic. | program PriorityQueueTest;
uses Classes;
Type
TItem = record
Priority:Integer;
Value:string;
end;
PItem = ^TItem;
TPriorityQueue = class(Tlist)
procedure Push(Priority:Integer;Value:string);
procedure SortPriority();
function Pop():String;
function Empty:Boolean;
end;
procedure TPriorityQueue.Pu... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Translate this program into PHP but keep the logic exactly as in Pascal. | program PriorityQueueTest;
uses Classes;
Type
TItem = record
Priority:Integer;
Value:string;
end;
PItem = ^TItem;
TPriorityQueue = class(Tlist)
procedure Push(Priority:Integer;Value:string);
procedure SortPriority();
function Pop():String;
function Empty:Boolean;
end;
procedure TPriorityQueue.Pu... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Port the following code from Perl to PHP with equivalent syntax and logic. | use strict;
use warnings;
use feature 'say';
use Heap::Priority;
my $h = Heap::Priority->new;
$h->highest_first();
$h->add(@$_) for ["Clear drains", 3],
["Feed cat", 4],
["Make tea", 5],
["Solve RC tasks", 1],
["Tax return", 2];
say while ($_ = $h->pop);
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Generate an equivalent PHP version of this Perl code. | use strict;
use warnings;
use feature 'say';
use Heap::Priority;
my $h = Heap::Priority->new;
$h->highest_first();
$h->add(@$_) for ["Clear drains", 3],
["Feed cat", 4],
["Make tea", 5],
["Solve RC tasks", 1],
["Tax return", 2];
say while ($_ = $h->pop);
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. | PriorityQueue <- function() {
keys <- values <- NULL
insert <- function(key, value) {
ord <- findInterval(key, keys)
keys <<- append(keys, key, ord)
values <<- append(values, value, ord)
}
pop <- function() {
head <- list(key=keys[1],value=values[[1]])
values <<- values[-1]
keys <<- keys... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Port the provided R code into PHP while preserving the original functionality. | PriorityQueue <- function() {
keys <- values <- NULL
insert <- function(key, value) {
ord <- findInterval(key, keys)
keys <<- append(keys, key, ord)
values <<- append(values, value, ord)
}
pop <- function() {
head <- list(key=keys[1],value=values[[1]])
values <<- values[-1]
keys <<- keys... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Rewrite the snippet below in PHP so it works the same as the original Racket code. | #lang racket
(require data/heap)
(define pq (make-heap (λ(x y) (<= (second x) (second y)))))
(define (insert! x pri)
(heap-add! pq (list pri x)))
(define (remove-min!)
(begin0
(first (heap-min pq))
(heap-remove-min! pq)))
(insert! 3 "Clear drains")
(insert! 4 "Feed cat")
(insert! 5 "Make tea")
(insert... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Please provide an equivalent version of this Racket code in PHP. | #lang racket
(require data/heap)
(define pq (make-heap (λ(x y) (<= (second x) (second y)))))
(define (insert! x pri)
(heap-add! pq (list pri x)))
(define (remove-min!)
(begin0
(first (heap-min pq))
(heap-remove-min! pq)))
(insert! 3 "Clear drains")
(insert! 4 "Feed cat")
(insert! 5 "Make tea")
(insert... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. |
#=0; @.=
say '══════ inserting tasks.'; call .ins 3 "Clear drains"
call .ins 4 "Feed cat"
call .ins 5 "Make tea"
call .ins 1 "Solve RC tasks"
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Generate an equivalent PHP version of this REXX code. |
#=0; @.=
say '══════ inserting tasks.'; call .ins 3 "Clear drains"
call .ins 4 "Feed cat"
call .ins 5 "Make tea"
call .ins 1 "Solve RC tasks"
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Produce a functionally identical PHP code for the snippet given in Ruby. | class PriorityQueueNaive
def initialize(data=nil)
@q = Hash.new {|h, k| h[k] = []}
data.each {|priority, item| @q[priority] << item} if data
@priorities = @q.keys.sort
end
def push(priority, item)
@q[priority] << item
@priorities = @q.keys.sort
end
def pop
p = @priorities[0]
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Translate the given Ruby code snippet into PHP without altering its behavior. | class PriorityQueueNaive
def initialize(data=nil)
@q = Hash.new {|h, k| h[k] = []}
data.each {|priority, item| @q[priority] << item} if data
@priorities = @q.keys.sort
end
def push(priority, item)
@q[priority] << item
@priorities = @q.keys.sort
end
def pop
p = @priorities[0]
... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Write a version of this Scala function in PHP with identical behavior. | import java.util.PriorityQueue
internal data class Task(val priority: Int, val name: String) : Comparable<Task> {
override fun compareTo(other: Task) = when {
priority < other.priority -> -1
priority > other.priority -> 1
else -> 0
}
}
private infix fun String.priority(priority: Int) =... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Port the provided Scala code into PHP while preserving the original functionality. | import java.util.PriorityQueue
internal data class Task(val priority: Int, val name: String) : Comparable<Task> {
override fun compareTo(other: Task) = when {
priority < other.priority -> -1
priority > other.priority -> 1
else -> 0
}
}
private infix fun String.priority(priority: Int) =... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Maintain the same structure and functionality when rewriting this code in PHP. | class Task : Comparable, CustomStringConvertible {
var priority : Int
var name: String
init(priority: Int, name: String) {
self.priority = priority
self.name = name
}
var description: String {
return "\(priority), \(name)"
}
}
func ==(t1: Task, t2: Task) -> Bool {
return t1.priority == t2.prio... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Write the same code in PHP as shown below in Swift. | class Task : Comparable, CustomStringConvertible {
var priority : Int
var name: String
init(priority: Int, name: String) {
self.priority = priority
self.name = name
}
var description: String {
return "\(priority), \(name)"
}
}
func ==(t1: Task, t2: Task) -> Bool {
return t1.priority == t2.prio... | <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Port the following code from Tcl to PHP with equivalent syntax and logic. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Port the following code from Tcl to PHP with equivalent syntax and logic. | package require struct::prioqueue
set pq [struct::prioqueue]
foreach {priority task} {
3 "Clear drains"
4 "Feed cat"
5 "Make tea"
1 "Solve RC tasks"
2 "Tax return"
} {
$pq put $task $priority
}
while {[$pq size]} {
puts [$pq get]
}
| <?php
$pq = new SplPriorityQueue;
$pq->insert('Clear drains', 3);
$pq->insert('Feed cat', 4);
$pq->insert('Make tea', 5);
$pq->insert('Solve RC tasks', 1);
$pq->insert('Tax return', 2);
$pq->setExtractFlags(SplPriorityQueue::EXTR_BOTH);
while (!$pq->isEmpty()) {
print_r($pq->extract());
}
?>
|
Write the same code in Rust as shown below in C. | #include <stdio.h>
#include <stdlib.h>
typedef struct {
int priority;
char *data;
} node_t;
typedef struct {
node_t *nodes;
int len;
int size;
} heap_t;
void push (heap_t *h, int priority, char *data) {
if (h->len + 1 >= h->size) {
h->size = h->size ? h->size * 2 : 4;
h->nodes... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Rewrite this program in Rust while keeping its functionality equivalent to the C++ version. | #include <iostream>
#include <string>
#include <queue>
#include <utility>
int main() {
std::priority_queue<std::pair<int, std::string> > pq;
pq.push(std::make_pair(3, "Clear drains"));
pq.push(std::make_pair(4, "Feed cat"));
pq.push(std::make_pair(5, "Make tea"));
pq.push(std::make_pair(1, "Solve RC tasks"))... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Produce a functionally identical Rust code for the snippet given in C#. | using System;
using System.Collections.Generic;
namespace PriorityQueueExample
{
class Program
{
static void Main(string[] args)
{
var p = new PriorityQueue<string, int>();
p.Enqueue("Clear drains", 3);
p.Enqueue("Feed cat", 4);
p.Enqueue("Make tea", 5);
p.Enqueue("Solve RC tasks", 1);
p.En... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Transform the following Java implementation into Rust, maintaining the same output and logic. | import java.util.PriorityQueue;
class Task implements Comparable<Task> {
final int priority;
final String name;
public Task(int p, String n) {
priority = p;
name = n;
}
public String toString() {
return priority + ", " + name;
}
public int compareTo(Task other) {
... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Change the following Java code into Rust without altering its purpose. | import java.util.PriorityQueue;
class Task implements Comparable<Task> {
final int priority;
final String name;
public Task(int p, String n) {
priority = p;
name = n;
}
public String toString() {
return priority + ", " + name;
}
public int compareTo(Task other) {
... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Change the following Go code into Rust without altering its purpose. | package main
import (
"fmt"
"container/heap"
)
type Task struct {
priority int
name string
}
type TaskPQ []Task
func (self TaskPQ) Len() int { return len(self) }
func (self TaskPQ) Less(i, j int) bool {
return self[i].priority < self[j].priority
}
func (self TaskPQ) Swap(i, j int) { self[i],... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Produce a language-to-language conversion: from Go to Rust, same semantics. | package main
import (
"fmt"
"container/heap"
)
type Task struct {
priority int
name string
}
type TaskPQ []Task
func (self TaskPQ) Len() int { return len(self) }
func (self TaskPQ) Less(i, j int) bool {
return self[i].priority < self[j].priority
}
func (self TaskPQ) Swap(i, j int) { self[i],... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Rewrite the snippet below in Python so it works the same as the original Rust code. | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... | >>> import queue
>>> pq = queue.PriorityQueue()
>>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")):
pq.put(item)
>>> while not pq.empty():
print(pq.get_nowait())
(1, 'Solve RC tasks')
(2, 'Tax return')
(3, 'Clear drains')
(4, 'Feed cat')
(5, 'Ma... |
Write the same code in VB as shown below in Rust. | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... | Type Tuple
Priority As Integer
Data As String
End Type
Dim a() As Tuple
Dim n As Integer
Private Function Left(i As Integer) As Integer
Left = 2 * i + 1
End Function
Private Function Right(i As Integer) As Integer
Right = 2 * i + 2
End Function
Private Function Parent(i As Integer) As Integer
Paren... |
Convert this Rust snippet to VB and keep its semantics consistent. | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... | Type Tuple
Priority As Integer
Data As String
End Type
Dim a() As Tuple
Dim n As Integer
Private Function Left(i As Integer) As Integer
Left = 2 * i + 1
End Function
Private Function Right(i As Integer) As Integer
Right = 2 * i + 2
End Function
Private Function Parent(i As Integer) As Integer
Paren... |
Convert the following code from C to Rust, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
typedef struct {
int priority;
char *data;
} node_t;
typedef struct {
node_t *nodes;
int len;
int size;
} heap_t;
void push (heap_t *h, int priority, char *data) {
if (h->len + 1 >= h->size) {
h->size = h->size ? h->size * 2 : 4;
h->nodes... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Preserve the algorithm and functionality while converting the code from C++ to Rust. | #include <iostream>
#include <string>
#include <queue>
#include <utility>
int main() {
std::priority_queue<std::pair<int, std::string> > pq;
pq.push(std::make_pair(3, "Clear drains"));
pq.push(std::make_pair(4, "Feed cat"));
pq.push(std::make_pair(5, "Make tea"));
pq.push(std::make_pair(1, "Solve RC tasks"))... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Produce a language-to-language conversion: from C# to Rust, same semantics. | using System;
using System.Collections.Generic;
namespace PriorityQueueExample
{
class Program
{
static void Main(string[] args)
{
var p = new PriorityQueue<string, int>();
p.Enqueue("Clear drains", 3);
p.Enqueue("Feed cat", 4);
p.Enqueue("Make tea", 5);
p.Enqueue("Solve RC tasks", 1);
p.En... | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... |
Convert this Rust block to Python, preserving its control flow and logic. | use std::collections::BinaryHeap;
use std::cmp::Ordering;
use std::borrow::Cow;
#[derive(Eq, PartialEq)]
struct Item<'a> {
priority: usize,
task: Cow<'a, str>,
}
impl<'a> Item<'a> {
fn new<T>(p: usize, t: T) -> Self
where T: Into<Cow<'a, str>>
{
Item {
priority: p,
... | >>> import queue
>>> pq = queue.PriorityQueue()
>>> for item in ((3, "Clear drains"), (4, "Feed cat"), (5, "Make tea"), (1, "Solve RC tasks"), (2, "Tax return")):
pq.put(item)
>>> while not pq.empty():
print(pq.get_nowait())
(1, 'Solve RC tasks')
(2, 'Tax return')
(3, 'Clear drains')
(4, 'Feed cat')
(5, 'Ma... |
Generate a C# translation of this Ada snippet without changing its computational steps. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hailstone
{
class Program
{
public static List<int> hs(int n,List<int> seq)
{
List<int> sequence = seq;
sequence.Add(n);
if (n == 1)
{
... |
Please provide an equivalent version of this Ada code in C#. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hailstone
{
class Program
{
public static List<int> hs(int n,List<int> seq)
{
List<int> sequence = seq;
sequence.Add(n);
if (n == 1)
{
... |
Can you help me rewrite this code in C instead of Ada, keeping it the same logically? | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | #include <stdio.h>
#include <stdlib.h>
int hailstone(int n, int *arry)
{
int hs = 1;
while (n!=1) {
hs++;
if (arry) *arry++ = n;
n = (n&1) ? (3*n+1) : (n/2);
}
if (arry) *arry++ = n;
return hs;
}
int main()
{
int j, hmax = 0;
int jatmax, n;
int *arry;
for ... |
Write a version of this Ada function in C with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | #include <stdio.h>
#include <stdlib.h>
int hailstone(int n, int *arry)
{
int hs = 1;
while (n!=1) {
hs++;
if (arry) *arry++ = n;
n = (n&1) ? (3*n+1) : (n/2);
}
if (arry) *arry++ = n;
return hs;
}
int main()
{
int j, hmax = 0;
int jatmax, n;
int *arry;
for ... |
Change the programming language of this snippet from Ada to C++ without modifying what it does. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | #include <iostream>
#include <vector>
#include <utility>
std::vector<int> hailstone(int i)
{
std::vector<int> v;
while(true){
v.push_back(i);
if (1 == i) break;
i = (i % 2) ? (3 * i + 1) : (i / 2);
}
return v;
}
std::pair<int,int> find_longest_hailstone_seq(int n)
{
std::... |
Translate the given Ada code snippet into C++ without altering its behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | #include <iostream>
#include <vector>
#include <utility>
std::vector<int> hailstone(int i)
{
std::vector<int> v;
while(true){
v.push_back(i);
if (1 == i) break;
i = (i % 2) ? (3 * i + 1) : (i / 2);
}
return v;
}
std::pair<int,int> find_longest_hailstone_seq(int n)
{
std::... |
Ensure the translated Go code behaves exactly like the original Ada snippet. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | package main
import "fmt"
func hs(n int, recycle []int) []int {
s := append(recycle[:0], n)
for n > 1 {
if n&1 == 0 {
n = n / 2
} else {
n = 3*n + 1
}
s = append(s, n)
}
return s
}
func main() {
seq := hs(27, nil)
fmt.Printf("hs(27): %... |
Write the same algorithm in Go as shown in this Ada implementation. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | package main
import "fmt"
func hs(n int, recycle []int) []int {
s := append(recycle[:0], n)
for n > 1 {
if n&1 == 0 {
n = n / 2
} else {
n = 3*n + 1
}
s = append(s, n)
}
return s
}
func main() {
seq := hs(27, nil)
fmt.Printf("hs(27): %... |
Transform the following Ada implementation into Java, maintaining the same output and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class Hailstone {
public static List<Long> getHailstoneSequence(long n) {
if (n <= 0)
throw new IllegalArgumentException("Invalid starting sequence number");
List<Long> list = new ArrayList<Long>();
... |
Port the provided Ada code into Java while preserving the original functionality. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class Hailstone {
public static List<Long> getHailstoneSequence(long n) {
if (n <= 0)
throw new IllegalArgumentException("Invalid starting sequence number");
List<Long> list = new ArrayList<Long>();
... |
Port the following code from Ada to Python with equivalent syntax and logic. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | def hailstone(n):
seq = [n]
while n>1:
n = 3*n + 1 if n & 1 else n//2
seq.append(n)
return seq
if __name__ == '__main__':
h = hailstone(27)
assert len(h)==112 and h[:4]==[27, 82, 41, 124] and h[-4:]==[8, 4, 2, 1]
print("Maximum length %i was found for hailstone(%i) for numbers <... |
Convert the following code from Ada to Python, ensuring the logic remains intact. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | def hailstone(n):
seq = [n]
while n>1:
n = 3*n + 1 if n & 1 else n//2
seq.append(n)
return seq
if __name__ == '__main__':
h = hailstone(27)
assert len(h)==112 and h[:4]==[27, 82, 41, 124] and h[-4:]==[8, 4, 2, 1]
print("Maximum length %i was found for hailstone(%i) for numbers <... |
Can you help me rewrite this code in VB instead of Ada, keeping it the same logically? | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | Private Function hailstone(ByVal n As Long) As Collection
Dim s As New Collection
s.Add CStr(n), CStr(n)
i = 0
Do While n <> 1
If n Mod 2 = 0 Then
n = n / 2
Else
n = 3 * n + 1
End If
s.Add CStr(n), CStr(n)
Loop
Set hailstone = s
End Functio... |
Write a version of this Ada function in VB with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure hailstone is
type int_arr is array(Positive range <>) of Integer;
type int_arr_pt is access all int_arr;
function hailstones(num:Integer; pt:int_arr_pt) return Integer is
stones : Integer := 1;
n : Integer := num;
begin
if pt /= null then pt(1) := num; end if;
... | Private Function hailstone(ByVal n As Long) As Collection
Dim s As New Collection
s.Add CStr(n), CStr(n)
i = 0
Do While n <> 1
If n Mod 2 = 0 Then
n = n / 2
Else
n = 3 * n + 1
End If
s.Add CStr(n), CStr(n)
Loop
Set hailstone = s
End Functio... |
Translate this program into C but keep the logic exactly as in Arturo. | hailstone: function [n][
ret: @[n]
while [n>1][
if? 1 = and n 1 -> n: 1+3*n
else -> n: n/2
'ret ++ n
]
ret
]
print "Hailstone sequence for 27:"
print hailstone 27
maxHailstoneLength: 0
maxHailstone: 0
loop 2..1000 'x [
l: size hailstone x
if l>maxHailstoneLength [
maxHailstoneLength: l
maxHailstone:... | #include <stdio.h>
#include <stdlib.h>
int hailstone(int n, int *arry)
{
int hs = 1;
while (n!=1) {
hs++;
if (arry) *arry++ = n;
n = (n&1) ? (3*n+1) : (n/2);
}
if (arry) *arry++ = n;
return hs;
}
int main()
{
int j, hmax = 0;
int jatmax, n;
int *arry;
for ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.