Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Port the provided C code into REXX while preserving the original functionality. | #include <stdio.h>
#include <string.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
double test_func(double x)
{
return cos(x);
}
double map(double x, double min_x, double max_x, double min_to, double max_to)
{
return (x - min_x)/(max_x - min_x)*(max_to - min_to) + min_to;
}
void c... |
numeric digits length( pi() ) - length(.)
parse arg a b N .
if a=='' | a=="," then a= 0
if b=='' | b=="," then b= 1
if N=='' | N=="," then N= 10
fac= 2 / N; pin= pi / N
Dma= (b-a) / 2 ... |
Change the following C code into REXX without altering its purpose. | #include <stdio.h>
#include <string.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
double test_func(double x)
{
return cos(x);
}
double map(double x, double min_x, double max_x, double min_to, double max_to)
{
return (x - min_x)/(max_x - min_x)*(max_to - min_to) + min_to;
}
void c... |
numeric digits length( pi() ) - length(.)
parse arg a b N .
if a=='' | a=="," then a= 0
if b=='' | b=="," then b= 1
if N=='' | N=="," then N= 10
fac= 2 / N; pin= pi / N
Dma= (b-a) / 2 ... |
Produce a language-to-language conversion: from C to REXX, same semantics. | #include <string.h>
#include <stdio.h>
#include <stdlib.h>
const char STX = '\002', ETX = '\003';
int compareStrings(const void *a, const void *b) {
char *aa = *(char **)a;
char *bb = *(char **)b;
return strcmp(aa, bb);
}
int bwt(const char *s, char r[]) {
int i, len = strlen(s) + 2;
char *ss, *s... |
$.=
parse arg $.1
if $.1='' then do; $.1= "banana"
$.2= "BANANA"
$.3= "appellee"
$.4= "dogwood"
$.5= "TO BE OR NOT TO BE OR WANT TO BE O... |
Change the following C code into REXX without altering its purpose. | #include <string.h>
#include <stdio.h>
#include <stdlib.h>
const char STX = '\002', ETX = '\003';
int compareStrings(const void *a, const void *b) {
char *aa = *(char **)a;
char *bb = *(char **)b;
return strcmp(aa, bb);
}
int bwt(const char *s, char r[]) {
int i, len = strlen(s) + 2;
char *ss, *s... |
$.=
parse arg $.1
if $.1='' then do; $.1= "banana"
$.2= "BANANA"
$.3= "appellee"
$.4= "dogwood"
$.5= "TO BE OR NOT TO BE OR WANT TO BE O... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <stdio.h>
#include <stdlib.h>
typedef struct sublist{
struct sublist* next;
int *buf;
} sublist_t;
sublist_t* sublist_new(size_t s)
{
sublist_t* sub = malloc(sizeof(sublist_t) + sizeof(int) * s);
sub->buf = (int*)(sub + 1);
sub->next = 0;
return sub;
}
typedef struct vlist_t {
sublist_t* head;
size_... | -- show how to use the queue class
q = .queue~of(1, 2, 3, 4)
-- show indexed access to item
say q[4]
-- update an item
q[2] = "Fred"
-- show update and that other indexes are unchanged
say q[2] q[4]
-- push an item on the front and show the change in positions
q~push("Mike")
say q[1] q[2] q[4]
-- pop an item and s... |
Produce a functionally identical REXX code for the snippet given in C. | #include <stdio.h>
#include <stdlib.h>
typedef struct sublist{
struct sublist* next;
int *buf;
} sublist_t;
sublist_t* sublist_new(size_t s)
{
sublist_t* sub = malloc(sizeof(sublist_t) + sizeof(int) * s);
sub->buf = (int*)(sub + 1);
sub->next = 0;
return sub;
}
typedef struct vlist_t {
sublist_t* head;
size_... | -- show how to use the queue class
q = .queue~of(1, 2, 3, 4)
-- show indexed access to item
say q[4]
-- update an item
q[2] = "Fred"
-- show update and that other indexes are unchanged
say q[2] q[4]
-- push an item on the front and show the change in positions
q~push("Mike")
say q[1] q[2] q[4]
-- pop an item and s... |
Please provide an equivalent version of this C code in REXX. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void init() {
srand((unsigned int)time(NULL));
}
int random(int low, int high) {
int diff, val;
diff = high - low;
if (diff == 0) {
return low;
}
val = rand() % diff;
return val + low;
}
void initDeck(i... |
call create; call show 'new deck'
call create; call riffle 1
call show 'riffle shuffle'
call create; call overhand 1/5
call show 'overhand shuffle'
call create; call barnYard 13
ca... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void init() {
srand((unsigned int)time(NULL));
}
int random(int low, int high) {
int diff, val;
diff = high - low;
if (diff == 0) {
return low;
}
val = rand() % diff;
return val + low;
}
void initDeck(i... |
call create; call show 'new deck'
call create; call riffle 1
call show 'riffle shuffle'
call create; call overhand 1/5
call show 'overhand shuffle'
call create; call barnYard 13
ca... |
Produce a language-to-language conversion: from C to REXX, same semantics. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int binomial(int n, int k) {
int num, denom, i;
if (n < 0 || k < 0 || n < k) return -1;
if (n == 0 || k == 0) return 1;
num = 1;
for (i = k + 1; i <= n; ++i) {
num = num * i;
}
denom = 1;
for (i =... | Numeric Digits 100
Do r=0 To 20
ra=r-1
If r=0 Then
f.r.1=1
Else Do
rsum=0
Do c=2 To r+1
ca=c-1
f.r.c=fdivide(fmultiply(f.ra.ca,r),c)
rsum=fsum(rsum,f.r.c)
End
f.r.1=fsubtract(1,rsum)
End
End
Do r=0 To 9
ol=''
Do c=1 To r+1
ol=ol right(f.r.c,5)
End
Say ol... |
Write the same code in REXX as shown below in C. | #include <stdio.h>
#define MAX_N 33
#define BRANCH 4
typedef unsigned long long xint;
#define FMT "llu"
xint rooted[MAX_N] = {1, 1, 0};
xint unrooted[MAX_N] = {1, 1, 0};
xint choose(xint m, xint k)
{
xint i, r;
if (k == 1) return m;
for (r = m, i = 1; i < k; i++)
r = r * (m + i) / (i + 1);
return r;
}
... |
parse arg nodes .
if nodes=='' | nodes=="," then nodes= 100
rooted. = 0; rooted.0= 1; rooted.1= 1
unrooted. = 0; unrooted.0= 1; unrooted.1= 1
numeric digits max(9, nodes % 2)
w= length(nodes)
say right(0, w) u... |
Can you help me rewrite this code in REXX instead of C, keeping it the same logically? | #include <stdio.h>
#define MAX_N 33
#define BRANCH 4
typedef unsigned long long xint;
#define FMT "llu"
xint rooted[MAX_N] = {1, 1, 0};
xint unrooted[MAX_N] = {1, 1, 0};
xint choose(xint m, xint k)
{
xint i, r;
if (k == 1) return m;
for (r = m, i = 1; i < k; i++)
r = r * (m + i) / (i + 1);
return r;
}
... |
parse arg nodes .
if nodes=='' | nodes=="," then nodes= 100
rooted. = 0; rooted.0= 1; rooted.1= 1
unrooted. = 0; unrooted.0= 1; unrooted.1= 1
numeric digits max(9, nodes % 2)
w= length(nodes)
say right(0, w) u... |
Port the following code from C to REXX with equivalent syntax and logic. | #include <iostream>
#include <iomanip>
#include <string>
std::string NYSIIS( std::string const& str )
{
std::string s, out;
s.reserve( str.length() );
for( auto const c : str )
{
if( c >= 'a' && c <= 'z' )
s += c - ('a' - 'A');
else if( c >= 'A' && c <= 'Z' )
... | return strip( left(key, 6) )
|
Keep all operations the same but rewrite the snippet in REXX. | #include <iostream>
#include <iomanip>
#include <string>
std::string NYSIIS( std::string const& str )
{
std::string s, out;
s.reserve( str.length() );
for( auto const c : str )
{
if( c >= 'a' && c <= 'z' )
s += c - ('a' - 'A');
else if( c >= 'A' && c <= 'Z' )
... | return strip( left(key, 6) )
|
Can you help me rewrite this code in REXX instead of C, keeping it the same logically? | #include <ldap.h>
char *name, *password;
...
LDAP *ld = ldap_init("ldap.somewhere.com", 389);
ldap_simple_bind_s(ld, name, password);
LDAPMessage **result;
ldap_search_s(ld, "dc=somewhere,dc=com", LDAP_SCOPE_SUBTREE,
"(&(objectclass=person)(|(cn=joe*)(cn=shmoe*)))",
NULL,
0,
result);
ldap_msgfree(*resul... |
options replace format comments java crossref symbols binary
import org.apache.directory.ldap.client.api.LdapConnection
import org.apache.directory.ldap.client.api.LdapNetworkConnection
import org.apache.directory.shared.ldap.model.cursor.EntryCursor
import org.apache.directory.shared.ldap.model.entry.Entry
import or... |
Keep all operations the same but rewrite the snippet in REXX. | #include <assert.h>
#include <stdbool.h>
#include <stdio.h>
typedef unsigned char byte;
struct Transition {
byte a, b;
unsigned int c;
} transitions[100];
void init() {
int i, j;
for (i = 0; i < 10; i++) {
for (j = 0; j < 10; j++) {
int idx = i * 10 + j;
transitions[id... |
parse arg N .
if N=='' | N=="," then N= 1000000
Np= N+1; w= length(N-1)
H= N* (2**max(4, (w%2+1) ) )
@.= .
#= 1
do j=3 by 2; ... |
Write a version of this C function in REXX with identical behavior. | #include <stdio.h>
#include <stdlib.h>
typedef unsigned int uint;
typedef unsigned long long tree;
#define B(x) (1ULL<<(x))
tree *list = 0;
uint cap = 0, len = 0;
uint offset[32] = {0, 1, 0};
void append(tree t)
{
if (len == cap) {
cap = cap ? cap*2 : 2;
list = realloc(list, cap*sizeof(tree));
}
list[len++] =... |
parse arg N .
if N=='' | N=="," then N=5
if N>5 then do; say N "isn't supported for this program at this time."; exit 13; end
nn= N + N - 1
numeric digits 200
numeric digits max(9, 1 + le... |
Produce a functionally identical REXX code for the snippet given in C. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#define LUCKY_SIZE 60000
int luckyOdd[LUCKY_SIZE];
int luckyEven[LUCKY_SIZE];
void compactLucky(int luckyArray[]) {
int i, j, k;
for (i = 0; i < LUCKY_SIZE; i++) {
if (luckyArray[i] == 0) {
j = i;
break;
}
... |
parse arg bot top func _ .
if func=='' then func= 'lucky'
s= left('s', bot\==top & top\==",")
say func 'number's":" bot top '───►' $lucky(bot, top, func, _)
exit 0
$lucky: arg x,y,f,?; if y=='' | y=="," then ... |
Rewrite the snippet below in REXX so it works the same as the original C code. |
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#define NMAX 10000000
double mean(double* values, int n)
{
int i;
double s = 0;
for ( i = 0; i < n; i++ )
s += values[i];
return s / n;
}
double stddev(double* values, int n)
{
int i;
d... |
numeric digits 20
parse arg n seed .
if n=='' | n=="," then n= 10000
if datatype(seed, 'W') then call random ,,seed
call pi
do g=1 for n; #.g= sqrt( -2 * ln( rand() ) ) * c... |
Generate a REXX translation of this C snippet without changing its computational steps. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
__int128 imax(__int128 a, __int128 b) {
if (a > b) {
return a;
}
return b;
}
__int128 ipow(__int128 b, __int128 n) {
__int128 res;
if (n == 0) {
return 1;
}
if (n == 1) {
return b;
}... |
numeric digits 30; w= length( commas( copies(1, digits())))
parse arg list
if list=='' then list= 1..10 95..105 297
say center(' N ', 9, "─") center(' B10 ', w, "─") center(' multiplier ', w, "─")
do i=1 for words(list)
z= word(list, i); LO= z; HI= z
if po... |
Translate this program into REXX but keep the logic exactly as in C. | #include "stdio.h"
#include "stdlib.h"
#include "stdbool.h"
#include "string.h"
struct int_a {
int *ptr;
size_t size;
};
struct int_a divisors(int n) {
int *divs, *divs2, *out;
int i, j, c1 = 0, c2 = 0;
struct int_a array;
divs = malloc(n * sizeof(int) / 2);
divs2 = malloc(n * sizeof(int)... |
parse arg n cols .
if n=='' | n=="," then n= 25
if cols=='' | cols=="," then cols= 10
w= 10
if cols>0 then say ' index │'center(' weird numbers', 1 + cols*(w+1) )
if cols>0 then say '───────┼'center("" ... |
Write the same algorithm in REXX as shown in this C implementation. | #include <stdlib.h>
#include <stdio.h>
#include <string.h>
enum { MAX_ROWS=14, MAX_NAMES=20, NAME_SZ=80 };
char *Lines[MAX_ROWS] = {
" +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
" | ID |",
" +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+",
" |QR| ... |
numeric digits 100
er= '***error*** illegal input txt'
parse arg iFID test .
if iFID=='' | iFID=="," then iFID= 'ASCIIART.TXT'
if test=='' | test=="," then test= 'cafe8050800000808080000a'
w= 0; wb= 0; !.= 0; ... |
Translate the given C code snippet into REXX without altering its behavior. | #include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#define LIMIT 15
int smallPrimes[LIMIT];
static void sieve() {
int i = 2, j;
int p = 5;
smallPrimes[0] = 2;
smallPrimes[1] = 3;
while (i < LIMIT) {
for (j = 0; j < i; j++) {
if (smallPrimes[j] * sma... |
parse arg N .
if N=='' | N=="," then N= 15
if N>=50 then numeric digits 10
w= 50
say '─divisors─' center("the Nth number with exactly N divisors", w, '─')
@.1= 2; ... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <readline/readline.h>
#include <readline/history.h>
#include <string.h>
int main()
{
char *s;
using_history();
while (1) {
s = readline("This be a prompt> ");
if (!s || !strcmp(s, "quit")) {
puts("bye.");
return 0;
}
if (!strcmp(s, "help"))
puts("commands: ls, cat, quit");
else if (!st... |
trace off
signal on syntax; signal on noValue
cmdX='ATTRIB CAL CHDIR COPY DEL DIR ECHO EDIT FC FIND KEDIT LLL MEM MKDIR MORE REM REXX',
'RMDIR SET TYPE VER XCOPY'
cls= 'CLS'
@hist.= '*** command not defi... |
Translate this program into REXX but keep the logic exactly as in C. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct UserInput {
char formFeed;
char lineFeed;
char tab;
char space;
};
struct UserInputNode {
struct UserInput ui;
struct UserInputNode *next;
};
bool decode(FILE *fp, const struct UserInput ui) {
char f = 0, l = 0, t = 0, s =... |
parse arg iFID .
if iFID=='' | iFID=="," then iFID= 'JIT.TXT'
$= 'abcdefghijklmnopqrstuvwxyz'; _=$; upper _; $= "0123456789"$ || _; $$=$ || xrange()
prompt= '────────── enter four positive integers or Quit'
pag=1; lin=1; FF= 'c'x
@.= ... |
Translate this program into REXX but keep the logic exactly as in C. | #include <stdio.h>
#define DEBUG_INT(x) printf( #x " at line %d\nresult: %d\n\n", __LINE__, x)
int add(int x, int y) {
int result = x + y;
DEBUG_INT(x);
DEBUG_INT(y);
DEBUG_INT(result);
DEBUG_INT(result+1);
return result;
}
int main() {
add(2, 7);
return 0;
}
|
trace i
parse arg maxDiv .
if maxDiv=='' | maxDiv=="," then maxDiv= 1000
say 'maximum random divisor is:' maxDiv
total= 0
do j=1 to 100
total= total + j/random(maxDiv)
end
say 'total=' total
|
Translate the given C code snippet into REXX without altering its behavior. | #include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
typedef enum State { READY, WAITING, REFUND, DISPENSE, COLLECT, QUIT } State;
typedef struct statechange {
const int in;
const State out;
} statechange;
#define MAXINPUTS 3
typedef struct FSM {
const State... |
10: say "Press D (deposit) or Q (quit)"
20: $=inkey(); upper $
if $=="D" then signal 50
if $=="Q" then exit
signal 20
50: say "Press S (select) or R (refund)"
60: $=inkey(); ... |
Maintain the same structure and functionality when rewriting this code in REXX. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <locale.h>
bool *primeSieve(int limit) {
int i, p;
limit++;
bool *c = calloc(limit, sizeof(bool));
c[0] = true;
c[1] = true;
for (i = 4; i < limit; i += 2) c[i] = true;
p = 3;
while (true) {
int p2 = p *... |
parse arg n cols tens over .
if n='' | n=="," then n=2000
if cols='' | cols=="," | cols==0 then cols= 10
if tens='' | tens=="," then tens= 0
if over='' | over=="," then over= 20
tell= n>0; n= abs(n)
call genP n * over... |
Rewrite the snippet below in REXX so it works the same as the original C code. | #include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <gmp.h>
mpz_t* partition(uint64_t n) {
mpz_t *pn = (mpz_t *)malloc((n + 2) * sizeof(mpz_t));
mpz_init_set_ui(pn[0], 1);
mpz_init_set_ui(pn[1], 1);
for (uint64_t i = 2; i < n + 2; i ++) {
mpz_init(pn[i]);
for (uint64_t k = 1, ... |
numeric digits 1000
parse arg lo hi .
if lo=='' | lo=="," then lo= 0
if hi=='' | hi=="," then hi= lo
@.= 0; @.0= 1; @.1= 1; @.2= 2; @.3= 3; @.4= 5
!.= @.; !.1= 1; !.3= 1; !.5= 1; !.7= 1; !.9= 1
w= length( commas(h... |
Write the same algorithm in REXX as shown in this C implementation. | #include <stdbool.h>
#include <stdio.h>
int reverse(int n) {
int result = 0;
while (n > 0) {
result = 10 * result + n % 10;
n /= 10;
}
return result;
}
int main() {
const int limit1 = 200;
int row = 0;
int num = 0;
int n;
for (n = 1; n < limit1; n++) {
boo... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 200
if cols=='' | cols=="," then cols= 10
w= 10
title= ' special divisors N that reverse(D) divides reverse(N) for all divisors' ,
' D of N, where N <... |
Please provide an equivalent version of this C code in REXX. | #include <stdio.h>
#include <stdint.h>
uint32_t hpo2(uint32_t n) {
return n & -n;
}
uint32_t lhpo2(uint32_t n) {
uint32_t q = 0, m = hpo2(n);
for (; m % 2 == 0; m >>= 1, ++q) {}
return q;
}
uint32_t nimsum(uint32_t x, uint32_t y) {
return x ^ y;
}
uint32_t nimprod(uint32_t x, uint32_t y) {
... |
numeric digits 40; d= digits() % 8
parse arg sz aa bb .
if sz=='' | sz=="," then sz= 15
if aa=='' | aa=="," then aa= 21508
if bb=='' | bb=="," then bb= 42689
w= max(4,length(sz)); @.= '+'; @.1= "*"; _= '═'
!= '║';... |
Convert this C block to REXX, preserving its control flow and logic. | #include <stdio.h>
#include <stdbool.h>
int digit_set(int n) {
static const int powers[] = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
100000000, 1000000000
};
int dset;
for (dset = 0; n; n /= 10)
dset += powers[n % 10];
return dset;
}
bool is_permuted_mult... |
do n=1
b= 2*n
t= 3*n
if verify(t, b)>0 then iterate
q= 4*n
if verify(q, b)>0 then iterate
if ... |
Translate the given C code snippet into REXX without altering its behavior. | #include <stdio.h>
#include <stdbool.h>
int digit_set(int n) {
static const int powers[] = {
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
100000000, 1000000000
};
int dset;
for (dset = 0; n; n /= 10)
dset += powers[n % 10];
return dset;
}
bool is_permuted_mult... |
do n=1
b= 2*n
t= 3*n
if verify(t, b)>0 then iterate
q= 4*n
if verify(q, b)>0 then iterate
if ... |
Rewrite this program in REXX while keeping its functionality equivalent to the C version. | #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
typedef uint64_t integer;
integer reverse(integer n) {
integer rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
typedef struct palgen_tag {
integer power;
integer next;
int digit;
b... |
numeric digits 20
parse arg palGaps
if palGaps='' then palGaps= 20 100@@15 1000@@10
do until palGaps=''; parse var palGaps stuff palGaps; call palGap stuff
end
exit 0
palGap: pr... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
typedef uint64_t integer;
integer reverse(integer n) {
integer rev = 0;
while (n > 0) {
rev = rev * 10 + (n % 10);
n /= 10;
}
return rev;
}
typedef struct palgen_tag {
integer power;
integer next;
int digit;
b... |
numeric digits 20
parse arg palGaps
if palGaps='' then palGaps= 20 100@@15 1000@@10
do until palGaps=''; parse var palGaps stuff palGaps; call palGap stuff
end
exit 0
palGap: pr... |
Generate a REXX translation of this C snippet without changing its computational steps. | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void) {
int nprimes = 1000000;
int nmax = ceil(nprimes*(log(nprimes)+log(log(nprimes))-0.9385));
int i, j, m, k; int *a;
k = (nmax-2)/2;
a = (int *)calloc(k + 1, sizeof(int));
for(i = 0; i <= k; i++)a[i] = 2*i... |
parse arg n cols .
if n=='' | n=="," then n= 100
if cols=='' | cols=="," then cols= 10
@.= .; lim= 16 * n
do j=1 for n; do k=1 for n until _>lim; _= j + k + 2*j*k; @._=
end
... |
Translate this program into REXX but keep the logic exactly as in C. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
bool *sieve(int limit) {
int i, p;
limit++;
bool *c = calloc(limit, sizeof(bool));
c[0] = true;
c[1] = true;
for (i = 4; i < limit; i += 2) c[i] = true;
p = 3;
while (true) {
int p2 = p * p;
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 1000000
if cols=='' | cols=="," then cols= 10
call genP
w= 10
call fRun 1; call show 1
call fRun 0; call... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <gmp.h>
bool *sieve(int limit) {
int i, p;
limit++;
bool *c = calloc(limit, sizeof(bool));
c[0] = true;
c[1] = true;
for (i = 4; i < limit; i += 2) c[i] = true;
p = 3;
while (true) {
int p2 = p * p;
... |
parse arg oLO oHI hip .
if oLO=='' | oLO=="," then oLO= 1
if oHI=='' | oHI=="," then oHI= 11
if hip=='' | hip=="," then hip= 11000
call genP
!!.= .
bignum= !(hip) ... |
Change the programming language of this snippet from C to REXX without modifying what it does. | #include <stdio.h>
void padovanN(int n, size_t t, int *p) {
int i, j;
if (n < 2 || t < 3) {
for (i = 0; i < t; ++i) p[i] = 1;
return;
}
padovanN(n-1, t, p);
for (i = n + 1; i < t; ++i) {
p[i] = 0;
for (j = i - 2; j >= i - n - 1; --j) p[i] += p[j];
}
}
int main()... |
parse arg n m .
if n=='' | n=="," then n= 15
if m=='' | m=="," then m= 8
w.= 1
do #=2 for m-1
@.= 0; @.0= 1; @.1= 1; @.2= 1
$= @.0 ... |
Port the following code from C to REXX with equivalent syntax and logic. | #include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct {
uint16_t year;
uint8_t month;
uint8_t day;
} Date;
bool leap(uint16_t year) {
return year%4==0 && (year%100!=0 || year%400==0);
}
const char *weekday(Date date) {
static const uint8_t leapdoom[] = {4,1,7,2,4,6,4,1,5,3,7... |
parse arg $
if $='' | $="," then $= ,
'01/06/1800 03/29/1875 12/07/1915 12/23/1970 05/14/2043 04/02/2077 04/02/2101'
d= 'Sun Mon Tues Wednes Thurs Fri Satur'
y.0= 3 7 7 4 2 6 4 1 5 3 7 5
y.1= 4 1 7 4 2 6 4 1 5 3 7 5... |
Translate this program into REXX but keep the logic exactly as in C. | #include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct {
uint16_t year;
uint8_t month;
uint8_t day;
} Date;
bool leap(uint16_t year) {
return year%4==0 && (year%100!=0 || year%400==0);
}
const char *weekday(Date date) {
static const uint8_t leapdoom[] = {4,1,7,2,4,6,4,1,5,3,7... |
parse arg $
if $='' | $="," then $= ,
'01/06/1800 03/29/1875 12/07/1915 12/23/1970 05/14/2043 04/02/2077 04/02/2101'
d= 'Sun Mon Tues Wednes Thurs Fri Satur'
y.0= 3 7 7 4 2 6 4 1 5 3 7 5
y.1= 4 1 7 4 2 6 4 1 5 3 7 5... |
Rewrite this program in REXX while keeping its functionality equivalent to the C version. |
#include <math.h>
int gjinv (double *a, int n, double *b)
{
int i, j, k, p;
double f, g, tol;
if (n < 1) return -1;
f = 0.;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
g = a[j+i*n];
f += g * g;
}
}
f = sqrt(f);
tol = f * 2.2204460492503131e-016;
for (i = 0; i < n; ++i) {
for (j = 0; ... |
Parse Arg seed nn
If seed='' Then
seed=23345
If nn='' Then nn=5
If seed='?' Then Do
Say 'rexx gjmi seed n computes a random matrix with n rows and columns'
Say 'Default is 23345 5'
Exit
End
Numeric Digits 50
Call random 1,2,seed
a=''
Do i=1 To nn**2
a=a random(9)+1
End
n2=words(a)
Do n=2 To n2/2
If n**... |
Ensure the translated REXX code behaves exactly like the original C snippet. |
#include <math.h>
int gjinv (double *a, int n, double *b)
{
int i, j, k, p;
double f, g, tol;
if (n < 1) return -1;
f = 0.;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
g = a[j+i*n];
f += g * g;
}
}
f = sqrt(f);
tol = f * 2.2204460492503131e-016;
for (i = 0; i < n; ++i) {
for (j = 0; ... |
Parse Arg seed nn
If seed='' Then
seed=23345
If nn='' Then nn=5
If seed='?' Then Do
Say 'rexx gjmi seed n computes a random matrix with n rows and columns'
Say 'Default is 23345 5'
Exit
End
Numeric Digits 50
Call random 1,2,seed
a=''
Do i=1 To nn**2
a=a random(9)+1
End
n2=words(a)
Do n=2 To n2/2
If n**... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <stdio.h>
#include <math.h>
typedef struct { double m; double fm; double simp; } triple;
triple _quad_simpsons_mem(double (*f)(double), double a, double fa, double b, double fb) {
double m = (a + b) / 2;
double fm = f(m);
double simp = fabs(b - a) / 6 * (fa + 4*fm + fb);
triple t = {m, ... |
numeric digits length( pi() ) - length(.)
a= 0; b= 1; f= 'SIN'
sinx= quadAsr('SIN',a,b,"1e" || (-digits() + 1) )
say "Simpson's integration of sine from " a ' to ' b ' = ' sinx
exit
pi: pi= 3.1415926535897... |
Convert this C block to REXX, preserving its control flow and logic. | #include <stdio.h>
#include <math.h>
typedef struct { double m; double fm; double simp; } triple;
triple _quad_simpsons_mem(double (*f)(double), double a, double fa, double b, double fb) {
double m = (a + b) / 2;
double fm = f(m);
double simp = fabs(b - a) / 6 * (fa + 4*fm + fb);
triple t = {m, ... |
numeric digits length( pi() ) - length(.)
a= 0; b= 1; f= 'SIN'
sinx= quadAsr('SIN',a,b,"1e" || (-digits() + 1) )
say "Simpson's integration of sine from " a ' to ' b ' = ' sinx
exit
pi: pi= 3.1415926535897... |
Port the provided C code into REXX while preserving the original functionality. | #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
typedef int bool;
char grid[8][8];
void placeKings() {
int r1, r2, c1, c2;
for (;;) {
r1 = rand() % 8;
c1 = rand() % 8;
r2 = rand() % 8;
c2 = rand() %... |
parse arg seed CBs .
if datatype(seed,'W') then call random ,,seed
if CBs=='' | CBs=="," then CBs=1
do boards=1 for abs(CBs)
if sign(CBs)\==CBs then do; say; say center(' board' board... |
Produce a functionally identical REXX code for the snippet given in C. | #include <math.h>
#include <stdint.h>
#include <stdio.h>
uint64_t factorial(int n) {
uint64_t result = 1;
int i;
for (i = 1; i <= n; i++) {
result *= i;
}
return result;
}
int inverse_factorial(uint64_t f) {
int p = 1;
int i = 1;
if (f == 1) {
return 0;
}
... |
numeric digits 1000
call hdr 'super'; do j=0 to 9; $= $ sf(j); end; call tell
call hdr 'hyper'; do j=0 to 9; $= $ hf(j); end; call tell
call hdr 'alternating '; do j=0 to 9; $= $ af(j); end; call tell
call hdr 'exp... |
Convert this C block to REXX, preserving its control flow and logic. | #include <ctype.h>
#include <locale.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
#include <glib.h>
typedef uint64_t integer;
typedef struct number_names_tag {
const char* cardinal;
const char* ordinal;
} number_names;
const number_names small[] = {
{ "zero", "zeroth" }, { "one", "first"... |
@= 'Four is the number of letters in the first word of this sentence,'
parse arg N M
if N='' | N="," then N= 201
if M='' | M="," then M=1000 10000 100000 1000000
@abcU= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'... |
Translate this program into REXX but keep the logic exactly as in C. |
#include<stdio.h>
#define Hi printf("Hi There.");
#define start int main(){
#define end return 0;}
start
Hi
#warning "Don't you have anything better to do ?"
#ifdef __unix__
#warning "What are you doing still working on Unix ?"
printf("\nThis is an Unix system.");
#elif _WIN32
#warning "You couldn't afford ... | options wordlist;
|
Maintain the same structure and functionality when rewriting this code in REXX. | char input[] = "top1 des1 ip1 ip2\n"
"top2 des1 ip2 ip3\n"
"ip1 extra1 ip1a ipcommon\n"
"ip2 ip2a ip2b ip2c ipcommon\n"
"des1 des1a des1b des1c\n"
"des1a des1a1 des1a2\n"
"des1c des1c1 extra1\n";
...
int find_name(item base, int len, const char *name)
{
int i;
for (i = 0; i < len; i+... |
parse arg job
jobL.=; stage.=; #.=0; @.=; JL=
tree.=; tree.1= ' top1 des1 ip1 ip2 '
tree.2= ' top2 des1 ip2 ip3 '
tree.3= ... |
Change the programming language of this snippet from C to REXX without modifying what it does. | char input[] = "top1 des1 ip1 ip2\n"
"top2 des1 ip2 ip3\n"
"ip1 extra1 ip1a ipcommon\n"
"ip2 ip2a ip2b ip2c ipcommon\n"
"des1 des1a des1b des1c\n"
"des1a des1a1 des1a2\n"
"des1c des1c1 extra1\n";
...
int find_name(item base, int len, const char *name)
{
int i;
for (i = 0; i < len; i+... |
parse arg job
jobL.=; stage.=; #.=0; @.=; JL=
tree.=; tree.1= ' top1 des1 ip1 ip2 '
tree.2= ' top2 des1 ip2 ip3 '
tree.3= ... |
Transform the following C implementation into REXX, maintaining the same output and logic. | #include <math.h>
#include <stdio.h>
#define nelems(x) (sizeof(x) / sizeof((x)[0]))
const unsigned long multiplier[] = {1, 3, 5, 7, 11, 3*5, 3*7, 3*11, 5*7, 5*11, 7*11, 3*5*7, 3*5*11, 3*7*11, 5*7*11, 3*5*7*11};
unsigned long long gcd(unsigned long long a, unsigned long long b)
{
while (b != 0)
{
a %=... |
numeric digits 100
call dMults 1,3,5,7,11,3*5,3*7,3*11,5*7,5*11,7*11, 3*5*7, 3*5*11, 3*7*11, 5*7*11, 3*5*7*11
call dTests 2501, 12851, 13289, 75301, 120787, 967009, 997417, 7091569, 13290059, ,
42854447, 223553581, 2027651281, 11111111111, 100895598169, 10027... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
#define ESC 27
#define TEST TRUE
typedef int bool;
int get_number(const char *prompt, int min, int max, bool show_mm) {
int n;
char *line = NULL;
size_t len = 0;
ssize_t read;
fflush(stdin);
do {
... |
parse arg seed .; if datatype(seed, 'W') then call random ,,seed
__= copies('─', 9)
do forever
do until $pot+3<$g; $pot = random(0, 3)
$g = random(0, 6)
end
say
say copies('─', 55); ... |
Write the same code in REXX as shown below in C. | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define TRUE 1
#define FALSE 0
#define ESC 27
#define TEST TRUE
typedef int bool;
int get_number(const char *prompt, int min, int max, bool show_mm) {
int n;
char *line = NULL;
size_t len = 0;
ssize_t read;
fflush(stdin);
do {
... |
parse arg seed .; if datatype(seed, 'W') then call random ,,seed
__= copies('─', 9)
do forever
do until $pot+3<$g; $pot = random(0, 3)
$g = random(0, 6)
end
say
say copies('─', 55); ... |
Transform the following C implementation into REXX, maintaining the same output and logic. |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "wren.h"
struct MemoryStruct {
char *memory;
size_t size;
};
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
struct MemoryStruct *m... |
parse arg catFID lanFID outFID .
call init
call get
call eSort #,0
call tSort
call eSort #,1
call out ... |
Write a version of this C function in REXX with identical behavior. |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <curl/curl.h>
#include "wren.h"
struct MemoryStruct {
char *memory;
size_t size;
};
static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) {
size_t realsize = size * nmemb;
struct MemoryStruct *m... |
parse arg catFID lanFID outFID .
call init
call get
call eSort #,0
call tSort
call eSort #,1
call out ... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
#ifndef min
#define min(x, y) ((x)<(y) ? (x) : (y))
#endif
struct edge {
void *from;
void *to;
};
struct components {
int nnodes;
void **nodes;
struct components *next;
};
struct node {
int index;
int lowlink;
bool onStack;
void *data;
};
struct... |
g='[2] [3] [1] [2 3 5] [4 6] [3 7] [6] [5 7 8]'
gg=g
Do i=1 By 1 While gg>''
Parse Var gg '[' g.i ']' gg
name.i=i-1
End
g.0=i-1
index.=0
lowlink.=0
stacked.=0
stack.=0
x=1
Do n=1 To g.0
If index.n=0 Then
If strong_connect(n)=0 Then
Return
End
Exit
strong_connect: Procedure Expose x g. index. lowl... |
Keep all operations the same but rewrite the snippet in Pascal. | package main
import "fmt"
var (
Nr = [16]int{3, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3}
Nc = [16]int{3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2}
)
var (
n, _n int
N0, N3, N4 [85]int
N2 [85]uint64
)
const (
i = 1
g = 8
e = 2
l = 4
)
func fY() bool {
if N... | unit FifteenSolverT;
\\ Solve 15 Puzzle. Nigel Galloway; February 1st., 2019.
interface
type TN=record n:UInt64; i,g,e,l:shortint; end;
type TG=record found:boolean; path:array[0..99] of TN; end;
function solve15(const board : UInt64; const bPos:shortint; const d:shortint; const ng:shortint):TG;
const endPos:UInt64=$12... |
Port the following code from Go to Pascal with equivalent syntax and logic. | package main
import (
"fmt"
"unsafe"
)
func main() {
myVar := 3.14
myPointer := &myVar
fmt.Println("Address:", myPointer, &myVar)
fmt.Printf("Address: %p %p\n", myPointer, &myVar)
var addr64 int64
var addr32 int32
ptr := unsafe.Pointer(myPointer)
if unsafe.Sizeof(ptr) <= unsafe.Sizeof(addr64) {
addr64 = ... | var
i: integer;
p: ^integer;
begin
p := @i;
writeLn(p^);
end;
|
Port the provided Go code into Pascal while preserving the original functionality. | package main
import (
"fmt"
"log"
"os"
"os/exec"
)
func reverseBytes(bytes []byte) {
for i, j := 0, len(bytes)-1; i < j; i, j = i+1, j-1 {
bytes[i], bytes[j] = bytes[j], bytes[i]
}
}
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
in, err ... | program reverseFixedLines(input, output, stdErr);
const
lineLength = 80;
var
line: string[lineLength];
i: integer;
begin
while not eof() do
begin
for i := 1 to lineLength do
begin
read(line[i]);
end;
for i := lineLength downto 1 do
begin
write(line[i]);
end;
writeLn();
end;
end.
|
Write a version of this Go function in Pascal with identical behavior. | package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"unicode/utf8"
)
func contains(list []int, value int) bool {
for _, v := range list {
if v == value {
return true
}
}
return false
}
func main() {
wordList := "unixdict.txt"
b, err := ioutil.Read... | begin % find the words longer than 10 characters that contain most consonants %
% an element of a WordList %
record WordListElement ( string(32) w; reference(WordListElement) next );
% structure to hold lists of words %
record WordList ( reference(WordListElement) first, last );
% lists of words ind... |
Translate this program into Pascal but keep the logic exactly as in Go. | package main
import (
"bytes"
"fmt"
"math/rand"
"time"
)
type maze struct {
c2 [][]byte
h2 [][]byte
v2 [][]byte
}
func newMaze(rows, cols int) *maze {
c := make([]byte, rows*cols)
h := bytes.Repeat([]byte{'-'}, rows*cols)
v := bytes.Repeat([]byte{'|'}, rows... | procedure SolveMaze(var AMaze: TMaze; const S, E: TPoint);
var
Route : TRoute;
Position : TPoint;
V : TPoint;
begin
ClearVisited(AMaze);
Position := S;
Route := TStack<TPoint>.Create;
with Position do
try
AMaze[x, y].Visited := True;
repeat
if (y > 0) and not AMaze[x,... |
Write a version of this Go function in Pascal with identical behavior. | package main
import "fmt"
func main() {
for {
fmt.Printf("SPAM\n")
}
}
| while true do
writeln('SPAM');
|
Translate the given Go code snippet into Pascal without altering its behavior. | package main
import (
"fmt"
"math"
)
type float float64
func (f float) p(e float) float { return float(math.Pow(float64(f), float64(e))) }
func main() {
ops := []string{"-x.p(e)", "-(x).p(e)", "(-x).p(e)", "-(x.p(e))"}
for _, x := range []float{float(-5), float(5)} {
for _, e := range []floa... | program exponentiationWithInfixOperatorsInTheBase(output);
const
minimumWidth = 7;
fractionDigits = minimumWidth div 4 + 1;
procedure testIntegerPower(
protected base: integer;
protected exponent: integer
);
begin
writeLn('=====> testIntegerPower <=====');
writeLn(' base = ', base:minimu... |
Please provide an equivalent version of this Go code in Pascal. | package main
import (
"fmt"
"math"
)
type float float64
func (f float) p(e float) float { return float(math.Pow(float64(f), float64(e))) }
func main() {
ops := []string{"-x.p(e)", "-(x).p(e)", "(-x).p(e)", "-(x.p(e))"}
for _, x := range []float{float(-5), float(5)} {
for _, e := range []floa... | program exponentiationWithInfixOperatorsInTheBase(output);
const
minimumWidth = 7;
fractionDigits = minimumWidth div 4 + 1;
procedure testIntegerPower(
protected base: integer;
protected exponent: integer
);
begin
writeLn('=====> testIntegerPower <=====');
writeLn(' base = ', base:minimu... |
Write a version of this Go function in Pascal with identical behavior. | package main
import (
"fmt"
"runtime"
"sync"
)
func main() {
p := sync.Pool{New: func() interface{} {
fmt.Println("pool empty")
return new(int)
}}
i := new(int)
j := new(int)
*i = 1
*j = 2
fmt.Println(*i + *j)
p.P... | procedure New (var P: Pointer);
|
Convert this Go block to Pascal, preserving its control flow and logic. | package main
import (
"fmt"
"runtime"
"sync"
)
func main() {
p := sync.Pool{New: func() interface{} {
fmt.Println("pool empty")
return new(int)
}}
i := new(int)
j := new(int)
*i = 1
*j = 2
fmt.Println(*i + *j)
p.P... | procedure New (var P: Pointer);
|
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"runtime"
)
func main() {
fileName1 := "rodgers.txt"
fileName2 := "rodgers_reversed.txt"
lineBreak := "\n"
if runtime.GOOS == "windows" {
lineBreak = "\r\n"
}
b, err := ioutil.ReadFile(fileName1)
if err ... | program TAC;
uses
sysutils, classes;
var
Sl:TStringList;
i,j : nativeInt;
begin
Sl := TStringList.Create;
Sl.Loadfromfile('Rodgers.txt');
i := 0;
j := Sl.Count-1;
While i<j do
Begin
Sl.Exchange(i,j);
inc(i);
dec(j);
end;
writeln(Sl.text);
end.
|
Please provide an equivalent version of this Go code in Pascal. | func multiply(a, b float64) float64 {
return a * b
}
| function multiply(a, b: real): real;
begin
multiply := a * b
end;
|
Preserve the algorithm and functionality while converting the code from Go to Pascal. | package main
import (
"fmt"
"rcu"
)
func main() {
fmt.Println("Decimal numbers under 1,000 whose digits include two 1's:")
var results []int
for i := 11; i <= 911; i++ {
digits := rcu.Digits(i, 10)
count := 0
for _, d := range digits {
if d == 1 {
... | program positiveDecimalIntegersWithTheDigit1occurringExactlyTwice(output);
var
n: integer;
begin
for n := 1 to 999 do
begin
if ord(n mod 10 = 1) + ord(n mod 100 div 10 = 1) + ord(n div 100 = 1) = 2 then
begin
writeLn(n)
end
end
end.
|
Produce a functionally identical Pascal code for the snippet given in Go. | package main
import (
"fmt"
"sort"
)
func main() {
strings := []string{"1a3c52debeffd", "2b6178c97a938stf", "3ycxdb1fgxa2yz"}
u := make(map[rune]int)
for _, s := range strings {
m := make(map[rune]int)
for _, c := range s {
m[c]++
}
for k, v := range m {... | program uniqueCharactersInEachString(output);
type
message = string(16);
characters = set of char;
function uniqueCharacters(protected sample: message): characters;
var
i: 1..sample.capacity;
firstOccurence, nonFirstOccurence: characters value [];
begin
for i := 1 to length(sample) do
begin
nonFi... |
Write a version of this Go function in Pascal with identical behavior. | package main
import "fmt"
func sieve(limit int) []bool {
limit++
c := make([]bool, limit)
c[0] = true
c[1] = true
p := 3
for {
p2 := p * p
if p2 >= limit {
break
}
for i := p2; i < limit; i += 2 * p {
c[i] = true
}
... | program NextSpecialprimes;
uses
sysutils,
primTrial;
procedure GetIncreasingGaps;
var
Gap,LastPrime,p : NativeUInt;
Begin
InitPrime;
Writeln('next increasing prime gap');
writeln('Prime1':8,'Prime2':8,'Gap':4);
Gap := 0;
LastPrime := actPrime;
repeat
p := NextPrime;
if p-LastPrime > Gap the... |
Write a version of this Go function in Pascal with identical behavior. | package main
import "fmt"
func sieve(limit int) []bool {
limit++
c := make([]bool, limit)
c[0] = true
c[1] = true
p := 3
for {
p2 := p * p
if p2 >= limit {
break
}
for i := p2; i < limit; i += 2 * p {
c[i] = true
}
... | program NextSpecialprimes;
uses
sysutils,
primTrial;
procedure GetIncreasingGaps;
var
Gap,LastPrime,p : NativeUInt;
Begin
InitPrime;
Writeln('next increasing prime gap');
writeln('Prime1':8,'Prime2':8,'Gap':4);
Gap := 0;
LastPrime := actPrime;
repeat
p := NextPrime;
if p-LastPrime > Gap the... |
Convert the following code from Go to Pascal, ensuring the logic remains intact. | package main
import (
"fmt"
"math/big"
"rcu"
)
func main() {
count := 0
limit := 25
n := int64(17)
repunit := big.NewInt(1111111111111111)
t := new(big.Int)
zero := new(big.Int)
eleven := big.NewInt(11)
hundred := big.NewInt(100)
var deceptive []int64
for count < li... | program DeceptiveNumbers;
uses
sysutils;
const
LIMIT = 100000;
RepInitLen = 13;
DecimalDigits = 10*1000*1000*1000*1000;
RepLimit = (DecimalDigits-1)DIV 9;
type
tmyUint64 = array[0..Limit DIV RepInitLen+1] of Uint64;
var
K: tmyUint64;
MaxKIdx : Int32;
procedure OutK(const K:tmyUint64);
var... |
Convert the following code from Go to Pascal, ensuring the logic remains intact. | package main
import (
"fmt"
"math/big"
"rcu"
)
func main() {
count := 0
limit := 25
n := int64(17)
repunit := big.NewInt(1111111111111111)
t := new(big.Int)
zero := new(big.Int)
eleven := big.NewInt(11)
hundred := big.NewInt(100)
var deceptive []int64
for count < li... | program DeceptiveNumbers;
uses
sysutils;
const
LIMIT = 100000;
RepInitLen = 13;
DecimalDigits = 10*1000*1000*1000*1000;
RepLimit = (DecimalDigits-1)DIV 9;
type
tmyUint64 = array[0..Limit DIV RepInitLen+1] of Uint64;
var
K: tmyUint64;
MaxKIdx : Int32;
procedure OutK(const K:tmyUint64);
var... |
Change the following Go code into Pascal without altering its purpose. | package main
import (
"math/rand"
"fmt"
)
func main() {
list := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for i := 1; i <= 10; i++ {
sattoloCycle(list)
fmt.Println(list)
}
}
func sattoloCycle(list []int) {
for x := len(list) -1; x > 0; x-- {
j := rand.Intn(x)
list[x], list[j] = list[j], list[x]
}
}
| program sattolocycle;
uses math;
var
a:Array of cardinal = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
i,j:integer;
t:cardinal;
begin
randomize;
i := length(a);
while i > 1 do
begin
dec(i);
j :=randomrange(0,i);
t:=a[i];a[i]:=a[j];a[j]:=t;
write(a[i]:4);
end;
writeln;
end.... |
Write the same code in Pascal as shown below in Go. | package main
import (
"math/rand"
"fmt"
)
func main() {
list := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
for i := 1; i <= 10; i++ {
sattoloCycle(list)
fmt.Println(list)
}
}
func sattoloCycle(list []int) {
for x := len(list) -1; x > 0; x-- {
j := rand.Intn(x)
list[x], list[j] = list[j], list[x]
}
}
| program sattolocycle;
uses math;
var
a:Array of cardinal = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19];
i,j:integer;
t:cardinal;
begin
randomize;
i := length(a);
while i > 1 do
begin
dec(i);
j :=randomrange(0,i);
t:=a[i];a[i]:=a[j];a[j]:=t;
write(a[i]:4);
end;
writeln;
end.... |
Maintain the same structure and functionality when rewriting this code in Pascal. | package main
import "fmt"
func sameDigits(n, b int) bool {
f := n % b
n /= b
for n > 0 {
if n%b != f {
return false
}
n /= b
}
return true
}
func isBrazilian(n int) bool {
if n < 7 {
return false
}
if n%2 == 0 && n >= 8 {
return true... | program brazilianNumbers;
uses
SysUtils;
const
PrimeMarker = 0;
SquareMarker = PrimeMarker + 1;
MAX = 1053421821;
var
isprime: array of word;
procedure MarkSmallestFactor;
var
i, j, lmt: NativeUint;
begin
lmt := High(isPrime);
fillWord(isPrime[0], lmt + 1... |
Can you help me rewrite this code in Pascal instead of Go, keeping it the same logically? | package main
import "fmt"
func sameDigits(n, b int) bool {
f := n % b
n /= b
for n > 0 {
if n%b != f {
return false
}
n /= b
}
return true
}
func isBrazilian(n int) bool {
if n < 7 {
return false
}
if n%2 == 0 && n >= 8 {
return true... | program brazilianNumbers;
uses
SysUtils;
const
PrimeMarker = 0;
SquareMarker = PrimeMarker + 1;
MAX = 1053421821;
var
isprime: array of word;
procedure MarkSmallestFactor;
var
i, j, lmt: NativeUint;
begin
lmt := High(isPrime);
fillWord(isPrime[0], lmt + 1... |
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. | package main
import (
"fmt"
"strconv"
)
func main() {
var fact [12]uint64
fact[0] = 1
for n := uint64(1); n < 12; n++ {
fact[n] = fact[n-1] * n
}
for b := 9; b <= 12; b++ {
fmt.Printf("The factorions for base %d are:\n", b)
for i := uint64(1); i < 1500000; i++... | program munchhausennumber;
uses
sysutils;
type
tdigit = byte;
const
MAXBASE = 17;
var
DgtPotDgt : array[0..MAXBASE-1] of NativeUint;
dgtCnt : array[0..MAXBASE-1] of NativeInt;
cnt: NativeUint;
function convertToString(n:NativeUint;base:byte):AnsiString;
const
cBASEDIGITS = '0123456789ABCDEFGHIJKLMNOPQ... |
Write the same code in Pascal as shown below in Go. | package main
import (
"fmt"
"strconv"
)
func main() {
var fact [12]uint64
fact[0] = 1
for n := uint64(1); n < 12; n++ {
fact[n] = fact[n-1] * n
}
for b := 9; b <= 12; b++ {
fmt.Printf("The factorions for base %d are:\n", b)
for i := uint64(1); i < 1500000; i++... | program munchhausennumber;
uses
sysutils;
type
tdigit = byte;
const
MAXBASE = 17;
var
DgtPotDgt : array[0..MAXBASE-1] of NativeUint;
dgtCnt : array[0..MAXBASE-1] of NativeInt;
cnt: NativeUint;
function convertToString(n:NativeUint;base:byte):AnsiString;
const
cBASEDIGITS = '0123456789ABCDEFGHIJKLMNOPQ... |
Translate the given Go code snippet into Pascal without altering its behavior. | package main
import "fmt"
func sumDivisors(n int) int {
sum := 0
i := 1
k := 2
if n%2 == 0 {
k = 1
}
for i*i <= n {
if n%i == 0 {
sum += i
j := n / i
if j != i {
sum += j
}
}
i += k
}
return... | program Sum_of_divisors;
}
uses
System.SysUtils;
function DivisorSum(n: Cardinal): Cardinal;
var
i,quot,total: Cardinal;
begin
total :=n+1;
i := 2;
repeat
quot := n div i;
if quot <= i then
BREAK;
if quot*i = n then
inc(total,i+quot);
inc(i);
until false;
if i... |
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import "fmt"
func sumDivisors(n int) int {
sum := 0
i := 1
k := 2
if n%2 == 0 {
k = 1
}
for i*i <= n {
if n%i == 0 {
sum += i
j := n / i
if j != i {
sum += j
}
}
i += k
}
return... | program Sum_of_divisors;
}
uses
System.SysUtils;
function DivisorSum(n: Cardinal): Cardinal;
var
i,quot,total: Cardinal;
begin
total :=n+1;
i := 2;
repeat
quot := n div i;
if quot <= i then
BREAK;
if quot*i = n then
inc(total,i+quot);
inc(i);
until false;
if i... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import (
"fmt"
"sync"
)
var a = []int{170, 45, 75, 90, 802, 24, 2, 66}
var aMax = 1000
const bead = 'o'
func main() {
fmt.Println("before:", a)
beadSort()
fmt.Println("after: ", a)
}
func beadSort() {
all := make([]byte, aMax*len(a))
abacus := make([][]byte, ... | program BDS;
const MAX = 1000;
type
type_matrix = record
lin,col:integer;
matrix: array [1..MAX,1..MAX] of boolean;
end;
type_vector = record
size:integer;
vector: array[1..MAX] of integer;
end;
procedure BeadSort(var v:type_vector);
var
i,j,k,sum:integer;
m:type_matrix;
begin
m.lin:=... |
Translate this program into Pascal but keep the logic exactly as in Go. | package main
import (
"fmt"
"log"
"strconv"
)
func co9Peterson(base int) (cob func(string) (byte, error), err error) {
if base < 2 || base > 36 {
return nil, fmt.Errorf("co9Peterson: %d invalid base", base)
}
addDigits := func(a, b byte) (string, error) {... | program castout9;
uses generics.collections;
type
TIntegerList = TSortedList<integer>;
procedure co9(const start,base,lim:integer;kaprekars:array of integer);
var
C1:integer = 0;
C2:integer = 0;
S:TIntegerlist;
k,i:integer;
begin
S:=TIntegerlist.Create;
for k := start to lim do
begin
inc(C1);
... |
Convert this Go block to Pascal, preserving its control flow and logic. | package main
import (
"fmt"
"log"
"strconv"
)
func co9Peterson(base int) (cob func(string) (byte, error), err error) {
if base < 2 || base > 36 {
return nil, fmt.Errorf("co9Peterson: %d invalid base", base)
}
addDigits := func(a, b byte) (string, error) {... | program castout9;
uses generics.collections;
type
TIntegerList = TSortedList<integer>;
procedure co9(const start,base,lim:integer;kaprekars:array of integer);
var
C1:integer = 0;
C2:integer = 0;
S:TIntegerlist;
k,i:integer;
begin
S:=TIntegerlist.Create;
for k := start to lim do
begin
inc(C1);
... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import "fmt"
func countDivisors(n int) int {
count := 0
i := 1
k := 2
if n%2 == 0 {
k = 1
}
for i*i <= n {
if n%i == 0 {
count++
j := n / i
if j != i {
count++
}
}
i += k
}
retu... | begin % find the count of the divisors of the first 100 positive integers %
% calculates the number of divisors of v %
integer procedure divisor_count( integer value v ) ; begin
integer total, n, p;
total := 1; n := v;
% Deal with powers of 2 first %
... |
Generate an equivalent Pascal version of this Go code. | package main
import "fmt"
func countDivisors(n int) int {
count := 0
i := 1
k := 2
if n%2 == 0 {
k = 1
}
for i*i <= n {
if n%i == 0 {
count++
j := n / i
if j != i {
count++
}
}
i += k
}
retu... | begin % find the count of the divisors of the first 100 positive integers %
% calculates the number of divisors of v %
integer procedure divisor_count( integer value v ) ; begin
integer total, n, p;
total := 1; n := v;
% Deal with powers of 2 first %
... |
Ensure the translated Pascal code behaves exactly like the original Go snippet. | package main
import "fmt"
func main() {
bf(10, `++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++
++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>>
>+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++.
<+++++++.--------.<<<<<+.<+++.---.`)
}
func bf(dLen int, is string) {
ds := make([]byt... | program rcExceuteBrainF;
uses
Crt;
Const
DataSize= 1024;
MaxNest= 1000;
procedure ExecuteBF(Source: string);
var
Dp: pByte;
DataSeg: Pointer;
Ip: pChar;
Las... |
Produce a language-to-language conversion: from Go to Pascal, same semantics. | package main
import "fmt"
func main() {
bf(10, `++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++
++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>>
>+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++.
<+++++++.--------.<<<<<+.<+++.---.`)
}
func bf(dLen int, is string) {
ds := make([]byt... | program rcExceuteBrainF;
uses
Crt;
Const
DataSize= 1024;
MaxNest= 1000;
procedure ExecuteBF(Source: string);
var
Dp: pByte;
DataSeg: Pointer;
Ip: pChar;
Las... |
Port the provided Go code into Pascal while preserving the original functionality. | package main
import (
"fmt"
"math/big"
)
func main() {
zero := big.NewInt(0)
one := big.NewInt(1)
for k := int64(2); k <= 10; k += 2 {
bk := big.NewInt(k)
fmt.Println("The first 50 Curzon numbers using a base of", k, ":")
count := 0
n := int64(1)
pow := big.... | program CurzonNumbers;
uses SysUtils;
const
MAX_CURZON_MEG = 100;
RC_LINE_LENGTH = 66;
procedure ListCurzonNumbers( base : integer);
var
k, n, m, x, testBit, maxCurzon : uint64;
nrHits : integer;
lineOut : string;
begin
maxCurzon := 1000000*MAX_CURZON_MEG;
k := uint64( base);
nrHits := 0;
n := 0;
W... |
Maintain the same structure and functionality when rewriting this code in Pascal. | package main
import (
"fmt"
"math/big"
)
func main() {
zero := big.NewInt(0)
one := big.NewInt(1)
for k := int64(2); k <= 10; k += 2 {
bk := big.NewInt(k)
fmt.Println("The first 50 Curzon numbers using a base of", k, ":")
count := 0
n := int64(1)
pow := big.... | program CurzonNumbers;
uses SysUtils;
const
MAX_CURZON_MEG = 100;
RC_LINE_LENGTH = 66;
procedure ListCurzonNumbers( base : integer);
var
k, n, m, x, testBit, maxCurzon : uint64;
nrHits : integer;
lineOut : string;
begin
maxCurzon := 1000000*MAX_CURZON_MEG;
k := uint64( base);
nrHits := 0;
n := 0;
W... |
Port the following code from Go to Pascal with equivalent syntax and logic. | package main
import "fmt"
func mertens(to int) ([]int, int, int) {
if to < 1 {
to = 1
}
merts := make([]int, to+1)
primes := []int{2}
var sum, zeros, crosses int
for i := 1; i <= to; i++ {
j := i
cp := 0
spf := false
for _, p := range primes {
... | program Merten;
uses
sysutils;
const
BigLimit = 10*1000*1000*1000;
type
tSieveElement = Int8;
tpSieve = pInt8;
tMoebVal = array[-1..1] of Int64;
var
MertensValues : array[-40000..50500] of NativeInt;
primes : array of byte;
sieve : array of tSieveElement;
procedure CompactPrimes;
var
... |
Change the programming language of this snippet from Go to Pascal without modifying what it does. | package main
import (
"fmt"
"rcu"
)
func main() {
limit := int(1e6)
lowerLimit := 2500
c := rcu.PrimeSieve(limit-1, true)
var erdos []int
lastErdos := 0
ec := 0
for i := 2; i < limit; {
if !c[i] {
found := true
for j, fact := 1, 1; fact < i; {
... | var p, c, z, k, isprime, factk, iskchecked;
procedure checkprimality;
var i, isichecked;
begin
isprime := 0;
if z = 2 then isprime := 1;
if z >= 3 then
begin
i := 2; isichecked := 0;
while isichecked = 0 do
begin
if (z / i) * i = z then isichecked := 1;
if isichecked = 0 then
if... |
Transform the following Go implementation into Pascal, maintaining the same output and logic. | package main
import (
"fmt"
"rcu"
)
func main() {
limit := int(1e6)
lowerLimit := 2500
c := rcu.PrimeSieve(limit-1, true)
var erdos []int
lastErdos := 0
ec := 0
for i := 2; i < limit; {
if !c[i] {
found := true
for j, fact := 1, 1; fact < i; {
... | var p, c, z, k, isprime, factk, iskchecked;
procedure checkprimality;
var i, isichecked;
begin
isprime := 0;
if z = 2 then isprime := 1;
if z >= 3 then
begin
i := 2; isichecked := 0;
while isichecked = 0 do
begin
if (z / i) * i = z then isichecked := 1;
if isichecked = 0 then
if... |
Change the programming language of this snippet from Go to Pascal without modifying what it does. | package main;func main(){print("Code Golf")}
| var a:QWord=$006F472065646F43;b:DWord=$0000666C;BEGIN write(pChar(@a),pChar(@b));END.
|
Change the programming language of this snippet from Go to Pascal without modifying what it does. | package main;func main(){print("Code Golf")}
| var a:QWord=$006F472065646F43;b:DWord=$0000666C;BEGIN write(pChar(@a),pChar(@b));END.
|
Rewrite this program in Pascal while keeping its functionality equivalent to the Go version. | package main
import "fmt"
func gcd(n, k int) int {
if n < k || k < 1 {
panic("Need n >= k and k >= 1")
}
s := 1
for n&1 == 0 && k&1 == 0 {
n >>= 1
k >>= 1
s <<= 1
}
t := n
if n&1 != 0 {
t = -k
}
for t != 0 {
for t&1 == 0 {
... | program Perftotient;
uses
sysutils;
const
cLimit = 57395631;
var
TotientList : array of LongWord;
Sieve : Array of byte;
SolList : array of LongWord;
T1,T0 : INt64;
procedure SieveInit(svLimit:NativeUint);
var
pSieve:pByte;
i,j,pr :NativeUint;
Begin
svlimit := (svLimit+1) DIV 2;
setlength(si... |
Port the provided Go code into Pascal while preserving the original functionality. | package main
import "fmt"
func gcd(n, k int) int {
if n < k || k < 1 {
panic("Need n >= k and k >= 1")
}
s := 1
for n&1 == 0 && k&1 == 0 {
n >>= 1
k >>= 1
s <<= 1
}
t := n
if n&1 != 0 {
t = -k
}
for t != 0 {
for t&1 == 0 {
... | program Perftotient;
uses
sysutils;
const
cLimit = 57395631;
var
TotientList : array of LongWord;
Sieve : Array of byte;
SolList : array of LongWord;
T1,T0 : INt64;
procedure SieveInit(svLimit:NativeUint);
var
pSieve:pByte;
i,j,pr :NativeUint;
Begin
svlimit := (svLimit+1) DIV 2;
setlength(si... |
Produce a language-to-language conversion: from Go to Pascal, same semantics. | package main
import "fmt"
func twoSum(a []int, targetSum int) (int, int, bool) {
len := len(a)
if len < 2 {
return 0, 0, false
}
for i := 0; i < len - 1; i++ {
if a[i] <= targetSum {
for j := i + 1; j < len; j++ {
sum := a[i] + a[j]
if sum ==... | program twosum;
uses
sysutils;
type
tSolRec = record
SolRecI,
SolRecJ : NativeInt;
end;
tMyArray = array of NativeInt;
const
ConstArray :array[-17..-13] of NativeInt = (0, 2, 11, 19, 90);
function Check2SumUnSorted(const A :tMyArray;
... |
Generate a Pascal translation of this Go snippet without changing its computational steps. | package main
import "fmt"
func twoSum(a []int, targetSum int) (int, int, bool) {
len := len(a)
if len < 2 {
return 0, 0, false
}
for i := 0; i < len - 1; i++ {
if a[i] <= targetSum {
for j := i + 1; j < len; j++ {
sum := a[i] + a[j]
if sum ==... | program twosum;
uses
sysutils;
type
tSolRec = record
SolRecI,
SolRecJ : NativeInt;
end;
tMyArray = array of NativeInt;
const
ConstArray :array[-17..-13] of NativeInt = (0, 2, 11, 19, 90);
function Check2SumUnSorted(const A :tMyArray;
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.