Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Preserve the algorithm and functionality while converting the code from Perl to VB. |
use strict;
use warnings;
use Time::Local;
my $year = shift // 1969;
my $width = shift // 80;
my $columns = int +($width + 2) / 22 or die "width too short at $width";
print map { center($_, $width), "\n" } '<reserved for snoopy>', $year;
my @months = qw( January February March April May June
July August September... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Write a version of this Perl function in Go with identical behavior. |
use strict;
use warnings;
use Time::Local;
my $year = shift // 1969;
my $width = shift // 80;
my $columns = int +($width + 2) / 22 or die "width too short at $width";
print map { center($_, $width), "\n" } '<reserved for snoopy>', $year;
my @months = qw( January February March April May June
July August September... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Translate this program into C but keep the logic exactly as in PowerShell. | Param([int]$Year = 1969)
Begin {
$COL_WIDTH = 21
$COLS = 3
$MONTH_COUNT = 12
$MONTH_LINES = 9
Function CenterStr([string]$s, [int]$lineSize) {
$padSize = [int](($lineSize - $s.Length) / 2)
($(if ($padSize -gt 0) { ' ' * $padSize } else { '' }) + $s).PadRight($lineSize,' ')
}
... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Change the following PowerShell code into C# without altering its purpose. | Param([int]$Year = 1969)
Begin {
$COL_WIDTH = 21
$COLS = 3
$MONTH_COUNT = 12
$MONTH_LINES = 9
Function CenterStr([string]$s, [int]$lineSize) {
$padSize = [int](($lineSize - $s.Length) / 2)
($(if ($padSize -gt 0) { ' ' * $padSize } else { '' }) + $s).PadRight($lineSize,' ')
}
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Translate this program into C++ but keep the logic exactly as in PowerShell. | Param([int]$Year = 1969)
Begin {
$COL_WIDTH = 21
$COLS = 3
$MONTH_COUNT = 12
$MONTH_LINES = 9
Function CenterStr([string]$s, [int]$lineSize) {
$padSize = [int](($lineSize - $s.Length) / 2)
($(if ($padSize -gt 0) { ' ' * $padSize } else { '' }) + $s).PadRight($lineSize,' ')
}
... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Produce a language-to-language conversion: from PowerShell to Java, same semantics. | Param([int]$Year = 1969)
Begin {
$COL_WIDTH = 21
$COLS = 3
$MONTH_COUNT = 12
$MONTH_LINES = 9
Function CenterStr([string]$s, [int]$lineSize) {
$padSize = [int](($lineSize - $s.Length) / 2)
($(if ($padSize -gt 0) { ' ' * $padSize } else { '' }) + $s).PadRight($lineSize,' ')
}
... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Rewrite the snippet below in Python so it works the same as the original PowerShell code. | Param([int]$Year = 1969)
Begin {
$COL_WIDTH = 21
$COLS = 3
$MONTH_COUNT = 12
$MONTH_LINES = 9
Function CenterStr([string]$s, [int]$lineSize) {
$padSize = [int](($lineSize - $s.Length) / 2)
($(if ($padSize -gt 0) { ' ' * $padSize } else { '' }) + $s).PadRight($lineSize,' ')
}
... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Convert the following code from PowerShell to VB, ensuring the logic remains intact. | Param([int]$Year = 1969)
Begin {
$COL_WIDTH = 21
$COLS = 3
$MONTH_COUNT = 12
$MONTH_LINES = 9
Function CenterStr([string]$s, [int]$lineSize) {
$padSize = [int](($lineSize - $s.Length) / 2)
($(if ($padSize -gt 0) { ' ' * $padSize } else { '' }) + $s).PadRight($lineSize,' ')
}
... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Ensure the translated Go code behaves exactly like the original PowerShell snippet. | Param([int]$Year = 1969)
Begin {
$COL_WIDTH = 21
$COLS = 3
$MONTH_COUNT = 12
$MONTH_LINES = 9
Function CenterStr([string]$s, [int]$lineSize) {
$padSize = [int](($lineSize - $s.Length) / 2)
($(if ($padSize -gt 0) { ' ' * $padSize } else { '' }) + $s).PadRight($lineSize,' ')
}
... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Change the following Racket code into C without altering its purpose. | #lang racket
(require racket/date net/base64 file/gunzip)
(define (calendar yr)
(define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n)))))
(define months
(for/list ([mn (in-naturals 1)]
[mname '(January February March April May June July
August Septembe... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Port the following code from Racket to C# with equivalent syntax and logic. | #lang racket
(require racket/date net/base64 file/gunzip)
(define (calendar yr)
(define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n)))))
(define months
(for/list ([mn (in-naturals 1)]
[mname '(January February March April May June July
August Septembe... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Port the provided Racket code into C++ while preserving the original functionality. | #lang racket
(require racket/date net/base64 file/gunzip)
(define (calendar yr)
(define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n)))))
(define months
(for/list ([mn (in-naturals 1)]
[mname '(January February March April May June July
August Septembe... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Write a version of this Racket function in Java with identical behavior. | #lang racket
(require racket/date net/base64 file/gunzip)
(define (calendar yr)
(define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n)))))
(define months
(for/list ([mn (in-naturals 1)]
[mname '(January February March April May June July
August Septembe... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Generate a Python translation of this Racket snippet without changing its computational steps. | #lang racket
(require racket/date net/base64 file/gunzip)
(define (calendar yr)
(define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n)))))
(define months
(for/list ([mn (in-naturals 1)]
[mname '(January February March April May June July
August Septembe... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Rewrite this program in VB while keeping its functionality equivalent to the Racket version. | #lang racket
(require racket/date net/base64 file/gunzip)
(define (calendar yr)
(define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n)))))
(define months
(for/list ([mn (in-naturals 1)]
[mname '(January February March April May June July
August Septembe... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Convert the following code from Racket to Go, ensuring the logic remains intact. | #lang racket
(require racket/date net/base64 file/gunzip)
(define (calendar yr)
(define (nsplit n l) (if (null? l) l (cons (take l n) (nsplit n (drop l n)))))
(define months
(for/list ([mn (in-naturals 1)]
[mname '(January February March April May June July
August Septembe... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Translate this program into C# but keep the logic exactly as in COBOL. | IDENTIFICATION DIVISION.
PROGRAM-ID. CALEND.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-DAY-NAMES-DEF.
03 FILLER PIC X(09) VALUE 'SUNDAY '.
03 FILLER PIC X(09) VALUE 'MONDAY '.
03 FILLER PI... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Preserve the algorithm and functionality while converting the code from COBOL to Java. | IDENTIFICATION DIVISION.
PROGRAM-ID. CALEND.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-DAY-NAMES-DEF.
03 FILLER PIC X(09) VALUE 'SUNDAY '.
03 FILLER PIC X(09) VALUE 'MONDAY '.
03 FILLER PI... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Can you help me rewrite this code in Python instead of COBOL, keeping it the same logically? | IDENTIFICATION DIVISION.
PROGRAM-ID. CALEND.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-DAY-NAMES-DEF.
03 FILLER PIC X(09) VALUE 'SUNDAY '.
03 FILLER PIC X(09) VALUE 'MONDAY '.
03 FILLER PI... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Port the following code from COBOL to VB with equivalent syntax and logic. | IDENTIFICATION DIVISION.
PROGRAM-ID. CALEND.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-DAY-NAMES-DEF.
03 FILLER PIC X(09) VALUE 'SUNDAY '.
03 FILLER PIC X(09) VALUE 'MONDAY '.
03 FILLER PI... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Rewrite this program in Go while keeping its functionality equivalent to the COBOL version. | IDENTIFICATION DIVISION.
PROGRAM-ID. CALEND.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-DAY-NAMES-DEF.
03 FILLER PIC X(09) VALUE 'SUNDAY '.
03 FILLER PIC X(09) VALUE 'MONDAY '.
03 FILLER PI... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Produce a language-to-language conversion: from REXX to C#, same semantics. |
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
calfill=' '; mc=12; _='1 3 1234567890' "fb"x
parse var _ grid calspaces # chk . cv_ days.1 days.2 days.3 daysn sd sw
_=0; parse var _ cols 1 jd 1 lowerCase 1 maxKalPuts 1 narrow 1,
narrower 1 narrowest 1 short 1 shorter 1 shortest 1,
... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Write a version of this REXX function in Java with identical behavior. |
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
calfill=' '; mc=12; _='1 3 1234567890' "fb"x
parse var _ grid calspaces # chk . cv_ days.1 days.2 days.3 daysn sd sw
_=0; parse var _ cols 1 jd 1 lowerCase 1 maxKalPuts 1 narrow 1,
narrower 1 narrowest 1 short 1 shorter 1 shortest 1,
... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Rewrite the snippet below in Python so it works the same as the original REXX code. |
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
calfill=' '; mc=12; _='1 3 1234567890' "fb"x
parse var _ grid calspaces # chk . cv_ days.1 days.2 days.3 daysn sd sw
_=0; parse var _ cols 1 jd 1 lowerCase 1 maxKalPuts 1 narrow 1,
narrower 1 narrowest 1 short 1 shorter 1 shortest 1,
... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Translate the given REXX code snippet into VB without altering its behavior. |
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
calfill=' '; mc=12; _='1 3 1234567890' "fb"x
parse var _ grid calspaces # chk . cv_ days.1 days.2 days.3 daysn sd sw
_=0; parse var _ cols 1 jd 1 lowerCase 1 maxKalPuts 1 narrow 1,
narrower 1 narrowest 1 short 1 shorter 1 shortest 1,
... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Rewrite this program in Go while keeping its functionality equivalent to the REXX version. |
@abc='abcdefghijklmnopqrstuvwxyz'; @abcU=@abc; upper @abcU
calfill=' '; mc=12; _='1 3 1234567890' "fb"x
parse var _ grid calspaces # chk . cv_ days.1 days.2 days.3 daysn sd sw
_=0; parse var _ cols 1 jd 1 lowerCase 1 maxKalPuts 1 narrow 1,
narrower 1 narrowest 1 short 1 shorter 1 shortest 1,
... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Keep all operations the same but rewrite the snippet in C. | require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), "Su Mo Tu We Th Fr Sa"]
days = []
date.wday.times { days.push " " }
while date.month == month
days.p... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Translate this program into C# but keep the logic exactly as in Ruby. | require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), "Su Mo Tu We Th Fr Sa"]
days = []
date.wday.times { days.push " " }
while date.month == month
days.p... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Convert this Ruby block to C++, preserving its control flow and logic. | require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), "Su Mo Tu We Th Fr Sa"]
days = []
date.wday.times { days.push " " }
while date.month == month
days.p... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Rewrite this program in Java while keeping its functionality equivalent to the Ruby version. | require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), "Su Mo Tu We Th Fr Sa"]
days = []
date.wday.times { days.push " " }
while date.month == month
days.p... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Can you help me rewrite this code in Python instead of Ruby, keeping it the same logically? | require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), "Su Mo Tu We Th Fr Sa"]
days = []
date.wday.times { days.push " " }
while date.month == month
days.p... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Translate the given Ruby code snippet into VB without altering its behavior. | require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), "Su Mo Tu We Th Fr Sa"]
days = []
date.wday.times { days.push " " }
while date.month == month
days.p... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Generate a Go translation of this Ruby snippet without changing its computational steps. | require 'date'
def cal(year, columns)
date = Date.new(year, 1, 1, Date::ENGLAND)
months = (1..12).collect do |month|
rows = [Date::MONTHNAMES[month].center(20), "Su Mo Tu We Th Fr Sa"]
days = []
date.wday.times { days.push " " }
while date.month == month
days.p... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Rewrite this program in C while keeping its functionality equivalent to the Scala version. | import java.io.PrintStream
import java.text.DateFormatSymbols
import java.text.MessageFormat
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Locale
internal fun PrintStream.printCalendar(year: Int, nCols: Byte, locale: Locale?) {
if (nCols < 1 || nCols > 12)
throw IllegalArgum... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Please provide an equivalent version of this Scala code in C#. | import java.io.PrintStream
import java.text.DateFormatSymbols
import java.text.MessageFormat
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Locale
internal fun PrintStream.printCalendar(year: Int, nCols: Byte, locale: Locale?) {
if (nCols < 1 || nCols > 12)
throw IllegalArgum... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Change the programming language of this snippet from Scala to C++ without modifying what it does. | import java.io.PrintStream
import java.text.DateFormatSymbols
import java.text.MessageFormat
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Locale
internal fun PrintStream.printCalendar(year: Int, nCols: Byte, locale: Locale?) {
if (nCols < 1 || nCols > 12)
throw IllegalArgum... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Translate the given Scala code snippet into Java without altering its behavior. | import java.io.PrintStream
import java.text.DateFormatSymbols
import java.text.MessageFormat
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Locale
internal fun PrintStream.printCalendar(year: Int, nCols: Byte, locale: Locale?) {
if (nCols < 1 || nCols > 12)
throw IllegalArgum... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Convert this Scala block to Python, preserving its control flow and logic. | import java.io.PrintStream
import java.text.DateFormatSymbols
import java.text.MessageFormat
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Locale
internal fun PrintStream.printCalendar(year: Int, nCols: Byte, locale: Locale?) {
if (nCols < 1 || nCols > 12)
throw IllegalArgum... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Can you help me rewrite this code in VB instead of Scala, keeping it the same logically? | import java.io.PrintStream
import java.text.DateFormatSymbols
import java.text.MessageFormat
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Locale
internal fun PrintStream.printCalendar(year: Int, nCols: Byte, locale: Locale?) {
if (nCols < 1 || nCols > 12)
throw IllegalArgum... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Generate a Go translation of this Scala snippet without changing its computational steps. | import java.io.PrintStream
import java.text.DateFormatSymbols
import java.text.MessageFormat
import java.util.Calendar
import java.util.GregorianCalendar
import java.util.Locale
internal fun PrintStream.printCalendar(year: Int, nCols: Byte, locale: Locale?) {
if (nCols < 1 || nCols > 12)
throw IllegalArgum... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Port the following code from Swift to C with equivalent syntax and logic. | import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width ? string
: String(repeating: " ", count: width - string.count) +... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Can you help me rewrite this code in C# instead of Swift, keeping it the same logically? | import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width ? string
: String(repeating: " ", count: width - string.count) +... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Rewrite the snippet below in C++ so it works the same as the original Swift code. | import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width ? string
: String(repeating: " ", count: width - string.count) +... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Write the same algorithm in Java as shown in this Swift implementation. | import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width ? string
: String(repeating: " ", count: width - string.count) +... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Write the same algorithm in Python as shown in this Swift implementation. | import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width ? string
: String(repeating: " ", count: width - string.count) +... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Rewrite this program in VB while keeping its functionality equivalent to the Swift version. | import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width ? string
: String(repeating: " ", count: width - string.count) +... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Port the provided Swift code into Go while preserving the original functionality. | import Foundation
let monthWidth = 20
let monthGap = 2
let dayNames = "Su Mo Tu We Th Fr Sa"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM"
func rpad(string: String, width: Int) -> String {
return string.count >= width ? string
: String(repeating: " ", count: width - string.count) +... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Write the same algorithm in C as shown in this Tcl implementation. | package require Tcl 8.5
proc calMonthDays {timezone locale year month} {
set days {}
set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \
-timezone $timezone -locale $locale -format "%Y-%m-%d %H:%M"]
while 1 {
set moment [clock add $moment 1 day]
lassign [clock format $moment -timez... | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
Preserve the algorithm and functionality while converting the code from Tcl to C#. | package require Tcl 8.5
proc calMonthDays {timezone locale year month} {
set days {}
set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \
-timezone $timezone -locale $locale -format "%Y-%m-%d %H:%M"]
while 1 {
set moment [clock add $moment 1 day]
lassign [clock format $moment -timez... | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
Generate an equivalent C++ version of this Tcl code. | package require Tcl 8.5
proc calMonthDays {timezone locale year month} {
set days {}
set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \
-timezone $timezone -locale $locale -format "%Y-%m-%d %H:%M"]
while 1 {
set moment [clock add $moment 1 day]
lassign [clock format $moment -timez... | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
Convert this Tcl snippet to Java and keep its semantics consistent. | package require Tcl 8.5
proc calMonthDays {timezone locale year month} {
set days {}
set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \
-timezone $timezone -locale $locale -format "%Y-%m-%d %H:%M"]
while 1 {
set moment [clock add $moment 1 day]
lassign [clock format $moment -timez... | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
Produce a functionally identical Python code for the snippet given in Tcl. | package require Tcl 8.5
proc calMonthDays {timezone locale year month} {
set days {}
set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \
-timezone $timezone -locale $locale -format "%Y-%m-%d %H:%M"]
while 1 {
set moment [clock add $moment 1 day]
lassign [clock format $moment -timez... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Translate the given Tcl code snippet into VB without altering its behavior. | package require Tcl 8.5
proc calMonthDays {timezone locale year month} {
set days {}
set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \
-timezone $timezone -locale $locale -format "%Y-%m-%d %H:%M"]
while 1 {
set moment [clock add $moment 1 day]
lassign [clock format $moment -timez... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Generate an equivalent Go version of this Tcl code. | package require Tcl 8.5
proc calMonthDays {timezone locale year month} {
set days {}
set moment [clock scan [format "%04d-%02d-00 12:00" $year $month] \
-timezone $timezone -locale $locale -format "%Y-%m-%d %H:%M"]
while 1 {
set moment [clock add $moment 1 day]
lassign [clock format $moment -timez... | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
Port the provided C code into Rust while preserving the original functionality. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
int width = 80, year = 1969;
int cols, lead, gap;
const char *wdays[] = { "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" };
struct months {
const char *name;
int days, start_wday, at;
} months[12] = {
{ "January", 31, 0, 0 },
{ "February", 28, 0, 0 },
{ "March... |
extern crate chrono;
use std::{env, cmp};
use chrono::{NaiveDate, Datelike};
const MONTH_WIDTH: usize = 22;
fn print_header(months: &[&str]) {
const DAYS_OF_WEEK: &str = "SU MO TU WE TH FR SA ";
println!();
for m in months {
print!("{:^20} ", m);
}
println!("\n{}", DAYS_OF_WEEK.re... |
Write the same algorithm in Rust as shown in this C++ implementation. | #include <windows.h>
#include <iostream>
using namespace std;
class calender
{
public:
void drawCalender( int y )
{
year = y;
for( int i = 0; i < 12; i++ )
firstdays[i] = getfirstday( i );
isleapyear();
build();
}
private:
void isleapyear()
{
isleap = false;
if( !( year % 4 ) )
{... |
extern crate chrono;
use std::{env, cmp};
use chrono::{NaiveDate, Datelike};
const MONTH_WIDTH: usize = 22;
fn print_header(months: &[&str]) {
const DAYS_OF_WEEK: &str = "SU MO TU WE TH FR SA ";
println!();
for m in months {
print!("{:^20} ", m);
}
println!("\n{}", DAYS_OF_WEEK.re... |
Transform the following C# implementation into Rust, maintaining the same output and logic. | using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CalendarStuff
{
class Program
{
static void Main(string[] args)
{
Console.WindowHeight = 46;
Console.Write(buildMonths(new DateTime(1969, 1, 1)));
Console.Read(... |
extern crate chrono;
use std::{env, cmp};
use chrono::{NaiveDate, Datelike};
const MONTH_WIDTH: usize = 22;
fn print_header(months: &[&str]) {
const DAYS_OF_WEEK: &str = "SU MO TU WE TH FR SA ";
println!();
for m in months {
print!("{:^20} ", m);
}
println!("\n{}", DAYS_OF_WEEK.re... |
Transform the following Go implementation into Rust, maintaining the same output and logic. | package main
import (
"fmt"
"time"
)
const pageWidth = 80
func main() {
printCal(1969)
}
func printCal(year int) {
thisDate := time.Date(year, 1, 1, 1, 1, 1, 1, time.UTC)
var (
dayArr [12][7][6]int
month, lastMonth time.Month
weekInMonth, dayInMonth int
)
for thisDate.Year() ==... |
extern crate chrono;
use std::{env, cmp};
use chrono::{NaiveDate, Datelike};
const MONTH_WIDTH: usize = 22;
fn print_header(months: &[&str]) {
const DAYS_OF_WEEK: &str = "SU MO TU WE TH FR SA ";
println!();
for m in months {
print!("{:^20} ", m);
}
println!("\n{}", DAYS_OF_WEEK.re... |
Convert the following code from Rust to Python, ensuring the logic remains intact. |
extern crate chrono;
use std::{env, cmp};
use chrono::{NaiveDate, Datelike};
const MONTH_WIDTH: usize = 22;
fn print_header(months: &[&str]) {
const DAYS_OF_WEEK: &str = "SU MO TU WE TH FR SA ";
println!();
for m in months {
print!("{:^20} ", m);
}
println!("\n{}", DAYS_OF_WEEK.re... | >>> import calendar
>>> help(calendar.prcal)
Help on method pryear in module calendar:
pryear(self, theyear, w=0, l=0, c=6, m=3) method of calendar.TextCalendar instance
Print a years calendar.
>>> calendar.prcal(1969)
1969
January February ... |
Port the following code from Java to Rust with equivalent syntax and logic. | import java.text.*;
import java.util.*;
public class CalendarTask {
public static void main(String[] args) {
printCalendar(1969, 3);
}
static void printCalendar(int year, int nCols) {
if (nCols < 1 || nCols > 12)
throw new IllegalArgumentException("Illegal column width.");
... |
extern crate chrono;
use std::{env, cmp};
use chrono::{NaiveDate, Datelike};
const MONTH_WIDTH: usize = 22;
fn print_header(months: &[&str]) {
const DAYS_OF_WEEK: &str = "SU MO TU WE TH FR SA ";
println!();
for m in months {
print!("{:^20} ", m);
}
println!("\n{}", DAYS_OF_WEEK.re... |
Port the following code from Rust to VB with equivalent syntax and logic. |
extern crate chrono;
use std::{env, cmp};
use chrono::{NaiveDate, Datelike};
const MONTH_WIDTH: usize = 22;
fn print_header(months: &[&str]) {
const DAYS_OF_WEEK: &str = "SU MO TU WE TH FR SA ";
println!();
for m in months {
print!("{:^20} ", m);
}
println!("\n{}", DAYS_OF_WEEK.re... |
docal 1969,6,""
function center (s,n) x=n-len(s):center=space(x\2+(x and 1))& s & space(x\2):end function
sub print(x) wscript.stdout.writeline x : end sub
function iif(a,b,c) :if a then iif=b else iif =c end if : end function
sub docal (yr,nmonth,sloc)
dim ld(6)
dim d(6)
if nmonth=5 or nmonth>6 or nmonth<1 th... |
Maintain the same structure and functionality when rewriting this code in C#. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Convert the following code from Ada to C#, ensuring the logic remains intact. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Write a version of this Ada function in C with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Write a version of this Ada function in C with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Write the same code in Go as shown below in Ada. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | package main
import (
"fmt"
"math/big"
)
func dList(n int) (r [][]int) {
a := make([]int, n)
for i := range a {
a[i] = i
}
var recurse func(last int)
recurse = func(last int) {
if last == 0 {
for j, v := range a {
... |
Write a version of this Ada function in Go with identical behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | package main
import (
"fmt"
"math/big"
)
func dList(n int) (r [][]int) {
a := make([]int, n)
for i := range a {
a[i] = i
}
var recurse func(last int)
recurse = func(last int) {
if last == 0 {
for j, v := range a {
... |
Produce a language-to-language conversion: from Ada to Java, same semantics. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Translate the given Ada code snippet into Java without altering its behavior. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Rewrite this program in Python while keeping its functionality equivalent to the Ada version. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Ensure the translated Python code behaves exactly like the original Ada snippet. | with Ada.Text_IO; use Ada.Text_IO;
procedure DePermute is
type U64 is mod 2**64;
type Num is range 0 .. 20;
type NumList is array (Natural range <>) of Num;
type PtNumList is access all NumList;
package IO is new Ada.Text_IO.Integer_IO (Num);
package UIO is new Ada.Text_IO.Modular_IO (U64);
fun... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Ensure the translated C code behaves exactly like the original Arturo snippet. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Rewrite the snippet below in C so it works the same as the original Arturo code. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Port the provided Arturo code into C# while preserving the original functionality. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Write the same code in C# as shown below in Arturo. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Port the provided Arturo code into Java while preserving the original functionality. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Write the same algorithm in Java as shown in this Arturo implementation. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Port the provided Arturo code into Python while preserving the original functionality. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Preserve the algorithm and functionality while converting the code from Arturo to Python. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Write the same code in Go as shown below in Arturo. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | package main
import (
"fmt"
"math/big"
)
func dList(n int) (r [][]int) {
a := make([]int, n)
for i := range a {
a[i] = i
}
var recurse func(last int)
recurse = func(last int) {
if last == 0 {
for j, v := range a {
... |
Generate an equivalent Go version of this Arturo code. | isClean?: function [s,o][
loop.with:'i s 'a [
if a = o\[i] -> return false
]
return true
]
derangements: function [n][
original: 1..n
select permutate original 'x ->
isClean? x original
]
subfactorial: function [n].memoize[
(n =< 1)? -> 1 - n
-> (n-1) * (add subfa... | package main
import (
"fmt"
"math/big"
)
func dList(n int) (r [][]int) {
a := make([]int, n)
for i := range a {
a[i] = i
}
var recurse func(last int)
recurse = func(last int) {
if last == 0 {
for j, v := range a {
... |
Maintain the same structure and functionality when rewriting this code in C. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Port the provided Clojure code into C while preserving the original functionality. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Port the provided Clojure code into C# while preserving the original functionality. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Port the following code from Clojure to C# with equivalent syntax and logic. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Convert this Clojure block to Java, preserving its control flow and logic. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Generate an equivalent Java version of this Clojure code. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Convert this Clojure snippet to Python and keep its semantics consistent. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Maintain the same structure and functionality when rewriting this code in Python. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Ensure the translated Go code behaves exactly like the original Clojure snippet. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | package main
import (
"fmt"
"math/big"
)
func dList(n int) (r [][]int) {
a := make([]int, n)
for i := range a {
a[i] = i
}
var recurse func(last int)
recurse = func(last int) {
if last == 0 {
for j, v := range a {
... |
Ensure the translated Go code behaves exactly like the original Clojure snippet. | (ns derangements.core
(:require [clojure.set :as s]))
(defn subfactorial [n]
(case n
0 1
1 0
(* (dec n) (+ (subfactorial (dec n)) (subfactorial (- n 2))))))
(defn no-fixed-point
"f : A -> B must be a biyective function written as a hash-map, returns
all g : A -> B such that (f(a) = b) => not(g(a) ... | package main
import (
"fmt"
"math/big"
)
func dList(n int) (r [][]int) {
a := make([]int, n)
for i := range a {
a[i] = i
}
var recurse func(last int)
recurse = func(last int) {
if last == 0 {
for j, v := range a {
... |
Convert this D snippet to C and keep its semantics consistent. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Can you help me rewrite this code in C instead of D, keeping it the same logically? | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | #include <stdio.h>
typedef unsigned long long LONG;
LONG deranged(int depth, int len, int *d, int show)
{
int i;
char tmp;
LONG count = 0;
if (depth == len) {
if (show) {
for (i = 0; i < len; i++) putchar(d[i] + 'a');
putc... |
Write the same algorithm in C# as shown in this D implementation. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Change the programming language of this snippet from D to C# without modifying what it does. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | using System;
class Derangements
{
static int n = 4;
static int [] buf = new int [n];
static bool [] used = new bool [n];
static void Main()
{
for (int i = 0; i < n; i++) used [i] = false;
rec(0);
}
static void rec(int ind)
{
for (int i = 0; i < n; i++)
{
if (!used [i] && i != in... |
Rewrite the snippet below in Java so it works the same as the original D code. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Change the following D code into Java without altering its purpose. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Derangement {
public static void main(String[] args) {
System.out.println("derangements for n = 4\n");
for (Object d : (ArrayList)(derangements(4, false)[0])) {
System.out.println(Arrays.toString(... |
Produce a functionally identical Python code for the snippet given in D. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Convert this D block to Python, preserving its control flow and logic. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | from itertools import permutations
import math
def derangements(n):
'All deranged permutations of the integers 0..n-1 inclusive'
return ( perm for perm in permutations(range(n))
if all(indx != p for indx, p in enumerate(perm)) )
def subfact(n):
if n == 2 or n == 0:
return 1
elif ... |
Translate the given D code snippet into Go without altering its behavior. | import std.stdio, std.algorithm, std.typecons, std.conv,
std.range, std.traits;
T factorial(T)(in T n) pure nothrow @safe @nogc {
Unqual!T result = 1;
foreach (immutable i; 2 .. n + 1)
result *= i;
return result;
}
T subfact(T)(in T n) pure nothrow @safe @nogc {
if (0 <= n && n <= 2)
... | package main
import (
"fmt"
"math/big"
)
func dList(n int) (r [][]int) {
a := make([]int, n)
for i := range a {
a[i] = i
}
var recurse func(last int)
recurse = func(last int) {
if last == 0 {
for j, v := range a {
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.