Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> #include <string.h> void swap(char* p1, char* p2, size_t size) { for (; size-- > 0; ++p1, ++p2) { char tmp = *p1; *p1 = *p2; *p2 = tmp; } } void cocktail_shaker_sort(void* base, size_t count, size_t size, int (*cmp)(const void*, const void*)...
call gen call show 'before sort' say copies('β–ˆ', 101) call cocktailSort # call show ' after sort' exit cocktailSort: proc...
Produce a language-to-language conversion: from C to REXX, same semantics.
#include <assert.h> #include <locale.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)...
parse arg n x hp . if n=='' | n=="," then n= 35 if x=='' | x=="," then x= 600 if hp=='' | hp=="," then hp= 10000000 u= 0 eds=4; ed.1= 1; ed.2= 3; ed.3= 7; ed.4= 9 call genP hp ...
Maintain the same structure and functionality when rewriting this code in REXX.
#include <stdio.h> unsigned int divisor_count(unsigned int n) { unsigned int total = 1; unsigned int p; for (; (n & 1) == 0; n >>= 1) { ++total; } for (p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ++count; }...
parse arg n cols . if n=='' | n=="," then n= 100 if cols=='' | cols=="," then cols= 10 w= max(8, length(n) ) @tau= ' the first ' commas(n) " tau numbers " say ' index β”‚'center(@tau, 1 + cols*(w+1) ) say '───────┼'cente...
Translate the given C code snippet into REXX without altering its behavior.
#include <stdbool.h> #include <stdio.h> bool is_prime(int n) { int i = 5; if (n < 2) { return false; } if (n % 2 == 0) { return n == 2; } if (n % 3 == 0) { return n == 3; } while (i * i <= n) { if (n % i == 0) { return false; } ...
parse arg hi cols target . if hi=='' | hi=="," then hi= 5000 if cols=='' | cols=="," then cols= 10 if target=='' | target=="," then target= 25 call genP w= 10 title= ' primes tha...
Write the same code in REXX as shown below in C.
#include <stdbool.h> #include <stdio.h> bool is_prime(int n) { int i = 5; if (n < 2) { return false; } if (n % 2 == 0) { return n == 2; } if (n % 3 == 0) { return n == 3; } while (i * i <= n) { if (n % i == 0) { return false; } ...
parse arg hi cols target . if hi=='' | hi=="," then hi= 5000 if cols=='' | cols=="," then cols= 10 if target=='' | target=="," then target= 25 call genP w= 10 title= ' primes tha...
Port the following code from C to REXX with equivalent syntax and logic.
#include <stdbool.h> #include <stdio.h> bool primeDigitsSum13(int n) { int sum = 0; while (n > 0) { int r = n % 10; switch (r) { case 2: case 3: case 5: case 7: break; default: return false; } n /= 10; sum +...
parse arg LO HI COLS . if LO=='' | LO=="," then LO= 337 if HI=='' | HI=="," then HI= 322222 if cols=='' | cols=="," then cols= 10 w= 10 title= ' decimal numbers found whose digits are ...
Convert this C snippet to REXX and keep its semantics consistent.
#include <stdbool.h> #include <stdio.h> bool primeDigitsSum13(int n) { int sum = 0; while (n > 0) { int r = n % 10; switch (r) { case 2: case 3: case 5: case 7: break; default: return false; } n /= 10; sum +...
parse arg LO HI COLS . if LO=='' | LO=="," then LO= 337 if HI=='' | HI=="," then HI= 322222 if cols=='' | cols=="," then cols= 10 w= 10 title= ' decimal numbers found whose digits are ...
Rewrite the snippet below in REXX so it works the same as the original C code.
#include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <gmp.h> bool is_prime(uint32_t n) { if (n == 2) return true; if (n < 2 || n % 2 == 0) return false; for (uint32_t p = 3; p * p <= n; p += 2) { if (n % p == 0) ret...
parse arg N hp . if N=='' | N=="," then N= 19 if hp=='' | hp=="," then hip= 1000000 call genP q= 024568 found= 0; $= do j=1 until...
Write a version of this C function in REXX with identical behavior.
#include <stdio.h> #include <stdlib.h> #include <math.h> #define LIMIT 10000 unsigned int sieve(unsigned int n, unsigned int **list) { unsigned char *sieve = calloc(n+1, 1); unsigned int i, j, max = 0; for (i = 2; i*i <= n; i++) if (!sieve[i]) for (j = i+i; j <= n; j += i) ...
parse arg hi cols . if hi=='' | hi=="," then hi= 10000 if cols=='' | cols=="," then cols= 10 w= 10 call genP title= ' Frobenius numbers that a...
Port the following code from C to REXX with equivalent syntax and logic.
#include <stdio.h> #include <stdlib.h> #include <math.h> #define LIMIT 10000 unsigned int sieve(unsigned int n, unsigned int **list) { unsigned char *sieve = calloc(n+1, 1); unsigned int i, j, max = 0; for (i = 2; i*i <= n; i++) if (!sieve[i]) for (j = i+i; j <= n; j += i) ...
parse arg hi cols . if hi=='' | hi=="," then hi= 10000 if cols=='' | cols=="," then cols= 10 w= 10 call genP title= ' Frobenius numbers that a...
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> typedef int(*cmp_func)(const void*, const void*); void perm_sort(void *a, int n, size_t msize, cmp_func _cmp) { char *p, *q, *tmp = malloc(msize); # define A(i) ((char *)a + msize * (i)) # define swap(a, b) {\ memcpy(tmp, a, msize);\ memcpy(a, b, msize);...
options replace format comments java crossref symbols nobinary import java.util.List import java.util.ArrayList numeric digits 20 class RSortingPermutationsort public properties private static iterations maxIterations -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ met...
Write the same code in REXX as shown below in C.
#include <stdio.h> #include <math.h> typedef unsigned long long ulong; ulong root(ulong base, ulong n) { ulong n1, n2, n3, c, d, e; if (base < 2) return base; if (n == 0) return 1; n1 = n - 1; n2 = n; n3 = n1; c = 1; d = (n3 + base) / n2; e = (n3 * d + base / (ulong)powl(d, n1)) ...
parse arg num root digs . if num=='' | num=="," then num= 2 if root=='' | root=="," then root= 2 if digs=='' | digs=="," then digs=2001 numeric digits digs say 'number=' num say ' root=' root...
Change the programming language of this snippet from C to REXX without modifying what it does.
#include <stdio.h> #include <math.h> typedef unsigned long long ulong; ulong root(ulong base, ulong n) { ulong n1, n2, n3, c, d, e; if (base < 2) return base; if (n == 0) return 1; n1 = n - 1; n2 = n; n3 = n1; c = 1; d = (n3 + base) / n2; e = (n3 * d + base / (ulong)powl(d, n1)) ...
parse arg num root digs . if num=='' | num=="," then num= 2 if root=='' | root=="," then root= 2 if digs=='' | digs=="," then digs=2001 numeric digits digs say 'number=' num say ' root=' root...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <gmp.h> int *primeSieve(int limit, int *length) { int i, p, *primes; int j, pc = 0; 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; ...
numeric digits 12 parse arg n cols . if n=='' | n=="," then n= 8 if cols=='' | cols=="," then cols= 10 call genP n**2 pp.= 1 do i=1 for n+1; im= i - 1; pp.i= pp.im * @.i end i=i-1; call genp pp....
Generate an equivalent REXX version of this C code.
int meaning_of_life();
parse source . howInvoked @fn say 'This program ('@fn") was invoked as a: " howInvoked if howInvoked\=='COMMAND' then do say 'This program ('@fn") wasn't invoked via a command." exit 12 end ...
Generate a REXX translation of this C snippet without changing its computational steps.
int meaning_of_life();
parse source . howInvoked @fn say 'This program ('@fn") was invoked as a: " howInvoked if howInvoked\=='COMMAND' then do say 'This program ('@fn") wasn't invoked via a command." exit 12 end ...
Convert this C block to REXX, preserving its control flow and logic.
#define _POSIX_SOURCE #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <string.h> #include <stddef.h> #include <sys/mman.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> struct functionInfo { char* name; int timesCalled; char marked; }; void addToList(...
fid='pgm.rex' cnt.=0 funl='' Do While lines(fid)>0 l=linein(fid) Do Until p=0 p=pos('(',l) If p>0 Then Do do i=p-1 To 1 By -1 While is_tc(substr(l,i,1)) End fn=substr(l,i+1,p-i-1) If fn<>'' Then Call store fn l=substr(l,p+1) End End End Do While funl<>'' ...
Please provide an equivalent version of this C code in REXX.
#include <sqlite3.h> #include <stdlib.h> #include <stdio.h> int main() { sqlite3 *db = NULL; char *errmsg; const char *code = "CREATE TABLE employee (\n" " empID INTEGER PRIMARY KEY AUTOINCREMENT,\n" " firstName TEXT NOT NULL,\n" " lastName TEXT NOT NULL,\n" " AGE INTEGER NOT NULL,\n" " DOB DATE...
id = 000112222 table.id.!firstname = 'Robert' table.id.!middlename = 'Jon' table.id.!lastname = 'Smith' table.id.!dob = '06/09/1946' table.id.!gender = 'm' table.id.!phone = '(111)-222-3333' table.id.!addr = '123 Elm Drive\Apartment 6A' table.id.!town = 'Gotham City'...
Write the same algorithm in REXX as shown in this C implementation.
#include <sqlite3.h> #include <stdlib.h> #include <stdio.h> int main() { sqlite3 *db = NULL; char *errmsg; const char *code = "CREATE TABLE employee (\n" " empID INTEGER PRIMARY KEY AUTOINCREMENT,\n" " firstName TEXT NOT NULL,\n" " lastName TEXT NOT NULL,\n" " AGE INTEGER NOT NULL,\n" " DOB DATE...
id = 000112222 table.id.!firstname = 'Robert' table.id.!middlename = 'Jon' table.id.!lastname = 'Smith' table.id.!dob = '06/09/1946' table.id.!gender = 'm' table.id.!phone = '(111)-222-3333' table.id.!addr = '123 Elm Drive\Apartment 6A' table.id.!town = 'Gotham City'...
Rewrite the snippet below in REXX so it works the same as the original C code.
#include <stdbool.h> #include <stdio.h> bool is_prime(unsigned int n) { if (n < 2) { return false; } if (n % 2 == 0) { return n == 2; } if (n % 3 == 0) { return n == 3; } for (unsigned int p = 5; p * p <= n; p += 4) { if (n % p == 0) { return fals...
n=1000 prime = .Array~new(n)~fill(.true)~~remove(1) p.=0 Do i = 2 to n If prime[i] = .true Then Do Do j = i * i to n by i prime~remove(j) End p.i=1 End End z=0 ol='' Do i=500 To 1000 If p.i then Do dr=digroot(i) If p.dr Then Do ol=ol' 'i'('dr')' z=z+1 If z//10=0...
Produce a functionally identical REXX code for the snippet given in C.
#include <stdbool.h> #include <stdio.h> bool is_prime(unsigned int n) { if (n < 2) { return false; } if (n % 2 == 0) { return n == 2; } if (n % 3 == 0) { return n == 3; } for (unsigned int p = 5; p * p <= n; p += 4) { if (n % p == 0) { return fals...
n=1000 prime = .Array~new(n)~fill(.true)~~remove(1) p.=0 Do i = 2 to n If prime[i] = .true Then Do Do j = i * i to n by i prime~remove(j) End p.i=1 End End z=0 ol='' Do i=500 To 1000 If p.i then Do dr=digroot(i) If p.dr Then Do ol=ol' 'i'('dr')' z=z+1 If z//10=0...
Preserve the algorithm and functionality while converting the code from C to REXX.
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int days[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m, y, w; if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1; days[1] -= (y % 4) || (!(y % 100) && (y % 400)); w = y * 365 + 97 * (y - 1) / 400 + ...
parse arg yyyy do j=1 for 12 _ = lastDOW('Sunday', j, yyyy) say right(_,4)'-'right(j,2,0)"-"left(word(_,2),2) end exit β”‚ lastDOW: procedure to return the date of the last day-of-week of β”‚ β”‚ ...
Translate the given C code snippet into REXX without altering its behavior.
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int days[] = {31,29,31,30,31,30,31,31,30,31,30,31}; int m, y, w; if (argc < 2 || (y = atoi(argv[1])) <= 1752) return 1; days[1] -= (y % 4) || (!(y % 100) && (y % 400)); w = y * 365 + 97 * (y - 1) / 400 + ...
parse arg yyyy do j=1 for 12 _ = lastDOW('Sunday', j, yyyy) say right(_,4)'-'right(j,2,0)"-"left(word(_,2),2) end exit β”‚ lastDOW: procedure to return the date of the last day-of-week of β”‚ β”‚ ...
Generate an equivalent REXX version of this C code.
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> int randInt(int low, int high) { return (rand() % (high - low)) + low; } void shuffle(int *const array, const int n) { if (n > 1) { int i; for (i = 0; i < n - 1; i++) { int j = randI...
parse arg N seed . if N=='' | N=="," then N= 5 if datatype(seed, 'W') then call random ,,seed w= length(N - 1) $= do i=0 for N; $= $ right(i, w, '_') end z= ...
Generate a REXX translation of this C snippet without changing its computational steps.
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <glib.h> int string_compare(gconstpointer p1, gconstpointer p2) { const char* const* s1 = p1; const char* const* s2 = p2; return strcmp(*s1, *s2); } GPtrArray* load_dictionary(const char* file, GError** error_ptr) { GError* error = N...
parse arg iFID L . if iFID==''|iFID=="," then iFID= 'wordlist.10k' if L==''| L=="," then L= 3 #= 0 @.= do r=0 while lines(iFID) \== 0 parse upper ...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include <stdio.h> #include <stdlib.h> int turn(int base, int n) { int sum = 0; while (n != 0) { int rem = n % base; n = n / base; sum += rem; } return sum % base; } void fairshare(int base, int count) { int i; printf("Base %2d:", base); for (i = 0; i < count; i++)...
parse arg n g if n=='' | n=="," then n= 25 if g='' | g="," then g= 2 3 5 11 do p=1 for words(g); r= word(g, p) $= 'base' right(r, 2)': ' do j=0 for...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include <stdio.h> #include <string.h> #include <locale.h> typedef int bool; typedef unsigned long long ull; #define TRUE 1 #define FALSE 0 char as_digit(int d) { return (d >= 0 && d <= 9) ? d + '0' : d - 10 + 'a'; } void revstr(char *str) { int i, len = strlen(str); char t; for (i = 0; i < le...
parse arg baseL baseH range if baseL=='' | baseL=="," then baseL= 2 if baseH=='' | baseH=="," then baseH=16 if range=='' | range=="," then range=1000..9999 do radix=baseL to baseH; #= 0; if radix<2 then iterate start= radix * 4; stop = rad...
Port the following code from C to REXX with equivalent syntax and logic.
#include<stdlib.h> #include<string.h> #include<stdio.h> int flag = 1; void heapPermute(int n, int arr[],int arrLen){ int temp; int i; if(n==1){ printf("\n["); for(i=0;i<arrLen;i++) printf("%d,",arr[i]); printf("\b] SignΒ : %d",flag); flag*=-1; } else{ for(i=0;i<n-1;i++){ heapPermute(n-1,ar...
Parse Arg things e.='' Select When things='?' Then Call help When things='' Then things=4 When words(things)>1 Then Do elements=things things=words(things) Do i=0 By 1 While elements<>'' Parse Var elements e.i elements End End Otherwise If datatype(things)<>'NUM' Then...
Port the provided C code into REXX while preserving the original functionality.
#include <stdio.h> #include <stdlib.h> #include <time.h> int compareInts(const void *i1, const void *i2) { int a = *((int *)i1); int b = *((int *)i2); return a - b; } int main() { int i, j, nsum, vsum, vcount, values[6], numbers[4]; srand(time(NULL)); for (;;) { vsum = 0; for (...
Generates 4 random, whole values between 1 and 6. Saves the sum of the 3 largest values. Generates a total of 6 values this way. Displays the total, and all 6 values once finished. */ Do try=1 By 1 ge15=0 sum=0 ol='' Do i=1 To 6 rl='' Do j=1 To 4 rl=rl (random(5)+1) End rl=wordsort(rl) ...
Port the provided C code into REXX while preserving the original functionality.
#include <stdio.h> #define MAX 15 int count_divisors(int n) { int i, count = 0; for (i = 1; i * i <= n; ++i) { if (!(n % i)) { if (i == n / i) count++; else count += 2; } } return count; } int main() { int i, k, n, seq[MAX]; ...
parse arg N . if N=='' | N=="," then N= 15 say '──divisors── ──smallest number with N divisors──' @.= do i=1 for N; z= 1 + (i\==1) do j=z by z if @....
Produce a functionally identical REXX code for the snippet given in C.
#include<string.h> #include<stdlib.h> #include<locale.h> #include<stdio.h> #include<wchar.h> #include<math.h> int main(int argC,char* argV[]) { double* arr,min,max; char* str; int i,len; if(argC == 1) printf("UsageΒ : %s <data points separated by spaces or commas>",argV[0]); else{ arr = (double*)malloc((argC-1...
options replace format comments java crossref symbols nobinary runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method sparkline(spark) private static spark = spark.changestr(',', ' ') bars = '\u2581 \u2582 \u2583 \u2584 \u2585 \u2586 \u2587 \u2588' barK = ...
Keep all operations the same but rewrite the snippet in REXX.
#include <stdio.h> #include <stdlib.h> struct node { int val, len; struct node *next; }; void lis(int *v, int len) { int i; struct node *p, *n = calloc(len, sizeof *n); for (i = 0; i < len; i++) n[i].val = v[i]; for (i = len; i--; ) { for (p = n + i; p++ < n + len; ) { if (p->val > n[i].val && p->len...
$.=; $.1= 3 2 6 4 5 1 $.2= 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15 do j=1 while $.j\==''; say say ' input: ' $.j call LIS $.j say 'output: ' result end exi...
Port the provided C code into REXX while preserving the original functionality.
#define STATIC_ASSERT(COND,MSG) typedef char static_assertion_##MSG[(!!(COND))*2-1] #define COMPILE_TIME_ASSERT3(X,L) STATIC_ASSERT(X,static_assertion_at_line_##L) #define COMPILE_TIME_ASSERT2(X,L) COMPILE_TIME_ASSERT3(X,L) #define COMPILE_TIME_ASSERT(X) COMPILE_TIME_ASSERT2(X,__LINE__) COMPILE_TIME_ASSERT(sizeof...
β”‚ The REXX language doesn't allow for the changing or overriding of β”‚ β”‚ syntax per se, but any of the built-in-functions (BIFs) can be β”‚ β”‚ overridden by just specifying your own. β”‚ β”‚ β”‚ β”‚ To use the REXX's version o...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_WORD_SIZE 80 #define MIN_LENGTH 9 #define WORD_SIZE (MIN_LENGTH + 1) 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("O...
parse arg minL iFID . if minL=='' | minL=="," then minL= 9 if iFID=='' | iFID=="," then iFID='unixdict.txt' #= 0; @.=; !.= 0 do recs=0 while lines(iFID)\==0 x= strip( linein( iFID) ) if leng...
Convert this C snippet to REXX and keep its semantics consistent.
#include <stdio.h> #include <wchar.h> #include <stdlib.h> #include <locale.h> int main(void) { char *locale = setlocale(LC_ALL, ""); FILE *in = fopen("input.txt", "r"); wint_t c; while ((c = fgetwc(in)) != WEOF) putwchar(c); fclose(in); return EXIT_SUCCESS; }
options replace format comments java crossref symbols nobinary numeric digits 20 runSample(arg) return -- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ method readCharacters(fName) public static binary returns String slurped = String('') slrp = StringBuilder() fr = Reader null ...
Rewrite the snippet below in REXX so it works the same as the original C code.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define BALLS 1024 int n, w, h = 45, *x, *y, cnt = 0; char *b; #define B(y, x) b[(y)*w + x] #define C(y, x) ' ' == b[(y)*w + x] #define V(i) B(y[i], x[i]) inline int rnd(int a) { return (rand()/(RAND_MAX/a))%a; } void show_board() { int i, j; for (puts("\0...
trace off if !all(arg()) then exit signal on halt parse arg rows balls freeze seed . if rows =='' | rows=="," then rows= 0 if balls=='' | balls=="," then balls= 100 if freeze=='' | fre...
Preserve the algorithm and functionality while converting the code from C to REXX.
#include <stdio.h> void f(int n) { int i = 1; if (n < 1) { return; } while (1) { int sq = i * i; while (sq > n) { sq /= 10; } if (sq == n) { printf("%3d %9d %4d\n", n, i * i, i); return; } i++; } } int main...
numeric digits 20 parse arg n cols . if n=='' | n=="," then n= 50 if cols=='' | cols=="," then cols= 10 w= 10 say ' index β”‚'center(" smallest squares that begin with N < " n, ...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include <stdio.h> void f(int n) { int i = 1; if (n < 1) { return; } while (1) { int sq = i * i; while (sq > n) { sq /= 10; } if (sq == n) { printf("%3d %9d %4d\n", n, i * i, i); return; } i++; } } int main...
numeric digits 20 parse arg n cols . if n=='' | n=="," then n= 50 if cols=='' | cols=="," then cols= 10 w= 10 say ' index β”‚'center(" smallest squares that begin with N < " n, ...
Translate the given C code snippet into REXX without altering its behavior.
#include <stdio.h> int circle_sort_inner(int *start, int *end) { int *p, *q, t, swapped; if (start == end) return 0; for (swapped = 0, p = start, q = end; p<q || (p==q && ++q); p++, q--) if (*p > *q) t = *p, *p = *q, *q = t, swapped = 1; return swapped | circle_sort_inner(start, q) | circle_sort_inner(...
parse arg x if x='' | x="," then x= 6 7 8 9 2 5 3 4 1 call make_array 'before sort:' call circleSort # call make_list ' after sort:' exit circleSort: d...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdbool.h> #include <stdio.h> #define MAX_WORD 80 #define LETTERS 26 bool is_letter(char c) { return c >= 'a' && c <= 'z'; } int index(char c) { return c - 'a'; } void word_wheel(const char* letters, char central, int min_length, FILE* dict) { int max_count[LETTERS] = { 0 }; for (const char* p = l...
parse arg grid minL iFID . if grid==''|grid=="," then grid= 'ndeokgelw' if minL==''|minL=="," then minL= 3 if iFID==''|iFID=="," then iFID= 'UNIXDICT.TXT' oMinL= minL; minL= abs(minL) gridU= grid; upper gridU Lg= length(grid); ...
Translate this program into REXX but keep the logic exactly as in C.
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFER_SIZE 128 typedef unsigned char character; typedef character *string; typedef struct node_t node; struct node_t { enum tag_t { NODE_LEAF, NODE_TREE, NODE_SEQ, } tag; union { stri...
* Brace expansion * 26.07.2016 * s.* holds the set of strings *--------------------------------------------------------------------*/ text.1='{,{,gotta have{ ,\, again\, }}more }cowbell!' text.2='~/{Downloads,Pictures} text.3='It{{em,alic}iz,erat}e{d,}, please. ' text.4='{}} some }{,{\\{ edge, edge} \,}{ cases, {here}...
Write the same code in REXX as shown below in C.
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Wheel { char *seq; int len; int pos; }; struct Wheel *create(char *seq) { struct Wheel *w = malloc(sizeof(struct Wheel)); if (w == NULL) { return NULL; } w->seq = seq; w->len = strlen(seq); w->pos = 0; ...
@.= parse arg lim @.1 if lim='' | lim="," then lim= 20 if @.1='' | @.1="," then do; @.1= ' A: 1 2 3 ' @.2= ' A: 1 B 2, B: 3 4 ' @.3= ' A: 1 D D, D: 6...
Convert this C snippet to REXX and keep its semantics consistent.
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Wheel { char *seq; int len; int pos; }; struct Wheel *create(char *seq) { struct Wheel *w = malloc(sizeof(struct Wheel)); if (w == NULL) { return NULL; } w->seq = seq; w->len = strlen(seq); w->pos = 0; ...
@.= parse arg lim @.1 if lim='' | lim="," then lim= 20 if @.1='' | @.1="," then do; @.1= ' A: 1 2 3 ' @.2= ' A: 1 B 2, B: 3 4 ' @.3= ' A: 1 D D, D: 6...
Convert this C snippet to REXX and keep its semantics consistent.
#include <X11/Xlib.h> void get_pixel_color (Display *d, int x, int y, XColor *color) { XImage *image; image = XGetImage (d, RootWindow (d, DefaultScreen (d)), x, y, 1, 1, AllPlanes, XYPixmap); color->pixel = XGetPixel (image, 0, 0); XFree (image); XQueryColor (d, DefaultColormap(d, DefaultScreen (d)), color);...
parse value cursor() with r c . hue=scrRead(r, c, 1, 'A') if hue=='00'x then color= 'black' if hue=='01'x then color= 'darkblue' if hue=='02'x then color= 'darkgreen' if hue=='03'x then color= 'darkturquoise' if hue=='04'x then color= 'darkred' ...
Generate an equivalent REXX version of this C code.
#include<stdio.h> #include<math.h> typedef struct{ double x,y; }point; double distance(point p1,point p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } void findCircles(point p1,point p2,double radius) { double separation = distance(p1,p2),mirrorDistance; if(separation == 0.0) { radiu...
a.='' a.1=0.1234 0.9876 0.8765 0.2345 2 a.2=0.0000 2.0000 0.0000 0.0000 1 a.3=0.1234 0.9876 0.1234 0.9876 2 a.4=0.1234 0.9876 0.8765 0.2345 0.5 a.5=0.1234 0.9876 0.1234 0.9876 0 Say ' x1 y1 x2 y2 radius cir1x cir1y cir2x cir2y' Say ' ------ ------ ------ ------ ------ ...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include<stdio.h> #include<math.h> typedef struct{ double x,y; }point; double distance(point p1,point p2) { return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)); } void findCircles(point p1,point p2,double radius) { double separation = distance(p1,p2),mirrorDistance; if(separation == 0.0) { radiu...
a.='' a.1=0.1234 0.9876 0.8765 0.2345 2 a.2=0.0000 2.0000 0.0000 0.0000 1 a.3=0.1234 0.9876 0.1234 0.9876 2 a.4=0.1234 0.9876 0.8765 0.2345 0.5 a.5=0.1234 0.9876 0.1234 0.9876 0 Say ' x1 y1 x2 y2 radius cir1x cir1y cir2x cir2y' Say ' ------ ------ ------ ------ ------ ...
Rewrite the snippet below in REXX so it works the same as the original C code.
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <math.h> typedef uint64_t xint; typedef unsigned long long ull; xint tens[20]; inline xint max(xint a, xint b) { return a > b ? a : b; } inline xint min(xint a, xint b) { return a < b ? a : b; } inline int ndigits(xint x) { int n = 0; while (x) n+...
parse arg N . if N=='' | N=="," then N= 25 !.0= 1260; !.1= 11453481; !.2= 115672; !.3= 124483; !.4= 105264 !.5= 1395; !.6= 126846; !.7= 1827; !.8= 110758; !.9= 156289 L= length(N); aN= abs(N) numeric digits max(9,...
Maintain the same structure and functionality when rewriting this code in REXX.
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #define SIM_N 5 #define PRINT_DISCARDED 1 #define min(x,y) ((x<y)?(x):(y)) typedef uint8_t card_t; unsigned int rand_n(unsigned int n) { unsigned int out, mask = 1; while (mask < n) mask = mask<<1 | 1; do { out =...
parse arg trials # shuffs seed . if trials=='' | trials=="," then trials= 1000 if #=='' | #=="," then #= 52 if shuffs=='' | shuffs=="," then shuffs= #%4 if datatype(seed, 'W') then call random ,,seed ok=0 ...
Rewrite the snippet below in REXX so it works the same as the original C code.
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #define SIM_N 5 #define PRINT_DISCARDED 1 #define min(x,y) ((x<y)?(x):(y)) typedef uint8_t card_t; unsigned int rand_n(unsigned int n) { unsigned int out, mask = 1; while (mask < n) mask = mask<<1 | 1; do { out =...
parse arg trials # shuffs seed . if trials=='' | trials=="," then trials= 1000 if #=='' | #=="," then #= 52 if shuffs=='' | shuffs=="," then shuffs= #%4 if datatype(seed, 'W') then call random ,,seed ok=0 ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> #define GRID_SIZE 15 char canvas[GRID_SIZE][GRID_SIZE]; void initN() { int i, j; for (i = 0; i < GRID_SIZE; i++) { for (j = 0; j < GRID_SIZE; j++) { canvas[i][j] = ' '; } canvas[i][5] = 'x'; } } void horizontal(size_t c1, size_t c2, size_t r) { s...
parse arg m if m='' | m="," then m= 0 1 20 300 4000 5555 6789 9393 $.=; nnn= words(m) do j=1 for nnn; z= word(m, j) if \datatype(z, 'W') then call serr "number isn't numeric: " z if \datatype(...
Preserve the algorithm and functionality while converting the code from C to REXX.
#include <stdio.h> #define GRID_SIZE 15 char canvas[GRID_SIZE][GRID_SIZE]; void initN() { int i, j; for (i = 0; i < GRID_SIZE; i++) { for (j = 0; j < GRID_SIZE; j++) { canvas[i][j] = ' '; } canvas[i][5] = 'x'; } } void horizontal(size_t c1, size_t c2, size_t r) { s...
parse arg m if m='' | m="," then m= 0 1 20 300 4000 5555 6789 9393 $.=; nnn= words(m) do j=1 for nnn; z= word(m, j) if \datatype(z, 'W') then call serr "number isn't numeric: " z if \datatype(...
Change the programming language of this snippet from C to REXX without modifying what it does.
#include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #define TRUE 1 #define FALSE 0 #define FACES "23456789tjqka" #define SUITS "shdc" typedef int bool; typedef struct { int face; char suit; } card; card cards[5]; int compare_card(const void *a, const void *b) { card c1 = *(...
* 10.12.2013 Walter Pachl *--------------------------------------------------------------------*/ d.1='2h 2d 2s ks qd'; x.1='three-of-a-kind' d.2='2h 5h 7d 8s 9d'; x.2='high-card' d.3='ah 2d 3s 4s 5s'; x.3='straight' d.4='2h 3h 2d 3s 3d'; x.4='full-house' d.5='2h 7h 2d 3s 3d'; x.5='two-pair' d.6='2h 7h 7d 7s 7c'; x.6...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> #include <ctype.h> #include <string.h> #include <stdlib.h> #define TRUE 1 #define FALSE 0 #define FACES "23456789tjqka" #define SUITS "shdc" typedef int bool; typedef struct { int face; char suit; } card; card cards[5]; int compare_card(const void *a, const void *b) { card c1 = *(...
* 10.12.2013 Walter Pachl *--------------------------------------------------------------------*/ d.1='2h 2d 2s ks qd'; x.1='three-of-a-kind' d.2='2h 5h 7d 8s 9d'; x.2='high-card' d.3='ah 2d 3s 4s 5s'; x.3='straight' d.4='2h 3h 2d 3s 3d'; x.4='full-house' d.5='2h 7h 2d 3s 3d'; x.5='two-pair' d.6='2h 7h 7d 7s 7c'; x.6...
Please provide an equivalent version of this C code in REXX.
#include <stdio.h> int main(void) { puts( "%!PS-Adobe-3.0 EPSF\n" "%%BoundingBox: -10 -10 400 565\n" "/a{0 0 moveto 0 .4 translate 0 0 lineto stroke -1 1 scale}def\n" "/b{a 90 rotate}def"); char i; for (i = 'c'; i <= 'z'; i++) printf("/%c{%c %c}def\n", i, i-1, i-2); puts("0 setlinewidth z showpage\n%%EOF...
parse arg order . if order=='' | order=="," then order= 23 tell= order>=0 s= FibWord( abs(order) ) x= 0; maxX= 0; dx= 0; b= ' '; @. = b; xp= 0 y=...
Convert this C snippet to REXX and keep its semantics consistent.
#include <stdio.h> #include <stdlib.h> #include <time.h> #define SEQLEN 3 int getseq(char *s) { int r = 0; int i = 1 << (SEQLEN - 1); while (*s && i) { switch (*s++) { case 'H': case 'h': r |= i; break; case 'T': case...
__= copies('─', 9) signal on halt parse arg # seed . if #=='' | #=="," then #= 3 if datatype(seed,'W') then call random ,,seed wins=0; do games=1 call gam...
Preserve the algorithm and functionality while converting the code from C to REXX.
#include <stdio.h> #include <string.h> void nb(int cells, int total_block_size, int* blocks, int block_count, char* output, int offset, int* count) { if (block_count == 0) { printf("%2d %s\n", ++*count, output); return; } int block_size = blocks[0]; int max_pos = cells - (total...
$.=; $.1= 5 2 1 $.2= 5 $.3= 10 8 $.4= 15 2 3 2 3 $.5= 5 2 3 do i=1 while $.i\=='' parse var $.i N blocks N= strip(N); blocks= space(blocks) call nono ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> #include <string.h> void nb(int cells, int total_block_size, int* blocks, int block_count, char* output, int offset, int* count) { if (block_count == 0) { printf("%2d %s\n", ++*count, output); return; } int block_size = blocks[0]; int max_pos = cells - (total...
$.=; $.1= 5 2 1 $.2= 5 $.3= 10 8 $.4= 15 2 3 2 3 $.5= 5 2 3 do i=1 while $.i\=='' parse var $.i N blocks N= strip(N); blocks= space(blocks) call nono ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include "stdio.h" #include "stdbool.h" #define ARRAY_LEN(a,T) (sizeof(a) / sizeof(T)) struct Interval { int start, end; bool print; }; int main() { struct Interval intervals[] = { {2, 1000, true}, {1000, 4000, true}, {2, 10000, false}, {2, 100000, false}, {2, 1000...
numeric digits 20 parse arg $ if $='' then $= '1 1000 1000 4000 1 -10000 1 -100000 1 -1000000 1 -10000000' do k=1 by 2 to words($) call banE word($, k), word($, k+1) end exit ...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include "stdio.h" #include "stdbool.h" #define ARRAY_LEN(a,T) (sizeof(a) / sizeof(T)) struct Interval { int start, end; bool print; }; int main() { struct Interval intervals[] = { {2, 1000, true}, {1000, 4000, true}, {2, 10000, false}, {2, 100000, false}, {2, 1000...
numeric digits 20 parse arg $ if $='' then $= '1 1000 1000 4000 1 -10000 1 -100000 1 -1000000 1 -10000000' do k=1 by 2 to words($) call banE word($, k), word($, k+1) end exit ...
Keep all operations the same but rewrite the snippet in REXX.
#include <stdio.h> #include <string.h> #include <stdint.h> #include <stdlib.h> #define MAX(x,y) ((x) > (y)Β ? (x)Β : (y)) #define MIN(x,y) ((x) < (y)Β ? (x)Β : (y)) size_t base20(unsigned int n, uint8_t *out) { uint8_t *start = out; do {*out++ = n % 20;} while (n /= 20); size_t length = out - start; ...
parse arg $ if $='' then $= 4005 8017 326205 886205, 172037122592320200101 do j=1 for words($) #= word($, j) say say center('converting the decimal number ' # " to ...
Write the same code in REXX as shown below in C.
#include <stdio.h> int valid(int n, int nuts) { int k; for (k = n; k; k--, nuts -= 1 + nuts/n) if (nuts%n != 1) return 0; return nuts && !(nuts%n); } int main(void) { int n, x; for (n = 2; n < 10; n++) { for (x = 0; !valid(n, x); x++); printf("%d: %d\n", n, x); } return 0; }
parse arg L H .; if L=='' then L= 5 if H=='' then H= 6 do n=L to H do $=0 while \valid(n, $) end say 'sailors='n " coco...
Translate the given C code snippet into REXX without altering its behavior.
#include <stdio.h> int valid(int n, int nuts) { int k; for (k = n; k; k--, nuts -= 1 + nuts/n) if (nuts%n != 1) return 0; return nuts && !(nuts%n); } int main(void) { int n, x; for (n = 2; n < 10; n++) { for (x = 0; !valid(n, x); x++); printf("%d: %d\n", n, x); } return 0; }
parse arg L H .; if L=='' then L= 5 if H=='' then H= 6 do n=L to H do $=0 while \valid(n, $) end say 'sailors='n " coco...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include<unistd.h> #include<stdio.h> #include<time.h> #define SHORTLAG 1000 #define LONGLAG 2000 int main(){ int i,times,hour,min,sec,min1,min2; time_t t; struct tm* currentTime; while(1){ time(&t); currentTime = localtime(&t); hour = currentTime->tm_hour; min = currentTime->tm_min; sec = curren...
Parse Arg msg If msg='?' Then Do Say 'Ring a nautical bell' Exit End Signal on Halt Do Forever Parse Value time() With hh ':' mn ':' ss ct=time('C') hhmmc=left(right(ct,7,0),5) If msg>'' Then Say center(arg(1) ct time(),79) If ss==00 & ( mn==00...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include<unistd.h> #include<stdio.h> #include<time.h> #define SHORTLAG 1000 #define LONGLAG 2000 int main(){ int i,times,hour,min,sec,min1,min2; time_t t; struct tm* currentTime; while(1){ time(&t); currentTime = localtime(&t); hour = currentTime->tm_hour; min = currentTime->tm_min; sec = curren...
Parse Arg msg If msg='?' Then Do Say 'Ring a nautical bell' Exit End Signal on Halt Do Forever Parse Value time() With hh ':' mn ':' ss ct=time('C') hhmmc=left(right(ct,7,0),5) If msg>'' Then Say center(arg(1) ct time(),79) If ss==00 & ( mn==00...
Write the same code in REXX as shown below in C.
#include<stdio.h> #include<conio.h> #include<math.h> #include<dos.h> typedef struct{ char str[3]; int key; }note; note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}}; int main(void) { int i=0; while(!kbhit()) { printf("\t%s",sequence[i].str); sound(261.63*pow(2,...
* 24.02.2013 Walter Pachl derived from original REXX version * Changes: sound(f,sec) --> beep(trunc(f),millisec) * $ -> sc * @. -> f. * re > ra (in sc) *--------------------------------------------------------------------*/ sc='do ra mi fa so la te do' dur=1250 ...
Translate the given C code snippet into REXX without altering its behavior.
#include<stdio.h> #include<conio.h> #include<math.h> #include<dos.h> typedef struct{ char str[3]; int key; }note; note sequence[] = {{"Do",0},{"Re",2},{"Mi",4},{"Fa",5},{"So",7},{"La",9},{"Ti",11},{"Do",12}}; int main(void) { int i=0; while(!kbhit()) { printf("\t%s",sequence[i].str); sound(261.63*pow(2,...
* 24.02.2013 Walter Pachl derived from original REXX version * Changes: sound(f,sec) --> beep(trunc(f),millisec) * $ -> sc * @. -> f. * re > ra (in sc) *--------------------------------------------------------------------*/ sc='do ra mi fa so la te do' dur=1250 ...
Write a version of this C function in REXX with identical behavior.
#include <ctime> #include <cstdint> extern "C" { int64_t from date(const char* string) { struct tm tmInfo = {0}; strptime(string, "%Y-%m-%d", &tmInfo); return mktime(&tmInfo); } }
patients='patients.csv' l=linein(patients) Parse Var l h1 ',' h2 n=0 idl='' Do n=1 By 1 While lines(patients)>0 l=linein(patients) Parse Var l id ',' lastname.id idl=idl id End n=n-1 visits='visits.csv' l=linein(visits) h3='LAST_VISIT' h4='SCORE_SUM' h5='SCORE_AVG' date.='' score.=0 Say '|' h1 '|' h2 '|' h3 ...
Write the same algorithm in REXX as shown in this C implementation.
#include <ldap.h> ... char *name, *password; ... LDAP *ld = ldap_init("ldap.somewhere.com", 389); ldap_simple_bind_s(ld, name, password); ... after done with it... ldap_unbind(ld);
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.exception.LdapException import org.slf4j.Logger import org.slf4j.LoggerFactory class ...
Produce a functionally identical REXX code for the snippet given in C.
#include <stdio.h> int main(int argc, char **argv){ int i; const char *commands[]={"-c", "-p", "-t", "-d", "-a", NULL}; enum {CREATE,PRINT,TITLE,DATE,AUTH}; if (argc<2) { usage: printf ("Usage: %s [commands]\n" "-c Create new entry.\n" "-p Print the latest entry.\n" ...
parse arg opts opts=space(opts) !.= do while opts\=='' parse var opts x opts select when x=='-e' ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> int main(int argc, char **argv){ int i; const char *commands[]={"-c", "-p", "-t", "-d", "-a", NULL}; enum {CREATE,PRINT,TITLE,DATE,AUTH}; if (argc<2) { usage: printf ("Usage: %s [commands]\n" "-c Create new entry.\n" "-p Print the latest entry.\n" ...
parse arg opts opts=space(opts) !.= do while opts\=='' parse var opts x opts select when x=='-e' ...
Write the same algorithm in REXX as shown in this C implementation.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int *board, *flood, *known, top = 0, w, h; static inline int idx(int y, int x) { return y * w + x; } int neighbors(int c, int *p) { int i, j, n = 0; int y = c / w, x = c % w; for (i = y - 1; i <= y + 1; i++) { if (i < 0 || i >= h) c...
maxR=0; maxC=0; maxX=0; minR=9e9; minC=9e9; minX=9e9; cells=0; @.= parse arg xxx; PZ='Hidato puzzle' xxx=translate(xxx, , "/\;:_", ',') do while xxx\=''; parse var xxx r c marks ',' xxx do while marks\=''; _=@...
Produce a language-to-language conversion: from C to REXX, same semantics.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int *board, *flood, *known, top = 0, w, h; static inline int idx(int y, int x) { return y * w + x; } int neighbors(int c, int *p) { int i, j, n = 0; int y = c / w, x = c % w; for (i = y - 1; i <= y + 1; i++) { if (i < 0 || i >= h) c...
maxR=0; maxC=0; maxX=0; minR=9e9; minC=9e9; minX=9e9; cells=0; @.= parse arg xxx; PZ='Hidato puzzle' xxx=translate(xxx, , "/\;:_", ',') do while xxx\=''; parse var xxx r c marks ',' xxx do while marks\=''; _=@...
Produce a functionally identical REXX code for the snippet given in C.
#include <stdio.h> typedef struct node_t *node, node_t; struct node_t { int v; node next; }; typedef struct { node head, tail; } slist; void push(slist *l, node e) { if (!l->head) l->head = e; if (l->tail) l->tail->next = e; l->tail = e; } node removehead(slist *l) { node e = l->head; if (e) { l->head = e->n...
options replace format comments java crossref savelog symbols binary import java.util.List placesList = [String - "UK London", "US New York", "US Boston", "US Washington" - , "UK Washington", "US Birmingham", "UK Birmingham", "UK Boston" - ] lists = [ - placesList - , strandSort(St...
Translate the given C code snippet into REXX without altering its behavior.
#define PI 3.141592653589793 #define TWO_PI 6.283185307179586 double normalize2deg(double a) { while (a < 0) a += 360; while (a >= 360) a -= 360; return a; } double normalize2grad(double a) { while (a < 0) a += 400; while (a >= 400) a -= 400; return a; } double normalize2mil(double a) { while (a < 0) a +...
numeric digits length( pi() ) - length(.) parse arg x if x='' | x="," then x= '-2 -1 0 1 2 6.2831853 16 57.2957795 359 399 6399 1000000' w= 20; w7= w+7 @deg = 'degrees'; @grd= "gradians"; @mil = 'mils'; @rad = "rad...
Generate an equivalent REXX version of this C code.
#include <libxml/parser.h> #include <libxml/xpath.h> xmlDocPtr getdoc (char *docname) { xmlDocPtr doc; doc = xmlParseFile(docname); return doc; } xmlXPathObjectPtr getnodeset (xmlDocPtr doc, xmlChar *xpath){ xmlXPathContextPtr context; xmlXPathObjectPtr result; context = xmlXPathNewContext(doc); result = ...
options replace format comments java symbols binary import javax.xml.parsers. import javax.xml.xpath. import org.w3c.dom. import org.w3c.dom.Node import org.xml.sax. xmlStr = '' - || '<inventory title="OmniCorp Store #45x10^3">' - || ' <section name="health">' - || ' <item upc="123456789" stock="12">' - ...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include<stdlib.h> #include<stdio.h> typedef struct{ int score; char name[100]; }entry; void ordinalRanking(entry* list,int len){ int i; printf("\n\nOrdinal Ranking\n---------------"); for(i=0;i<len;i++) printf("\n%d\t%d\t%s",i+1,list[i].score,list[i].name); } void standardRanking(entry* list,int len){ ...
44 Solomon 1 1 1 1 1 42 Jason 2 3 2 2 2.5 42 Errol 2 3 2 3 2.5 41 Garry 4 6 3 4 5 41 Bernard 4 6 3 5 5 41 Barry 4 6 3 6 5 39 Stephen 7 7 4 7 7 **************************/ Do i=1 To 7 Parse Value sourceline(i+1) With rank.i name.i . End pool=0 crank=0 Do i=1 To 7 If rank.i<>crank Then Do poo...
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_usleep(WrenVM* vm) { useconds_t usec = (useconds_t)wrenGetSlotDouble(vm, 1); usleep(usec); } void C_espeak(WrenVM* vm) { const char *arg = wrenGetSlotString(vm, 1); char command[strlen(arg) + 10]; ...
parse arg t #= words(t) if #==0 then exit dq= '"' rate= 1 do j=1 for # x= word(t, j); upper x ...
Write a version of this C function in REXX with identical behavior.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include "wren.h" void C_usleep(WrenVM* vm) { useconds_t usec = (useconds_t)wrenGetSlotDouble(vm, 1); usleep(usec); } void C_espeak(WrenVM* vm) { const char *arg = wrenGetSlotString(vm, 1); char command[strlen(arg) + 10]; ...
parse arg t #= words(t) if #==0 then exit dq= '"' rate= 1 do j=1 for # x= word(t, j); upper x ...
Write the same code in REXX as shown below in C.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define strcomp(X, Y) strcasecmp(X, Y) struct option { const char *name, *value; int flag; }; struct option updlist[] = { { "NEEDSPEELING", NULL }, { "SEEDSREMOVED", "" }, { "NUMBEROFBANANAS", "1024" }, { "NUMBEROFSTRAWBERRIES", "62000" }, { NULL...
parse arg iFID oFID . if iFID=='' | iFID=="," then iFID= 'UPDATECF.TXT' if oFID=='' | oFID=="," then oFID='\TEMP\UPDATECF.$$$' call lineout iFID; call lineout oFID $.=0 call dos 'ERASE' oFID cha...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include <ctype.h> #include <glib.h> #define ROWS 4 #define COLS 10 #define NPRX "/" const char *table[ROWS][COLS] = { { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }, { "H", "O", "L", NULL, "M", "E", "S", NULL, "R", ...
parse arg msg if msg='' then msg= 'One night-it was the twentieth of March, 1888-I was returning' say 'plain text=' msg call genCipher 'et aon ris', 'bcdfghjklm', 'pq/uvwxyz.' enc= encrypt(msg); say ' encrypted=' enc dec= decrypt(enc); say...
Write the same code in REXX as shown below in C.
%{ int cie, cei, ie, ei; %} %% cie ++cie, ++ie; cei ++cei, ++ei; ie ++ie; ei ++ei; .|\n ; %% int main() { cie = cei = ie = ei = 0; yylex(); printf("%s: %s\n","I before E when not preceded by C", (2*ei < ie ? "plausible" : "implausible")); printf("%s: %s\n","E before I when preceded by C", (2*cie <...
parse arg iFID . if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' #.=0 do r=0 while lines(iFID)\==0 u=space( lineIn(iFID), 0); upper u if u=='' then iterate #.words=#.wor...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
%{ int cie, cei, ie, ei; %} %% cie ++cie, ++ie; cei ++cei, ++ei; ie ++ie; ei ++ei; .|\n ; %% int main() { cie = cei = ie = ei = 0; yylex(); printf("%s: %s\n","I before E when not preceded by C", (2*ei < ie ? "plausible" : "implausible")); printf("%s: %s\n","E before I when preceded by C", (2*cie <...
parse arg iFID . if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT' #.=0 do r=0 while lines(iFID)\==0 u=space( lineIn(iFID), 0); upper u if u=='' then iterate #.words=#.wor...
Ensure the translated REXX code behaves exactly like the original C snippet.
void draw_line_antialias( image img, unsigned int x0, unsigned int y0, unsigned int x1, unsigned int y1, color_component r, color_component g, color_component b );
background= 'Β·' image.= background plotC= 'β–‘β–’β–“β–ˆ' EoE= 3000 do j=-EoE to +EoE image.j.0= '─' ...
Translate the given C code snippet into REXX without altering its behavior.
#include <stdbool.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> void swap(char* str, int i, int j) { char c = str[i]; str[i] = str[j]; str[j] = c; } void reverse(char* str, int i, int j) { for (; i < j; ++i, --j) swap(str, i, j); } bool next_permutation(cha...
parse arg n if n='' | n="," then n= 0 9 12 21 12453 738440 45072010 95322020 w= length( commas( word(n, words(n) ) ) ) do j=1 for words(n); y= word(n, j) masky= mask(y) lim= copies(9, length(y) ) ...
Generate an equivalent REXX version of this C code.
#include <stdbool.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> void swap(char* str, int i, int j) { char c = str[i]; str[i] = str[j]; str[j] = c; } void reverse(char* str, int i, int j) { for (; i < j; ++i, --j) swap(str, i, j); } bool next_permutation(cha...
parse arg n if n='' | n="," then n= 0 9 12 21 12453 738440 45072010 95322020 w= length( commas( word(n, words(n) ) ) ) do j=1 for words(n); y= word(n, j) masky= mask(y) lim= copies(9, length(y) ) ...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include <stdio.h> #include <stdlib.h> #include <X11/Xlib.h> #include <X11/Xutil.h> int main(int argc, char *argv[]) { Display *dpy; Window win; GC gc; int scr; Atom WM_DELETE_WINDOW; XEvent ev; XEvent ev2; KeySym keysym; int loop; dpy = XOpenDisplay(NULL); if (dpy == NULL) { fputs("Canno...
call press 'This text will be put into a buffer as if it came from the keyboard'
Can you help me rewrite this code in REXX instead of C, keeping it the same logically?
#include <stdint.h> #include <stdio.h> #include <glib.h> typedef struct named_number_tag { const char* name; uint64_t number; } named_number; const named_number named_numbers[] = { { "hundred", 100 }, { "thousand", 1000 }, { "million", 1000000 }, { "billion", 1000000000 }, { "trillion", 10...
numeric digits 3003 parse arg x if x='' then x= -164 0 4 6 11 13 75 100 337 9223372036854775807 @.= . do j=1 for words(x) say 4_is( word(x, j) ) ...
Maintain the same structure and functionality when rewriting this code in REXX.
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> static int nextInt(int size) { return rand() % size; } static bool cylinder[6]; static void rshift() { bool t = cylinder[5]; int i; for (i = 4; i >= 0; i--) { cylinder[i + 1] = cylinder[i]; }...
parse arg cyls tests seed . if cyls=='' | cyls=="," then cyls= 6 if tests=='' | tests=="," then tests= 100000 if datatype(seed, 'W') then call random ,,seed cyls_ = cyls - 1; @0= copies(0, cyls) @abc= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' scenarios= 'LSLSFsF...
Maintain the same structure and functionality when rewriting this code in REXX.
#include<stdlib.h> #include<stdio.h> char** imageMatrix; char blankPixel,imagePixel; typedef struct{ int row,col; }pixel; int getBlackNeighbours(int row,int col){ int i,j,sum = 0; for(i=-1;i<=1;i++){ for(j=-1;j<=1;j++){ if(i!=0 || j!=0) sum+= (imageMatrix[row+i][col+j]==imagePixel); } } return...
parse arg iFID .; if iFID=='' then iFID='ZHANG_SUEN.DAT' white=' '; @.=white do row=1 while lines(iFID)\==0; _=linein(iFID) _=translate(_,,.0); cols.row=length(_) do col=1 for cols.row; @.row.col=substr(_,col,1) end ...
Please provide an equivalent version of this C code in REXX.
#include<stdlib.h> #include<locale.h> #include<wchar.h> #include<stdio.h> #include<time.h> char rank[9]; int pos[8]; void swap(int i,int j){ int temp = pos[i]; pos[i] = pos[j]; pos[j] = temp; } void generateFirstRank(){ int kPos,qPos,bPos1,bPos2,rPos1,rPos2,nPos1,nPos2,i; for(i=0;i<8;i++){ rank[i] = 'e...
parse arg seed . if seed\=='' then call random ,,seed @.=. r1=random(1,6) @.r1='R' do until r2\==r1 & r2\==r1-1 & r2\==r1+1 r2=random(1,8) end @.r2=...
Port the provided C code into REXX while preserving the original functionality.
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> typedef char const *const string; bool consume_sentinal(bool middle, string s, size_t *pos) { if (middle) { if (s[*pos] == ' ' && s[*pos + 1] == '#' && s[*pos + 2] == ' ' && s[*pos + 3] == '#' && s[*pos + 4] == ' ') { ...
#.0= ' ## #' #.1= ' ## #' #.2= ' # ##' #.3= ' #### #' #.4= ' # ##' #.5= ' ## #' #.6= ' # ####' #.7= ' ### ##' #.8= ' ## ###' #.9= ' # ##' ; do i=0 for 10; ...
Port the following code from C to REXX with equivalent syntax and logic.
#include<stdlib.h> #include<stdio.h> int main(int argC,char* argV[]) { char str[1000]; if(argC!=5) printf("UsageΒ : %s < Followed by level, id, source string and description>",argV[0]); else{ sprintf(str,"EventCreate /t %s /id %s /l APPLICATION /so %s /d \"%s\"",argV[1],argV[2],argV[3],argV[4]); system(str);...
eCMD = 'EVENTCREATE' type = 'INFORMATION' id = 234 logName = 'APPLICATION' source = 'REXX' desc = 'attempting to add an entry for a Rosetta Code demonstrat...
Preserve the algorithm and functionality while converting the code from C to REXX.
#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" }, { "two", "second" }, { "three",...
numeric digits 3000 parse arg n if n='' | n="," then n= 1 2 3 4 5 11 65 100 101 272 23456 8007006005004003 pgmOpts= 'ordinal quiet' do j=1 for words(n) x=word(n, j) ...
Keep all operations the same but rewrite the snippet in REXX.
#include <string.h> #include <memory.h> static unsigned int _parseDecimal ( const char** pchCursor ) { unsigned int nVal = 0; char chNow; while ( chNow = **pchCursor, chNow >= '0' && chNow <= '9' ) { nVal *= 10; nVal += chNow - '0'; ++*pchCursor; } return nVal...
_= "_"; say center('input IP address' , 30), center('hex IP address' , 32), center('decimal IP address' , 39) "space port" say copies(_, 30) copies(_, 32) copies(_, 39) copies(_, 5) copies(_, 5) call IP_parse 127.0.0.1 call IP...
Port the provided C code into REXX while preserving the original functionality.
#include <math.h> #include <stdbool.h> #include <stdio.h> const double eps = 1e-14; typedef struct point_t { double x, y; } point; point make_point(double x, double y) { point p = { x, y }; return p; } void print_point(point p) { double x = p.x; double y = p.y; if (x == 0) { x = 0; ...
parse arg x1 y1 x2 y2 cx cy r . if x1=='' | x1=="," then x1= 0 if y1=='' | y1=="," then y1= -3 if x2=='' | x2=="," then x2= 0 if y2=='' | y2=="," then y2= 6 if cx=='' | cx=="," then cx= 0 if cy=='' | cy==",...
Produce a language-to-language conversion: from C to REXX, same semantics.
#include <ctype.h> #include <stdbool.h> #include <stdio.h> #include <string.h> typedef enum { whole_word = 1, overkill = 2, case_insensitive = 4 } redact_options; bool is_word_char(char ch) { return ch == '-' || isalpha((unsigned char)ch); } void redact(char* text, const char* target, redact_options...
zDefault= 'Tom? Toms bottom tomato is in his stomach while playing the "Tom-tom"' , "brand tom-toms. That's so tom." parse arg x '~' z if x=='' | x=="," then x= 'Tom tom t' if z= '' | z= "," then z= zDefault options= 'wβ”‚sβ”‚n wβ”‚iβ”‚n pβ”‚sβ”‚n ...
Write the same code in REXX as shown below in C.
#include <stdio.h> #include <string.h> int findNumOfDec(const char *s) { int pos = 0; while (s[pos] && s[pos++] != '.') {} return strlen(s + pos); } void test(const char *s) { int num = findNumOfDec(s); const char *p = num != 1 ? "s" : ""; printf("%s has %d decimal%s\n", s, num, p); } int ma...
numeric digits 1000 @.=; parse arg @.1; if @.1='' then do; #= 9 @.1 = 12 @.2 = 12.345 @.3 = 12.345555555555 ...
Produce a functionally identical REXX code for the snippet given in C.
#include<stdio.h> #include<stdlib.h> #define min(a, b) (a<=b?a:b) void minab( unsigned int n ) { int i, j; for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf( "%2d ", min( min(i, n-1-i), min(j, n-1-j) )); } printf( "\n" ); } return; } int main(void) { minab(10); ...
parse arg $ if $='' | $="," then $= 21 10 9 2 1 @title= ' the minimum number of cells after, before, above, and below a ' do j=1 for words($); g= word($, j) w= length( (g-1) % 2) say center(@title g"x"g ' squa...
Maintain the same structure and functionality when rewriting this code in REXX.
#include <stdio.h> #include <math.h> typedef struct { double x; double y; } pair; int main() { double list[17] = {1, 8, 2, -3, 0, 1, 1, -2.3, 0, 5.5, 8,6, 2, 9, 11, 10, 3}; double diff, maxDiff = -1; pair maxPairs[5]; int i, count = 0; for (i = 1; i < 17; ++i) { diff = fabs(list[i-...
parse arg $ if $='' | S=="," then $= , '1,8,2,-3,0,1,1,-2.3,0,5.5,8,6,2,9,11,10,3' w= 0 $= translate($, , ',') #= words($) do i=1...
Produce a functionally identical REXX code for the snippet given in C.
#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 ...