Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Keep all operations the same but rewrite the snippet in REXX. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
bool sixesThrowAgain = true;
void init() {
srand((unsigned int)time(NULL));
}
int rollDice() {
return rand() % 6 + 1;
}
int nextSquare(int square) {
switch (square) {
case 4: return 14;
case 9: return 31;
case ... |
parse arg np seed .
if np=='' | np=="," then np= 3
if datatype(seed, 'W') then call random ,,seed
pad= left('',7)
do k=1 for 100; @.k= k
end
... |
Maintain the same structure and functionality when rewriting this code in REXX. | O_RDONLY, O_WRONLY, or O_RDWR. O_CREAT, O_EXCL, O_NOCTTY, and O_TRUNC
| w=length(abc)
|
Transform the following C implementation into REXX, maintaining the same output and logic. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void farey(int n)
{
typedef struct { int d, n; } frac;
frac f1 = {0, 1}, f2 = {1, n}, t;
int k;
printf("%d/%d %d/%d", 0, 1, 1, n);
while (f2.n > 1) {
k = (n + f1.n) / f2.n;
t = f1, f1 = f2, f2 = (frac) { f2.d * k - t.d, f2.n * k - t.n };
printf(" %... |
parse arg LO HI INC .
if LO=='' | LO=="," then LO= 1
if HI=='' | HI=="," then HI= LO
if INC=='' | INC=="," then INC= 1
sw= linesize() - 1
oLO= LO
do j=abs(LO)... |
Translate the given C code snippet into REXX without altering its behavior. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
void farey(int n)
{
typedef struct { int d, n; } frac;
frac f1 = {0, 1}, f2 = {1, n}, t;
int k;
printf("%d/%d %d/%d", 0, 1, 1, n);
while (f2.n > 1) {
k = (n + f1.n) / f2.n;
t = f1, f1 = f2, f2 = (frac) { f2.d * k - t.d, f2.n * k - t.n };
printf(" %... |
parse arg LO HI INC .
if LO=='' | LO=="," then LO= 1
if HI=='' | HI=="," then HI= LO
if INC=='' | INC=="," then INC= 1
sw= linesize() - 1
oLO= LO
do j=abs(LO)... |
Rewrite the snippet below in REXX so it works the same as the original C code. | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int main( void ) {
int s=0, p, i=1;
for(p=2;p<=999;p++) {
if(isprime(p)) {
if(i%2) {
... |
parse arg hi .
if hi=='' | hi=="," then hi= 1000
call genP
title= 'odd indexed primes the sum of the odd indexed primes'
say ' index │'center(title, 65)
say '───────┼'center("" , 65, '─')
found... |
Maintain the same structure and functionality when rewriting this code in REXX. | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int main( void ) {
int s=0, p, i=1;
for(p=2;p<=999;p++) {
if(isprime(p)) {
if(i%2) {
... |
parse arg hi .
if hi=='' | hi=="," then hi= 1000
call genP
title= 'odd indexed primes the sum of the odd indexed primes'
say ' index │'center(title, 65)
say '───────┼'center("" , 65, '─')
found... |
Change the programming language of this snippet from C to REXX without modifying what it does. | #include<stdlib.h>
#include<string.h>
#include<stdio.h>
unsigned long long bruteForceProperDivisorSum(unsigned long long n){
unsigned long long i,sum = 0;
for(i=1;i<(n+1)/2;i++)
if(n%i==0 && n!=i)
sum += i;
return sum;
}
void printSeries(unsigned long long* arr,int size,char* type){
int i;
printf("\n... |
parse arg low high $L
high= word(high low 10,1); low= word(low 1,1)
if $L='' then $L=11 12 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080
numeric digits 100
big= 2**47; NTlimit= 16 + 1
numeric digits max(9, length... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include<stdlib.h>
#include<string.h>
#include<stdio.h>
unsigned long long bruteForceProperDivisorSum(unsigned long long n){
unsigned long long i,sum = 0;
for(i=1;i<(n+1)/2;i++)
if(n%i==0 && n!=i)
sum += i;
return sum;
}
void printSeries(unsigned long long* arr,int size,char* type){
int i;
printf("\n... |
parse arg low high $L
high= word(high low 10,1); low= word(low 1,1)
if $L='' then $L=11 12 28 496 220 1184 12496 1264460 790 909 562 1064 1488 15355717786080
numeric digits 100
big= 2**47; NTlimit= 16 + 1
numeric digits max(9, length... |
Can you help me rewrite this code in REXX instead of C, keeping it the same logically? | #include <stdio.h>
main(){
unsigned char uc; char c;
enum{e1, e2, e3}e123;
short si; int i; long li;
unsigned short su; unsigned u; unsigned long lu;
float sf; float f; double lf; long double llf;
union {char c; unsigned u; int i; float f; }ucuif;
struct {char c; unsigned u; int i; float ... |
digs=digits() ; say digs
a=.1.2...$ ; say a
a=+7 ; say a
a='+66' ; say a
a='- 66.' ; ... |
Generate a REXX translation of this C snippet without changing its computational steps. | #include <stdio.h>
main(){
unsigned char uc; char c;
enum{e1, e2, e3}e123;
short si; int i; long li;
unsigned short su; unsigned u; unsigned long lu;
float sf; float f; double lf; long double llf;
union {char c; unsigned u; int i; float f; }ucuif;
struct {char c; unsigned u; int i; float ... |
digs=digits() ; say digs
a=.1.2...$ ; say a
a=+7 ; say a
a='+66' ; say a
a='- 66.' ; ... |
Produce a functionally identical REXX code for the snippet given in C. | #include <stdio.h>
#include <string.h>
typedef int bool;
typedef unsigned long long ull;
#define TRUE 1
#define FALSE 0
bool is_prime(ull n) {
ull d;
if (n < 2) return FALSE;
if (!(n % 2)) return n == 2;
if (!(n % 3)) return n == 3;
d = 5;
while (d * d <= n) {
if (!(n % d)) return F... |
parse arg bet.1 bet.2 bet.3 highP .
if bet.1=='' | bet.1=="," then bet.1= 1..45
if bet.2=='' | bet.2=="," then bet.2= 241..250
if bet.3=='' | bet.3=="," then bet.3= 391..400
if highP=='' | highP=="," then highP= 1000000
call genP
do j=1 for 3... |
Convert this C block to REXX, preserving its control flow and logic. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
bool isPrime(uint64_t n) {
uint64_t test;
if (n < 2) return false;
if (n % 2 == 0) return n == 2;
if (n % 3 == 0) return n == 3;
test = 5;
while (test * test < n) {
if (n % test == 0) return false;
test += 2;
... |
do j=1;
if \isPrime(j) then iterate
r= testMer(j)
if r==0 then say right('M'j, 10) "──────── is a Mersenne prime."
else say right('M'j, 50) "is composite, a factor:" r
end
ex... |
Produce a functionally identical REXX code for the snippet given in C. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
bool isPrime(uint64_t n) {
uint64_t test;
if (n < 2) return false;
if (n % 2 == 0) return n == 2;
if (n % 3 == 0) return n == 3;
test = 5;
while (test * test < n) {
if (n % test == 0) return false;
test += 2;
... |
do j=1;
if \isPrime(j) then iterate
r= testMer(j)
if r==0 then say right('M'j, 10) "──────── is a Mersenne prime."
else say right('M'j, 50) "is composite, a factor:" r
end
ex... |
Write the same algorithm in REXX as shown in this C implementation. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <locale.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) {
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 15000
if cols=='' | cols=="," then cols= 10
call genP
w= 10
title= 'the smallest primes < ' commas(hi) ... |
Rewrite the snippet below in REXX so it works the same as the original C code. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <locale.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) {
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 15000
if cols=='' | cols=="," then cols= 10
call genP
w= 10
title= 'the smallest primes < ' commas(hi) ... |
Transform the following C implementation into REXX, maintaining the same output and logic. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#define TRUE 1
#define FALSE 0
typedef unsigned char bool;
void sieve(bool *c, int limit) {
int i, p = 3, p2;
c[0] = TRUE;
c[1] = TRUE;
for (;;) {
p2 = p * p;
if (p2 >= limit) {
break;... |
parse arg N endU end2 end3 end4 end5 .
if N=='' | N=="," then N= 1000035 - 1
if endU=='' | endU=="," then endU= 10
if end2=='' | end2=="," then end2= 5
if end3=='' | end3=="," then end3= 5
if end4=='' | end4=="," then end4= 5
if end5=='' | end5... |
Write the same code in REXX as shown below in C. | #include <stdio.h>
#include <stdlib.h>
typedef unsigned long long xint;
typedef unsigned uint;
typedef struct {
uint x, y;
xint value;
} sum_t;
xint *cube;
uint n_cubes;
sum_t *pq;
uint pq_len, pq_cap;
void add_cube(void)
{
uint x = n_cubes++;
cube = realloc(cube, sizeof(xint) * (n_cubes + 1));
cube[n_cubes] ... |
parse arg L.1 H.1 L.2 H.2 L.3 H.3 .
if L.1=='' | L.1=="," then L.1= 1
if H.1=='' | H.1=="," then H.1= 25
if L.2=='' | L.2=="," then L.2= 454
if H.2=='' | H.2=="," then H.2= 456
if L.3=='' | L.3=="," then L.3=2000
if H.3=='' | H.3... |
Please provide an equivalent version of this C code in REXX. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
const int PRIMES[] = {
2, 3, 5, 7,
11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211... |
parse arg N kind _ . 1 . okind; upper kind
if N=='' | N=="," then N= 36
if kind=='' | kind=="," then kind= 'STRONG'
if _\=='' then call ser 'too many arguments specified.'
if kind\=='WEAK' & kind\=='STRONG' then call ser 'invalid 2nd argument: ' okind
... |
Generate a REXX translation of this C snippet without changing its computational steps. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
void mpz_left_fac_ui(mpz_t rop, unsigned long op)
{
mpz_t t1;
mpz_init_set_ui(t1, 1);
mpz_set_ui(rop, 0);
size_t i;
for (i = 1; i <= op; ++i) {
mpz_add(rop, rop, t1);
mpz_mul_ui(t1, t1, i);
}
mpz_c... |
parse arg bot top inc .
if bot=='' | bot=="," then bot= 1
if top=='' | top=="," then top= bot
if inc='' | inc=="," then inc= 1
tell= bot<0
bot= abs(bot)
w= length(top) ... |
Produce a functionally identical REXX code for the snippet given in C. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
void mpz_left_fac_ui(mpz_t rop, unsigned long op)
{
mpz_t t1;
mpz_init_set_ui(t1, 1);
mpz_set_ui(rop, 0);
size_t i;
for (i = 1; i <= op; ++i) {
mpz_add(rop, rop, t1);
mpz_mul_ui(t1, t1, i);
}
mpz_c... |
parse arg bot top inc .
if bot=='' | bot=="," then bot= 1
if top=='' | top=="," then top= bot
if inc='' | inc=="," then inc= 1
tell= bot<0
bot= abs(bot)
w= length(top) ... |
Change the programming language of this snippet from C to REXX without modifying what it does. | #include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define LIMIT 3000
void init_sieve(unsigned char sieve[], int limit) {
int i, j;
for (i = 0; i < limit; i++) {
sieve[i] = 1;
}
sieve[0] = 0;
sieve[1] = 0;
for (i = 2; i < limit; i++) {
if (sieve[i]) {
for... |
parse arg hi .
if hi=='' | hi=="," then hi= 30
tell= hi>0; hi= abs(hi); hi= hi - 1
if tell>0 then say 'list of unique triplet strange primes whose sum is a prime.:'
call genP
finds= 0 ... |
Change the following C code into REXX without altering its purpose. | #include <stdbool.h>
#include <stdio.h>
#include <string.h>
#define LIMIT 3000
void init_sieve(unsigned char sieve[], int limit) {
int i, j;
for (i = 0; i < limit; i++) {
sieve[i] = 1;
}
sieve[0] = 0;
sieve[1] = 0;
for (i = 2; i < limit; i++) {
if (sieve[i]) {
for... |
parse arg hi .
if hi=='' | hi=="," then hi= 30
tell= hi>0; hi= abs(hi); hi= hi - 1
if tell>0 then say 'list of unique triplet strange primes whose sum is a prime.:'
call genP
finds= 0 ... |
Convert this C block to REXX, preserving its control flow and logic. | #include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
bool is_prime(uint64_t n) {
if (n < 2)
return false;
if (n % 2 == 0)
return n == 2;
if (n % 3 == 0)
return n == 3;
for (uint64_t p = 5; p * p <= n; p += 4) {
if (n % p == 0)
retur... |
numeric digits 92
parse arg n .
if n=='' | n=="," then n= 42
w= length(n) + 1; wm= digits()%4
say center('n', w ) center("Motzkin[n]", wm) center(' primality', 11)
say center('' , w, "─") center('' ... |
Ensure the translated REXX code behaves exactly like the original C snippet. | #include <stdio.h>
#define sqr(x) ((x) * (x))
#define greet printf("Hello There!\n")
int twice(int x)
{
return 2 * x;
}
int main(void)
{
int x;
printf("This will demonstrate function and label scopes.\n");
printf("All output is happening through printf(), a function declared in the header stdio.h, which is exte... |
blarney = -0
signal do_add
ttt = sinD(30)
DO_Add:
say 'calling the sub: add.2.args'
call add.2.args 1, 7 ... |
Convert this C snippet to REXX and keep its semantics consistent. | #include<stdio.h>
#include<stdlib.h>
#include<math.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int main(void) {
int np = 1, d, i, n;
printf( "3 " );
for(d=1; d<6; d++) {
for(i=3... |
parse arg hi cols dig .
if hi=='' | hi=="," then hi= 4000
if cols=='' | cols=="," then cols= 10
if dig=='' | dig=="," then dig= 3
call genP
w= 10
title= ' primes N ... |
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>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int main(void) {
int np = 1, d, i, n;
printf( "3 " );
for(d=1; d<6; d++) {
for(i=3... |
parse arg hi cols dig .
if hi=='' | hi=="," then hi= 4000
if cols=='' | cols=="," then cols= 10
if dig=='' | dig=="," then dig= 3
call genP
w= 10
title= ' primes N ... |
Can you help me rewrite this code in REXX instead of C, keeping it the same logically? | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int nextprime( int p ) {
int i=0;
if(p==0) return 2;
if(p<3) return p+1;
while(!isprime(++i + p));
r... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 100
if cols=='' | cols=="," then cols= 5
call genP hi
do p=1 while @.p<hi
end
#m= # - 1
call genP @.# + @.#m - 1
w= 20 ... |
Ensure the translated REXX code behaves exactly like the original C snippet. | #include<stdio.h>
#include<stdlib.h>
int isprime( int p ) {
int i;
if(p==2) return 1;
if(!(p%2)) return 0;
for(i=3; i*i<=p; i+=2) {
if(!(p%i)) return 0;
}
return 1;
}
int nextprime( int p ) {
int i=0;
if(p==0) return 2;
if(p<3) return p+1;
while(!isprime(++i + p));
r... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 100
if cols=='' | cols=="," then cols= 5
call genP hi
do p=1 while @.p<hi
end
#m= # - 1
call genP @.# + @.#m - 1
w= 20 ... |
Ensure the translated REXX code behaves exactly like the original C snippet. | #include <stdio.h>
static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0};
int isstrange(long n) {
if (n < 10) return 0;
for (; n >= 10; n /= 10) {
if (!p[n%10 + (n/10)%10]) return 0;
}
return 1;
}
int main(void) {
long n;
int k = 0;
for ... |
parse arg LO HI .
if LO=='' | LO=="," then LO= 101
if HI=='' | HI=="," then HI= 499
!.= 0; !.2= 1; !.3= 1; !.5= 1; !.7= 1
!.11= 1; !.13= 1; !.17= 1
$=
#= 0 ... |
Port the following code from C to REXX with equivalent syntax and logic. | #include <stdio.h>
static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0,
0, 1, 0, 1, 0, 0, 0, 1, 0};
int isstrange(long n) {
if (n < 10) return 0;
for (; n >= 10; n /= 10) {
if (!p[n%10 + (n/10)%10]) return 0;
}
return 1;
}
int main(void) {
long n;
int k = 0;
for ... |
parse arg LO HI .
if LO=='' | LO=="," then LO= 101
if HI=='' | HI=="," then HI= 499
!.= 0; !.2= 1; !.3= 1; !.5= 1; !.7= 1
!.11= 1; !.13= 1; !.17= 1
$=
#= 0 ... |
Translate this program into REXX but keep the logic exactly as in C. | #include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
typedef uint32_t integer;
integer next_prime_digit_number(integer n) {
if (n == 0)
return 2;
switch (n % 10) {
case 2:
return n + 1;
case 3:
case 5:
return n + 2;
default:
return 2 +... |
parse arg n q
if n=='' | n=="," then n= 25
if q='' then q= 100 1000
say '═══listing the first' n "SPDS primes═══"
call spds n
do i=1 for words(q)+1; y=word(q, i); if y=='' | y=="," then iterate
... |
Convert this C snippet to REXX and keep its semantics consistent. | #include<stdlib.h>
#include<ctype.h>
#include<stdio.h>
int** doublyEvenMagicSquare(int n) {
if (n < 4 || n % 4 != 0)
return NULL;
int bits = 38505;
int size = n * n;
int mult = n / 4,i,r,c,bitPos;
int** result = (int**)malloc(n*sizeof(int*));
for(i=0;i<n;i++)
result[i] = (int*)malloc(n*sizeof(int));
fo... |
n= 8; s= n%4; L= n%2-s+1; w= length(n**2)
@.= 0; H= n%2+s
call gen
call diag
call corn
call midd
call swap ... |
Write the same code in REXX as shown below in C. | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define TRUE 1
#define FALSE 0
#define TRILLION 1000000000000
typedef unsigned char bool;
typedef unsigned long long uint64;
void sieve(uint64 limit, uint64 *primes, uint64 *length) {
uint64 i, count, p, p2;
bool *c = calloc(limit + 1, sizeof(bool)); ... |
numeric digits 20
parse arg LO HI .
if LO=='' | LO=="," then LO= 1
if HI=='' | HI=="," then HI= 145
sw= linesize() - 1
# = 0
$= ... |
Generate a REXX translation of this C snippet without changing its computational steps. | #include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef unsigned char bool;
#define TRUE 1
#define FALSE 0
#define MILLION 1000000
#define BILLION 1000 * MILLION
#define MAX_COUNT 2*BILLION + 9*9 + 1
void sieve(bool *sv) {
int n = 0, s[8], a, b, c, d, e, f, g, h, i, j;
for (a = 0; a < 2; ++a) {
... |
parse arg n .
if n=='' | n=="," then n= 50
tell = n>0; n= abs(n)
@.= .
do j=1 for n*10
$= j
do... |
Can you help me rewrite this code in REXX instead of C, keeping it the same logically? | #include <locale.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
uint64_t digit_sum(uint64_t n, uint64_t sum) {
++sum;
while (n > 0 && n % 10 == 0) {
sum -= 9;
n /= 10;
}
return sum;
}
inline bool divisible(uint64_t n, uint64_t d) {
if ((d & 1) == 0 && (n & 1) == 1... |
parse arg lim .
if lim=='' | lim==',' then lim= 10000000
numeric digits 2 + max(8, length(lim) )
gap= 0; old= 0
@gsa= 'gap starts at Niven #'
call tell center('gap size', 12) cent... |
Port the provided C code into REXX while preserving the original functionality. | #include<string.h>
#include<stdlib.h>
#include<ctype.h>
#include<stdio.h>
#define UNITS_LENGTH 13
int main(int argC,char* argV[])
{
int i,reference;
char *units[UNITS_LENGTH] = {"kilometer","meter","centimeter","tochka","liniya","diuym","vershok","piad","fut","arshin","sazhen","versta","milia"};
double factor, ... |
numeric digits 200
KM= 1000; CM=100
sw= linesize() -1
parse arg N what _ __
if N=='' then call err 'no arguments specified.'... |
Write a version of this C function in REXX with identical behavior. | #include <stdio.h>
int pancake(int n) {
int gap = 2, sum = 2, adj = -1;
while (sum < n) {
adj++;
gap = gap * 2 - 1;
sum += gap;
}
return n + adj;
}
int main() {
int i, j;
for (i = 0; i < 4; i++) {
for (j = 1; j < 6; j++) {
int n = i * 5 + j;
... |
pad= center('' , 10)
say pad center('pancakes', 10 ) center('pancake flips', 15 )
say pad center('' , 10, "─") center('', 15, "─")
do #=1 for 20; say pad center(#, 10) center( pancake(#), 15)
end
exit 0... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include <stdio.h>
#include <math.h>
#include <string.h>
#define N 2200
int main(int argc, char **argv){
int a,b,c,d;
int r[N+1];
memset(r,0,sizeof(r));
for(a=1; a<=N; a++){
for(b=a; b<=N; b++){
int aabb;
if(a&1 && b&1) continue;
aabb=a*a + b*b;
for(c=b; c<=N; c++){
int aabbcc=aabb +... |
parse arg hi .
if hi=='' | hi=="," then hi=2200; high= 3 * hi
@.=.
!.=.
do j=1 for high
_= j*j; !._= j; if j<=hi then @.j= _
end
d.=. ... |
Generate an equivalent REXX version of this C code. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct node_t {
int x, y;
struct node_t *prev, *next;
} node;
node *new_node(int x, int y) {
node *n = malloc(sizeof(node));
n->x = x;
n->y = y;
n->next = NULL;
n->prev = NULL;
return n;
}
void free_node(node **n) {
... | all =.set~new
Call time 'R'
cnt.=0
do a=2 to 100
do b=a+1 to 100-2
p=a b
if a+b>100 then leave b
all~put(p)
prd=a*b
cnt.prd+=1
End
End
Say "There are" all~items "pairs where X+Y <=" max "(and X<Y)"
spairs=.set~new
Do Until all~items=0
do p over all
d=decompositions(p)
If take... |
Produce a functionally identical REXX code for the snippet given in C. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 12
char *super = 0;
int pos, cnt[MAX];
int fact_sum(int n)
{
int s, x, f;
for (s = 0, x = 0, f = 1; x < n; f *= ++x, s += f);
return s;
}
int r(int n)
{
if (!n) return 0;
char c = super[pos - n];
if (!--cnt[n]) {
cnt[n] = n;
if (!r(n-... |
parse arg cycles .
if cycles=='' | cycles=="," then cycles= 7
do n=0 to cycles
#= 0; $.=
do pop=1 for n; @.pop= d2x(pop); $.0= $.0 || @.pop
end
do while aPerm(n, 0)
... |
Convert this C block to REXX, preserving its control flow and logic. | #include <stdio.h>
#include <complex.h>
#include <math.h>
#define FMTSPEC(arg) _Generic((arg), \
float: "%f", double: "%f", \
long double: "%Lf", unsigned int: "%u", \
unsigned long: "%lu", unsigned long long: "%llu", \
int: "%d", long: "%ld", long long: "%lld", \
default: "(invalid type (%p)")
#... |
* 22.06.2014 Walter Pachl using a complex data class
* ooRexx Distribution contains an elaborate complex class
* parts of which are used here
* see REXX for Extra Credit implementation
*--------------------------------------------------------------------*/
Numeric Digits 1000
Call test_integer .complex~new(1e+12,0e-3)... |
Rewrite this program in REXX while keeping its functionality equivalent to the C version. | #include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<stdio.h>
int main(int argC,char* argV[])
{
char str[100];
const char d[2] = " ";
char* token;
int i = 0,times,lag;
long int sum = 0, idle, lastSum = 0,lastIdle = 0;
long double idleFraction;
if(argC!=3)
printf("Usage : %s <number of times /pr... |
signal on halt
numeric digits 20
parse arg n wait iFID .
if n=='' | n="," then n= 10
if wait=='' | wait="," then wait= 1
if iFID=='' | iFID="," then iFID= '/proc/stat'
prevTot = 0; ... |
Maintain the same structure and functionality when rewriting this code in REXX. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void fatal(const char* message) {
fprintf(stderr, "%s\n", message);
exit(1);
}
void* xmalloc(size_t n) {
void* ptr = malloc(n);
if (ptr == NULL)
fatal("Out of memory");
return ptr;
}
void* xrealloc(void* p, size_... |
parse arg $
if $='' | $="," then $= 10 100 1000 10000
do k=1 for words($)
x= Ulam( word($, k) )
say 'the ' commas(#)th(#) ' Ulam number is: ' commas(x)
end
exit 0 ... |
Generate an equivalent REXX version of this C code. | #include <stdio.h>
int a[17][17], idx[4];
int find_group(int type, int min_n, int max_n, int depth)
{
int i, n;
if (depth == 4) {
printf("totally %sconnected group:", type ? "" : "un");
for (i = 0; i < 4; i++) printf(" %d", idx[i]);
putchar('\n');
return 1;
}
for (i = min_n; i < max_n; i++) {
for (n = ... |
@.=0; #=17
do d=0 for #; @.d.d= 2
end
do k=1 by 0 while k<=8
do i=0 for #; j= (i+k) // #
@.i.j= 1; @.j.i= 1
end
k= k + k ... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <stdio.h>
#include <string.h>
#include <gmp.h>
char *power_of_six(unsigned int n, char *buf) {
mpz_t p;
mpz_init(p);
mpz_ui_pow_ui(p, 6, n);
mpz_get_str(buf, 10, p);
mpz_clear(p);
return buf;
}
char *smallest_six(unsigned int n) {
static char nbuf[32], powbuf[1024];
unsigned i... |
numeric digits 100
parse arg hi .
if hi=='' | hi=="," then hi= 22
w= 50
@smp6= ' smallest power of six (expressed in decimal) which contains N'
say ' N │ power │'center(@... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include<stdio.h>
#include<ctype.h>
void typeDetector(char* str){
if(isalnum(str[0])!=0)
printf("\n%c is alphanumeric",str[0]);
if(isalpha(str[0])!=0)
printf("\n%c is alphabetic",str[0]);
if(iscntrl(str[0])!=0)
printf("\n%c is a control character",str[0]);
if(isdigit(str[0])!=0)
printf("\n%c is a digit",s... |
signal on noValue
y= 1938 ; call showType y
y= 77.1 ; call showType y
y= ; call showType y
y= ' ' ; call showType y
y= 'abc' ; call showType y
y= 'ABC' ; ... |
Write the same algorithm in REXX as shown in this C implementation. | #include <stdio.h>
#include <stdbool.h>
bool steady(int n)
{
int mask = 1;
for (int d = n; d != 0; d /= 10)
mask *= 10;
return (n * n) % mask == n;
}
int main()
{
for (int i = 1; i < 10000; i++)
if (steady(i))
printf("%4d^2 = %8d\n", i, i * i);
return 0;
}
|
Numeric Digits 50
Call time 'R'
n=1000000000
Say 'Steady squares below' n
Do i=1 To n
c=right(i,1)
If pos(c,'156')>0 Then Do
i2=i*i
If right(i2,length(i))=i Then
Say right(i,length(n)) i2
End
End
Say time('E')
|
Translate this program into REXX but keep the logic exactly as in C. | #include <stdbool.h>
#include <stdio.h>
int primes[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
211, 223, 227, 229, 233, 239, 241, 251, 257, 263,... |
parse arg N kind _ . 1 . okind; upper kind
if N=='' | N=="," then N= 35
if kind=='' | kind=="," then kind= 'SAFE'
if _\=='' then call ser 'too many arguments specified.'
if kind\=='SAFE' & kind\=='UNSAFE' then call ser 'invalid 2nd argument: ' okind
... |
Transform the following C implementation into REXX, maintaining the same output and logic. | #include <stdio.h>
#include <unistd.h>
int main()
{
int i;
printf("\033[?1049h\033[H");
printf("Alternate screen buffer\n");
for (i = 5; i; i--) {
printf("\rgoing back in %d...", i);
fflush(stdout);
sleep(1);
}
printf("\033[?1049l");
return 0;
}
|
parse value scrsize() with sd sw .
parse value cursor(1,1) with curRow curCol .
do original=1 for sd
@line.original=scrRead(original,1, sw)
end
'CLS'
do sd % 2 ... |
Change the programming language of this snippet from C to REXX without modifying what it does. | #include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void talk(const char *s)
{
pid_t pid;
int status;
pid = fork();
if (pid < 0) {
perror("fork");
exit(1);
}
if (pid == 0) {
execlp("espeak", "espeak", s, (void*)0);
perror("espeak");
_exit(1);
}
waitpid(pid, &status, 0)... |
parse arg t
if t='' then exit
dquote= '"'
rate= 1
'NIRCMD' "speak text" dquote t dquote rate
|
Write the same algorithm in REXX as shown in this C implementation. | static unsigned char const k8[16] = { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 };
static unsigned char const k7[16] = { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 };
static unsigned char const k6[16] = { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 };
static ... |
numeric digits 12
@.0 = 4 10 9 2 13 8 0 14 6 11 1 12 7 15 5 3
@.1 = 14 11 4 12 6 13 15 10 2 3 8 1 0 7 5 9
@.2 = 5 8 1 13 10 3 4 ... |
Translate this program into REXX but keep the logic exactly as in C. | #include <stdio.h>
#define JOBS 12
#define jobs(a) for (switch_to(a = 0); a < JOBS || !printf("\n"); switch_to(++a))
typedef struct { int seq, cnt; } env_t;
env_t env[JOBS] = {{0, 0}};
int *seq, *cnt;
void hail()
{
printf("% 4d", *seq);
if (*seq == 1) return;
++*cnt;
*seq = (*seq & 1) ? 3 * *seq + 1 : *seq / 2;
... |
parse arg n .
if n=='' | n=="," then n= 12
@.=
do i=1 for n; @.i= i
end
w= length(n)
do forever until @.0; @.0= 1 ... |
Change the programming language of this snippet from C to REXX without modifying what it does. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "wren.h"
void C_xrandr(WrenVM* vm) {
const char *arg = wrenGetSlotString(vm, 1);
char command[strlen(arg) + 8];
strcpy(command, "xrandr ");
strcat(command, arg);
system(command);
}
void C_usleep(WrenVM* vm... |
parse arg cols lines .
'MODE' "CON: COLS="cols 'LINES='lines
|
Convert the following code from C to REXX, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "wren.h"
void C_xrandr(WrenVM* vm) {
const char *arg = wrenGetSlotString(vm, 1);
char command[strlen(arg) + 8];
strcpy(command, "xrandr ");
strcat(command, arg);
system(command);
}
void C_usleep(WrenVM* vm... |
parse arg cols lines .
'MODE' "CON: COLS="cols 'LINES='lines
|
Produce a functionally identical REXX code for the snippet given in C. | #include <windows.h>
#include <wchar.h>
int
main()
{
CONSOLE_SCREEN_BUFFER_INFO info;
COORD pos;
HANDLE conout;
long len;
wchar_t c;
conout = CreateFileW(L"CONOUT$", GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
0, NULL);
if (conout == INVALID_HANDLE_VALUE)
... |
row = 6
col = 3
howMany = 1
stuff = scrRead(row, col, howMany)
other = scrRead(40, 3, 1)
|
Port the following code from C to REXX with equivalent syntax and logic. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
uint64_t modpow(uint64_t a, uint64_t b, uint64_t n) {
uint64_t x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y) % n;
}
y = (y * y) % n;
b /= 2;
}
return x % n;
}
struct Solution {
u... |
Numeric Digits 1000000
ttest ='[(10, 13), (56, 101), (1030, 10009), (44402, 100049)]'
Do While pos('(',ttest)>0
Parse Var ttest '(' n ',' p ')' ttest
r = tonelli(n, p)
Say "n =" n "p =" p
Say " roots :" r (p - r)
End
Exit
legendre: Procedure
Parse Arg a, p
return pow(a, (p - 1) % 2, p)
tonelli... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
uint64_t modpow(uint64_t a, uint64_t b, uint64_t n) {
uint64_t x = 1, y = a;
while (b > 0) {
if (b % 2 == 1) {
x = (x * y) % n;
}
y = (y * y) % n;
b /= 2;
}
return x % n;
}
struct Solution {
u... |
Numeric Digits 1000000
ttest ='[(10, 13), (56, 101), (1030, 10009), (44402, 100049)]'
Do While pos('(',ttest)>0
Parse Var ttest '(' n ',' p ')' ttest
r = tonelli(n, p)
Say "n =" n "p =" p
Say " roots :" r (p - r)
End
Exit
legendre: Procedure
Parse Arg a, p
return pow(a, (p - 1) % 2, p)
tonelli... |
Please provide an equivalent version of this C code in REXX. | #include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct RealSet {
bool(*contains)(struct RealSet*, struct RealSet*, double);
struct RealSet *left;
struct RealSet *right;
double low, high;
};
typedef enum {
CLOSED,
LEFT_OPEN,
RIGHT_OPEN,
BOTH_OPEN,
} RangeTy... |
call quertySet 1, 3, '[1,2)'
call quertySet , , '[0,2) union (1,3)'
call quertySet , , '[0,1) union (2,3]'
call quertySet , , '[0,2] inter (1,3)'
call quertySet , , '(1,2) ∩ (2,3]'
call quertySet , , '[0,2) \ (1,3)'
say; say center(' star... |
Rewrite the snippet below in REXX so it works the same as the original C code. | #include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
struct RealSet {
bool(*contains)(struct RealSet*, struct RealSet*, double);
struct RealSet *left;
struct RealSet *right;
double low, high;
};
typedef enum {
CLOSED,
LEFT_OPEN,
RIGHT_OPEN,
BOTH_OPEN,
} RangeTy... |
call quertySet 1, 3, '[1,2)'
call quertySet , , '[0,2) union (1,3)'
call quertySet , , '[0,1) union (2,3]'
call quertySet , , '[0,2] inter (1,3)'
call quertySet , , '(1,2) ∩ (2,3]'
call quertySet , , '[0,2) \ (1,3)'
say; say center(' star... |
Write a version of this C function in REXX with identical behavior. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define USE_FAKES 1
const char *states[] = {
#if USE_FAKES
"New Kory", "Wen Kory", "York New", "Kory New", "New Kory",
#endif
"Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut",
"Delaware",
"Florida", "Georgia", "Hawa... |
!='Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut, Delaware, Florida, Georgia,',
'Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana, Maine, Maryland, Massachusetts, ',
'Michigan, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, New Hampshire, ... |
Ensure the translated REXX code behaves exactly like the original C snippet. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
int main() {
for (unsigned int d = 2; d <= 9; ++d) {
printf("First 10 super-%u numbers:\n", d);
char digits[16] = { 0 };
memset(digits, '0' + d, d);
mpz_t bignum;
mpz_init(bignum);
for (unsig... |
numeric digits 100
parse arg n LO HI .
if n=='' | n=="," then n= 10
if LO=='' | LO=="," then LO= 2
if HI=='' | HI=="," then HI= 9
do d=LO to HI... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gmp.h>
int main() {
for (unsigned int d = 2; d <= 9; ++d) {
printf("First 10 super-%u numbers:\n", d);
char digits[16] = { 0 };
memset(digits, '0' + d, d);
mpz_t bignum;
mpz_init(bignum);
for (unsig... |
numeric digits 100
parse arg n LO HI .
if n=='' | n=="," then n= 10
if LO=='' | LO=="," then LO= 2
if HI=='' | HI=="," then HI= 9
do d=LO to HI... |
Write the same algorithm in REXX as shown in this C implementation. | #include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int pRec(int n) {
static int *memo = NULL;
static size_t curSize = 0;
if (curSize <= (size_t) n) {
size_t lastSize = curSize;
while (curSize <= (size_t) n) curSize += 1024 * sizeof(int);
memo = r... |
numeric digits 40
parse arg n nF Ln cL .
if n=='' | n=="," then n= 20
if nF=='' | nF=="," then nF= 64
if Ln=='' | Ln=="," then Ln= 10
if cL=='' | cL=="," then cL= 32
PR= 1.3247179572447... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
typedef enum type
{
INT,
STRING
} Type;
typedef struct maybe
{
int i;
char *s;
Type t;
_Bool is_something;
} Maybe;
void print_Maybe(Maybe *m)
{
if (m->t == INT)
printf("Just %d : INT\n", m->i);
else if (m->t == STRING)
printf("Just... |
call add 1, 2
call add 1, 2.0
call add 1, 2.0, -6
call add self, 2
exit 0
add: void= 'VOID'; f=
do j=1 for arg()
call bind( arg(j) ); f= f arg(j)
end
say
... |
Convert this C block to REXX, preserving its control flow and logic. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <glib.h>
char text_char(char c) {
switch (c) {
case 'a': case 'b': case 'c':
return '2';
case 'd': case 'e': case 'f':
return '3';
case 'g': case 'h': case 'i':
return '4';
case 'j': case 'k': case 'l':
... |
parse arg iFID .
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT'
@.= 0
!.=; $.=
alphabet= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
digitKey= 22233344455566677778889999
digKey= 0; ... |
Write the same algorithm in REXX as shown in this C implementation. | #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
typedef struct cidr_tag {
uint32_t address;
unsigned int mask_length;
} cidr_t;
bool cidr_parse(const char* str, cidr_t* cidr) {
int a, b, c, d, m;
if (sscanf(str, "%d.%d.%d.%d/%d", &a, &b, &c, &d, &m) != 5)
return false;
if (m ... |
parse arg a .
if a=='' | a=="," then a= '87.70.141.1/22' ,
'36.18.154.103/12' ,
'62.62.197.11/29' ,
'67.137.119.181/4' ,
'161.214.74.21/24' ,
... |
Port the following code from C to REXX with equivalent syntax and logic. | #include <stdbool.h>
#include <stdio.h>
#include <stdint.h>
typedef struct cidr_tag {
uint32_t address;
unsigned int mask_length;
} cidr_t;
bool cidr_parse(const char* str, cidr_t* cidr) {
int a, b, c, d, m;
if (sscanf(str, "%d.%d.%d.%d/%d", &a, &b, &c, &d, &m) != 5)
return false;
if (m ... |
parse arg a .
if a=='' | a=="," then a= '87.70.141.1/22' ,
'36.18.154.103/12' ,
'62.62.197.11/29' ,
'67.137.119.181/4' ,
'161.214.74.21/24' ,
... |
Rewrite the snippet below in REXX so it works the same as the original C code. | #include <gmp.h>
void perm(mpz_t out, int n, int k)
{
mpz_set_ui(out, 1);
k = n - k;
while (n > k) mpz_mul_ui(out, out, n--);
}
void comb(mpz_t out, int n, int k)
{
perm(out, n, k);
while (k) mpz_divexact_ui(out, out, k--);
}
int main(void)
{
mpz_t x;
mpz_init(x);
perm(x, 1000, 969);
gmp_printf("P(1000,969... |
numeric digits 100
do j=1 for 12; _=
do k=1 for j
_=_ 'P('j","k')='perm(j,k)" "
end
say strip(_)
end
say ... |
Change the programming language of this snippet from C to REXX without modifying what it does. | #include "gmp.h"
void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
mpf_add (out1, in1, in2);
mpf_div_ui (out1, out1, 2);
mpf_mul (out2, in1, in2);
mpf_sqrt (out2, out2);
}
int main (void) {
mpf_set_default_prec (300000);
mpf_t x0, y0, resA, resB, Z, var;
mpf_init_set_ui (x0, 1);
mpf_init_... |
parse arg d .; if d=='' | d=="," then d= 500
numeric digits d+5
z= 1/4; a= 1; g= sqrt(1/2)
n= 1
do j=1 until a==old; old= a
x= (a+g) * .5; g= sqrt(a*g)
z= z - n*(x-a)**2; n= n+n; a= x
end
... |
Convert the following code from C to REXX, ensuring the logic remains intact. | #include "gmp.h"
void agm (const mpf_t in1, const mpf_t in2, mpf_t out1, mpf_t out2) {
mpf_add (out1, in1, in2);
mpf_div_ui (out1, out1, 2);
mpf_mul (out2, in1, in2);
mpf_sqrt (out2, out2);
}
int main (void) {
mpf_set_default_prec (300000);
mpf_t x0, y0, resA, resB, Z, var;
mpf_init_set_ui (x0, 1);
mpf_init_... |
parse arg d .; if d=='' | d=="," then d= 500
numeric digits d+5
z= 1/4; a= 1; g= sqrt(1/2)
n= 1
do j=1 until a==old; old= a
x= (a+g) * .5; g= sqrt(a*g)
z= z - n*(x-a)**2; n= n+n; a= x
end
... |
Write the same algorithm in REXX as shown in this C implementation. | #include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
typedef int bool;
void sieve(int limit, int primes[], int *count) {
bool *c = calloc(limit + 1, sizeof(bool));
int i, p = 3, p2, n = 0;
p2 = p * p;
while (p2 <= limit) {
for (i = p2; i <= limit; i += 2 * p)
... |
parse arg a
if a='' | a="," then a= '500 -500 -1000 -2000 -4000 -8000 -16000' ,
'-32000 -64000 -128000 -512000 -1024000'
do k=1 for words(a); H=word(a, k)
neg= H<1
H= abs(H) ... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <inttypes.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <gmp.h>
int es_check(uint32_t *sieve, uint64_t n)
{
if ((n != 2 && !(n & 1)) || (n < 2))
return 0;
else
return !(sieve[n >> 6] & (1 << (n >> 1 & 31)));
}
uint32_t *e... |
parse arg N H .
if N=='' | N==',' then N= 10
if H=='' | H==',' then H= 100000
numeric digits 600000
w= length( commas( digits() ) )
@.=.; @.0= 1; @.1= 2; @.2= 3; @.3= 5; @.4= 7; @.5= 11; @.6= 13... |
Please provide an equivalent version of this C code in REXX. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
typedef int64_t integer;
struct Pair {
integer md;
int tc;
};
integer mod(integer x, integer y) {
return ((x % y) + y) % y;
}
integer gcd(integer a, integer b) {
if (0 == a) return b;
if (0 == b) return a;
if (a == b) return a;
... |
parse arg fract '' -1 t; z=$egyptF(fract)
if t\==. then say fract ' ───► ' z
return z
$egyptF: parse arg z 1 zn '/' zd,,$; if zd=='' then zd=1
if z='' then call erx "no fraction was specified."
if zd==0 then call erx "denominator can'... |
Transform the following C implementation into REXX, maintaining the same output and logic. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
typedef int64_t integer;
struct Pair {
integer md;
int tc;
};
integer mod(integer x, integer y) {
return ((x % y) + y) % y;
}
integer gcd(integer a, integer b) {
if (0 == a) return b;
if (0 == b) return a;
if (a == b) return a;
... |
parse arg fract '' -1 t; z=$egyptF(fract)
if t\==. then say fract ' ───► ' z
return z
$egyptF: parse arg z 1 zn '/' zd,,$; if zd=='' then zd=1
if z='' then call erx "no fraction was specified."
if zd==0 then call erx "denominator can'... |
Ensure the translated REXX code behaves exactly like the original C snippet. | #include <stdio.h>
#include <math.h>
#define N 5
double Pi;
double lroots[N];
double weight[N];
double lcoef[N + 1][N + 1] = {{0}};
void lege_coef()
{
int n, i;
lcoef[0][0] = lcoef[1][1] = 1;
for (n = 2; n <= N; n++) {
lcoef[n][0] = -(n - 1) * lcoef[n - 2][0] / n;
for (i = 1; i <= n; i++)
lcoef[n][i] = ((2 ... |
* 31.10.2013 Walter Pachl Translation from REXX (from PL/I)
* using ooRexx' rxmath package
* which limits the precision to 16 digits
*--------------------------------------------------------------------*/
prec=60
Numeric Digits prec
epsilon=1/10**prec
pi=3.14159265358... |
Keep all operations the same but rewrite the snippet in REXX. | #include <stdio.h>
#include <stdlib.h>
int
main()
{
int i;
srand(time(NULL));
for (i = 0; i < 10; i++)
puts((rand() % 2) ? "heads" : "tails");
return 0;
}
|
y = random(100, 200)
|
Change the following C code into REXX without altering its purpose. | #include <stdio.h>
#include <stdlib.h>
int
main()
{
int i;
srand(time(NULL));
for (i = 0; i < 10; i++)
puts((rand() % 2) ? "heads" : "tails");
return 0;
}
|
y = random(100, 200)
|
Can you help me rewrite this code in REXX instead of C, keeping it the same logically? | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char byte;
byte *grid = 0;
int w, h, len;
unsigned long long cnt;
static int next[4], dir[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
void walk(int y, int x)
{
int i, t;
if (!y || y == h || !x || x == w) {
cnt += 2;
return;
}
t = y... |
numeric digits 20
parse arg N .; if N=='' | N=="," then N= 10
dir.= 0; dir.0.1= -1; dir.1.0= -1; dir.2.1= 1; dir.3.0= 1
do y=2 to N; say
do x=1 for y; if x//2 & y//2 then iterate
z= solve(y,x,1); _= comm... |
Produce a functionally identical REXX code for the snippet given in C. | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef unsigned char byte;
byte *grid = 0;
int w, h, len;
unsigned long long cnt;
static int next[4], dir[4][2] = {{0, -1}, {-1, 0}, {0, 1}, {1, 0}};
void walk(int y, int x)
{
int i, t;
if (!y || y == h || !x || x == w) {
cnt += 2;
return;
}
t = y... |
numeric digits 20
parse arg N .; if N=='' | N=="," then N= 10
dir.= 0; dir.0.1= -1; dir.1.0= -1; dir.2.1= 1; dir.3.0= 1
do y=2 to N; say
do x=1 for y; if x//2 & y//2 then iterate
z= solve(y,x,1); _= comm... |
Maintain the same structure and functionality when rewriting this code in REXX. | #include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef long long llong_t;
struct PrimeArray {
llong_t *ptr;
size_t size;
size_t capacity;
};
struct PrimeArray allocate() {
struct PrimeArray primes;
primes.size = 0;
primes.capacity = 10;
p... |
numeric digits 20
parse arg N .
if N=='' | N=="," then N= 200
Nth= N<0; N= abs(N)
@.=0; @.0=1; @.2=1; @.3=1; @.4=1; @.5=1; @.6=1; @.8=1
sw= linesize() - 1; if sw<1 then sw= 79
w=12; ... |
Maintain the same structure and functionality when rewriting this code in REXX. | #include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
#define pi M_PI
int main(){
time_t t;
double side, vertices[3][3],seedX,seedY,windowSide;
int i,iter,choice;
printf("Enter triangle side length : ");
scanf("%lf",&side);
printf("Enter number of iterations : ");
sc... |
parse value scrsize() with sd sw .
sw= sw - 2
sd= sd - 4
parse arg pts chr seed .
if pts=='' | pts=="," then pts= 1000000
if chr=='' | chr=="," then chr= '∙'
if datatype(seed,'W... |
Write a version of this C function in REXX with identical behavior. | #include<graphics.h>
#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<time.h>
#define pi M_PI
int main(){
time_t t;
double side, vertices[3][3],seedX,seedY,windowSide;
int i,iter,choice;
printf("Enter triangle side length : ");
scanf("%lf",&side);
printf("Enter number of iterations : ");
sc... |
parse value scrsize() with sd sw .
sw= sw - 2
sd= sd - 4
parse arg pts chr seed .
if pts=='' | pts=="," then pts= 1000000
if chr=='' | chr=="," then chr= '∙'
if datatype(seed,'W... |
Ensure the translated REXX code behaves exactly like the original C snippet. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare(const void *a, const void *b) {
int int_a = *((int *)a);
int int_b = *((int *)b);
return (int_a > int_b) - (int_a < int_b);
}
char results[7];
bool next_result() {
char *ptr = results + 5;
int num = 0;
... |
results = '000000'
games = '12 13 14 23 24 34'
points.=0
records.=0
Do Until nextResult(results)=0
records.=0
Do i=1 To 6
r=substr(results,i,1)
g=word(games,i); Parse Var g g1 +1 g2
Select
When r='2' Then
records.g1=records.g1+3
When r='1' Th... |
Translate the given C code snippet into REXX without altering its behavior. | #include <sys/types.h>
#include <regex.h>
#include <stdio.h>
typedef struct {
const char *s;
int len, prec, assoc;
} str_tok_t;
typedef struct {
const char * str;
int assoc, prec;
regex_t re;
} pat_t;
enum assoc { A_NONE, A_L, A_R };
pat_t pat_eos = {"", A_NONE, 0};
pat_t pat_ops[] = {
{"^\\)", A_NONE, -1},
... |
parse arg x
if x='' then x= '3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3'
ox=x
x='(' space(x) ") "
#=words(x)
do i=1 for #; @.i=word(x, i)
end
tell=1 ... |
Convert this C snippet to REXX and keep its semantics consistent. | #include<stdlib.h>
#include<stdio.h>
#include<math.h>
int p[512];
double fade(double t) { return t * t * t * (t * (t * 6 - 15) + 10); }
double lerp(double t, double a, double b) { return a + t * (b - a); }
double grad(int hash, double x, double y, double z) {
int h = hash & 15;
doubl... |
_= 97a0895b5a0f830dc95f6035c2e907e18c24671e458e086325f0150a17be0694f778ea4b001ac53e5efcdbcb75230b2039b12158ed953857ae147d88aba844af,
||4aa547868b301ba64d929ee7536fe57a3cd385e6dc695c29372ef528f4668f3641193fa101d85049d14c84bbd05912a9c8c4878274bc9f56a4646dc6adba0340,
||34d9e2fa7c7b05ca2693767eff5255d4cfce3be32f103a11b6... |
Rewrite the snippet below in REXX so it works the same as the original C code. | #include <stdio.h>
#include <math.h>
#include <stdlib.h>
int header[] = {46, 115, 110, 100, 0, 0, 0, 24,
255, 255, 255, 255, 0, 0, 0, 3,
0, 0, 172, 68, 0, 0, 0, 1};
int main(int argc, char *argv[]){
float freq, dur;
long i, v;
if (argc < 3) {
p... |
parse arg freq time .
if freq=='' | freq=="," then freq= 880
if time=='' | time=="," then time= 5
call sound freq, time
exit 0
|
Maintain the same structure and functionality when rewriting this code in REXX. | #include <stdio.h>
#include <stdlib.h>
#define SWAP(a,b) do{t=(a);(a)=(b);(b)=t;}while(0)
void _mr_unrank1(int rank, int n, int *vec) {
int t, q, r;
if (n < 1) return;
q = rank / n;
r = rank % n;
SWAP(vec[r], vec[n-1]);
_mr_unrank1(q, n-1, vec);
}
int _mr_rank1(int n, int *vec, int *inv) {
... |
parse arg N y seed .
if N=='' | N=="," then N= 4
if y=='' | y=="," then y= 17
if datatype(seed,'W') then call random ,,seed
permutes= permSets(N)
w= length(permutes)
@.=
do p=0 f... |
Transform the following C implementation into REXX, maintaining the same output and logic. | #include <stdio.h>
#include <stdlib.h>
#define SWAP(a,b) do{t=(a);(a)=(b);(b)=t;}while(0)
void _mr_unrank1(int rank, int n, int *vec) {
int t, q, r;
if (n < 1) return;
q = rank / n;
r = rank % n;
SWAP(vec[r], vec[n-1]);
_mr_unrank1(q, n-1, vec);
}
int _mr_rank1(int n, int *vec, int *inv) {
... |
parse arg N y seed .
if N=='' | N=="," then N= 4
if y=='' | y=="," then y= 17
if datatype(seed,'W') then call random ,,seed
permutes= permSets(N)
w= length(permutes)
@.=
do p=0 f... |
Change the following C code into REXX without altering its purpose. | #include <math.h>
#include <stdio.h>
int p(int l, int n) {
int test = 0;
double logv = log(2.0) / log(10.0);
int factor = 1;
int loop = l;
while (loop > 10) {
factor *= 10;
loop /= 10;
}
while (n > 0) {
int val;
test++;
val = (int)(factor * pow(10.0,... |
parse arg L n b .
if L=='' | L=="," then L= 12
if n=='' | n=="," then n= 1
if b=='' | b=="," then b= 2
LL= length(L)
fd= left(L, 1)
fr= substr(L, 2) ... |
Produce a functionally identical REXX code for the snippet given in C. | #include <math.h>
#include <stdio.h>
int p(int l, int n) {
int test = 0;
double logv = log(2.0) / log(10.0);
int factor = 1;
int loop = l;
while (loop > 10) {
factor *= 10;
loop /= 10;
}
while (n > 0) {
int val;
test++;
val = (int)(factor * pow(10.0,... |
parse arg L n b .
if L=='' | L=="," then L= 12
if n=='' | n=="," then n= 1
if b=='' | b=="," then b= 2
LL= length(L)
fd= left(L, 1)
fr= substr(L, 2) ... |
Rewrite this program in REXX while keeping its functionality equivalent to the C version. | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int PRIMES[] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47,
53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113,
127, 131, 137, 139, 149, 151, 157,... |
parse arg n .
if n=='' | n=="," then n= 50
numeric digits n
big= copies(9, digits() )
@.= '2nd'; @.1= '1st'
do t=1 to -1 by -2; usum= 0; vsum= 0; s= 0
#... |
Can you help me rewrite this code in REXX instead of C, keeping it the same logically? | #include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
void* xmalloc(size_t n) {
void* ptr = malloc(n);
if (ptr == NULL) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
return ptr;
}
void* xrealloc(void* p, size_t n) {
void* ptr = realloc(... |
numeric digits 200
parse arg LOx HIx LOn HIn .
if LOx=='' | LOx=="," then LOx= 1
if HIx=='' | HIx=="," then HIx= LOx + 24
if LOn=='' | LOn=="," then LOn= 2
if HIn=='' | HIn=="," then HIn= LOn + 27
call genP HIn ... |
Translate the given C code snippet into REXX without altering its behavior. | #include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct bit_array_tag {
uint32_t size;
uint32_t* array;
} bit_array;
bool bit_array_create(bit_array* b, uint32_t size) {
uint32_t* array = calloc((size + 31)/32, sizeof(uint32_t));
if (array == ... |
parse arg what
do until what==''
parse var what x n what; parse var x x '-' y
parse var n n '-' m
if x=='' | x=="," then x= 19
if y=='' | y=="," then y= x
if n=='' | n==",... |
Preserve the algorithm and functionality while converting the code from C to REXX. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct stirling_cache_tag {
int max;
int* values;
} stirling_cache;
int stirling_number1(stirling_cache* sc, int n, int k) {
if (k == 0)
return n == 0 ? 1 : 0;
if (n > sc->max || k > n)
return 0;
return sc->values[... |
parse arg lim .
if lim=='' | lim=="," then lim= 12
olim= lim
lim= abs(lim)
numeric digits max(9, 2*lim)
@.=; @.0.0= 1
do n=0 for... |
Maintain the same structure and functionality when rewriting this code in REXX. | #include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct stirling_cache_tag {
int max;
int* values;
} stirling_cache;
int stirling_number1(stirling_cache* sc, int n, int k) {
if (k == 0)
return n == 0 ? 1 : 0;
if (n > sc->max || k > n)
return 0;
return sc->values[... |
parse arg lim .
if lim=='' | lim=="," then lim= 12
olim= lim
lim= abs(lim)
numeric digits max(9, 2*lim)
@.=; @.0.0= 1
do n=0 for... |
Write the same algorithm in REXX as shown in this C implementation. | #include <assert.h>
#include <math.h>
#include <stdio.h>
typedef struct point_tag {
double x;
double y;
} point_t;
double perpendicular_distance(point_t p, point_t p1, point_t p2) {
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
double d = sqrt(dx * dx + dy * dy);
return fabs(p.x * dy - p.... |
parse arg epsilon pts
if epsilon='' | epsilon="," then epsilon= 1
if pts='' then pts= '(0,0) (1,0.1) (2,-0.1) (3,5) (4,6) (5,7) (6,8.1) (7,9) (8,9) (9,9)'
pts= space(pts)
say ' error threshold: ' epsilon
say ' points spe... |
Translate the given C code snippet into REXX without altering its behavior. | #include <assert.h>
#include <math.h>
#include <stdio.h>
typedef struct point_tag {
double x;
double y;
} point_t;
double perpendicular_distance(point_t p, point_t p1, point_t p2) {
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
double d = sqrt(dx * dx + dy * dy);
return fabs(p.x * dy - p.... |
parse arg epsilon pts
if epsilon='' | epsilon="," then epsilon= 1
if pts='' then pts= '(0,0) (1,0.1) (2,-0.1) (3,5) (4,6) (5,7) (6,8.1) (7,9) (8,9) (9,9)'
pts= space(pts)
say ' error threshold: ' epsilon
say ' points spe... |
Port the following code from C to REXX with equivalent syntax and logic. | #include<stdio.h>
#include<math.h>
#define pi M_PI
typedef struct{
double x,y;
}vector;
vector initVector(double r,double theta){
vector c;
c.x = r*cos(theta);
c.y = r*sin(theta);
return c;
}
vector addVector(vector a,vector b){
vector c;
c.x = a.x + b.x;
c.y = a.y + b.y;
return c;
}
vector subtra... | v=.vector~new(12,-3); Say "v=.vector~new(12,-3) =>" v~print
v~ab(1,1,6,4); Say "v~ab(1,1,6,4) =>" v~print
v~al(45,2); Say "v~al(45,2) =>" v~print
w=v~'+'(v); Say "w=v~'+'(v) =>" w~print
x=v~'-'(w); Say "x=v~'-'(w) =>" x~print
y=x~'*'(3); ... |
Convert this C snippet to REXX and keep its semantics consistent. | #include <stdio.h>
#include <math.h>
#define C 7
typedef struct { double x, y; } pt;
pt zero(void) { return (pt){ INFINITY, INFINITY }; }
int is_zero(pt p) { return p.x > 1e20 || p.x < -1e20; }
pt neg(pt p) { return (pt){ p.x, -p.y }; }
pt dbl(pt p) {
if (is_zero(p)) return p;
pt r;
double L = (3 * p.x * p.x)... |
numeric digits 100
a= func(1) ; say ' a = ' show(a)
b= func(2) ; say ' b = ' show(b)
c= add(a, b) ; say ' c = (a+b) =' show(c)
d= neg(c) ... |
Write a version of this C function in REXX with identical behavior. | #include <stdio.h>
#include <math.h>
#define C 7
typedef struct { double x, y; } pt;
pt zero(void) { return (pt){ INFINITY, INFINITY }; }
int is_zero(pt p) { return p.x > 1e20 || p.x < -1e20; }
pt neg(pt p) { return (pt){ p.x, -p.y }; }
pt dbl(pt p) {
if (is_zero(p)) return p;
pt r;
double L = (3 * p.x * p.x)... |
numeric digits 100
a= func(1) ; say ' a = ' show(a)
b= func(2) ; say ' b = ' show(b)
c= add(a, b) ; say ' c = (a+b) =' show(c)
d= neg(c) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.