Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Produce a language-to-language conversion: from C to Icon, same semantics.
#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}, ...
procedure main() infix := "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3" printf("Infix = %i\n",infix) printf("RPN = %i\n",Infix2RPN(infix)) end link printf record op_info(pr,as) procedure Infix2RPN(expr) static oi initial { oi := table() every oi[!"+-"] ...
Ensure the translated Icon code behaves exactly like the original C snippet.
#include<stdio.h> #define Hi printf("Hi There."); #define start int main(){ #define end return 0;} start Hi #warning "Don't you have anything better to doΒ ?" #ifdef __unix__ #warning "What are you doing still working on UnixΒ ?" printf("\nThis is an Unix system."); #elif _WIN32 #warning "You couldn't afford ...
&trace &error
Preserve the algorithm and functionality while converting the code from C to Icon.
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <unistd.h> #define VECSZ 100 #define STATESZ 64 typedef float floating_pt; #define EXP expf #define SQRT sqrtf static floating_pt randnum (void) { return (floating_pt) ((double) (random () & 2147483647) / ...
link printf link random procedure main () local initial_path local final_path local kT, kmax randomize() kT := 1.0 kmax := 1000000 write() write(" kT: ", kT) write(" kmax: ", kmax) write() write(" k T E(s)") write(" --------------------------") initial_path := rando...
Port the provided C code into REXX while preserving the original functionality.
#include <math.h> #include <stdint.h> #include <stdio.h> const uint64_t N = 6364136223846793005; static uint64_t state = 0x853c49e6748fea9b; static uint64_t inc = 0xda3e39cb94b95bdb; uint32_t pcg32_int() { uint64_t old = state; state = old * N + inc; uint32_t shifted = (uint32_t)(((old >> 18) ^ old) >> 2...
Numeric Digits 40 N = 6364136223846793005 state = x2d('853c49e6748fea9b',16) inc = x2d('da3e39cb94b95bdb',16) Call seed 42,54 Do zz=1 To 5 res=nextint() Say int2str(res) End Call seed 987654321,1 cnt.=0 Do i=1 To 100000 z=nextfloat() cnt.z=cnt.z+1 End Say '' Say 'The counts for 100,000 repetitions are...
Maintain the same structure and functionality when rewriting this code in REXX.
struct RS232_data { unsigned carrier_detect : 1; unsigned received_data : 1; unsigned transmitted_data : 1; unsigned data_terminal_ready : 1; unsigned signal_ground : 1; unsigned data_set_ready : 1; unsigned request_to_send : 1; unsigned clear_to_send :...
* Decode Memory structure of RS-232 Plug Definition * Not sure if I understood it completelyΒ :-) Open for corrections * You never stop learning (as long as you live) * 03.08.2012 Walter Pachl **********************************************************************/ Call decode 'ABC' Call decode 'XY' Exit decode: Par...
Port the following code from C to REXX with equivalent syntax and logic.
#include <stdio.h> unsigned int lpd(unsigned int n) { if (n<=1) return 1; int i; for (i=n-1; i>0; i--) if (n%i == 0) return i; } int main() { int i; for (i=1; i<=100; i++) { printf("%3d", lpd(i)); if (i % 10 == 0) printf("\n"); } return 0; }
parse arg n cols . if n=='' | n=="," then n= 101 if cols=='' | cols=="," then cols= 10 w= length(n) + 1 @LPD = "largest proper divisor of N, where N < " n idx = 1 say ' in...
Produce a language-to-language conversion: from C to REXX, same semantics.
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct rec_t rec_t; struct rec_t { int depth; rec_t * p[10]; }; rec_t root = {0, {0}}; #define USE_POOL_ALLOC #ifdef USE_POOL_ALLOC rec_t *tail = 0, *head = 0; #define POOL_SIZE (1 << 20) inline rec_t *new_rec() { if (head == tail) { head = cal...
parse arg LO HI . if LO=='' | LO=="," then LO= 1 if HI=='' | HI=="," then HI=1000000 - 1 max$=; seeds=; maxL=0 do #=LO to HI; n=#; @.=0; @.#=1 $=n do c=1 until x==n; x=n n=; ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <math.h> #include <stdint.h> #include <stdio.h> static uint64_t state; static const uint64_t STATE_MAGIC = 0x2545F4914F6CDD1D; void seed(uint64_t num) { state = num; } uint32_t next_int() { uint64_t x; uint32_t answer; x = state; x = x ^ (x >> 12); x = x ^ (x << 25); x = x ^ (x ...
numeric digits 200 parse arg n reps pick seed1 seed2 . if n=='' | n=="," then n= 5 if reps=='' | reps=="," then reps= 100000 if pick=='' | pick=="," then pick= 5 if seed1=='' | seed1=="," then seed1= 1234567 if seed2=='' | seed...
Translate this program into REXX but keep the logic exactly as in C.
#include <stdio.h> int riseEqFall(int num) { int rdigit = num % 10; int netHeight = 0; while (num /= 10) { netHeight += ((num % 10) > rdigit) - ((num % 10) < rdigit); rdigit = num % 10; } return netHeight == 0; } int nextNum() { static int num = 0; do {num++;} while (!ris...
parse arg n . if n=='' | n=="," then n= 200 append= n>0 n= abs(n) call init do j=1 until #==n s= 0 ...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include <stdio.h> inline int self_desc(unsigned long long xx) { register unsigned int d, x; unsigned char cnt[10] = {0}, dig[10] = {0}; for (d = 0; xx > ~0U; xx /= 10) cnt[ dig[d++] = xx % 10 ]++; for (x = xx; x; x /= 10) cnt[ dig[d++] = x % 10 ]++; while(d-- && dig[x++] == cnt[d]); return d == -1; ...
-- REXX program to check if a number (base 10) is self-describing. parse arg x y . if x=='' then exit if y=='' then y=x -- 10 digits is the maximum size number that works here, so cap it numeric digits 10 y=min(y, 9999999999) loop number = x to y loop i = 1 to number~length digit = number~subchar(i) -- r...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_WORD_SIZE 32 typedef struct string_tag { size_t length; char str[MAX_WORD_SIZE]; } string_t; void fatal(const char* message) { fprintf(stderr, "%s\n", message); exit(1); } void* xmalloc(size_t n) { void* ptr = malloc(n); ...
parse arg minL iFID . if minL=='' | minL=="," then minL= 12 if iFID=='' | iFID=="," then iFID='unixdict.txt' call readDict abc= 'abcdefghijklmnopqrstuvwxyz'; upper abc Labc= length(abc) finds= 0 ...
Convert this C block to REXX, preserving its control flow and logic.
#include <stdio.h> #define N_COND 3 #define COND_LEN (1 << N_COND) struct { const char *str, *truth;} cond[N_COND] = { {"Printer does not print", "1111...."}, {"A red light is flashing", "11..11.."}, {"Printer is unrecognised", "1.1.1.1."}, }, solu[] = { {"Check the power cable", "..1....."}, {"Check the pr...
Q.=; Q.1 = 'Does the printer not print?' Q.2 = 'Is there a red light flashing on the printer?' Q.3 = 'Is the printer unrecognized by the software?' Q.0 = 3 action.= ...
Write the same algorithm in REXX as shown in this C implementation.
#include <stdio.h> #define SIZE 256 int check(char *word) { int e = 0, ok = 1; for(; *word && ok; word++) { switch(*word) { case 'a': case 'i': case 'o': case 'u': ok = 0; break; case 'e': e++; } } return ok && e > 3; } ...
parse arg char many iFID . if char=='' | char=="," then char= 'e' if many=='' | many=="," then many= 4 if iFID=='' | iFID=="," then iFID='unixdict.txt' chrU= char; upper chrU do #=1 while lines(iFID)\==0 x= strip...
Produce a language-to-language conversion: from C to REXX, same semantics.
#include <stdio.h> int min(int a, int b) { if (a < b) return a; return b; } int main() { int n; int numbers1[5] = {5, 45, 23, 21, 67}; int numbers2[5] = {43, 22, 78, 46, 38}; int numbers3[5] = {9, 98, 12, 98, 53}; int numbers[5] = {}; for (n = 0; n < 5; ++n) { numbers[n] = min...
l.1=.array~of( 5, 45, 23, 21, 67) l.2=.array~of(43, 22, 78, 46, 38) l.3=.array~of( 9, 98, 12, 98, 53) o='' Do i=1 To 5 o=o min(l.1[i],l.2[i],l.3[i]) End Say strip(o)
Generate an equivalent REXX version of this C code.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> struct substr { const char *start; size_t length; }; struct substr *lswrc(const char *str) { size_t length = strlen(str); struct substr *arr = malloc(sizeof(struct substr) * (length + 1)); if (!arr) return NULL; ...
parse arg $ if $=='' | $=="," then $= 'xyzyabcybdfd' L= length($) maxL= 0 @.= do j=1 for L; b= substr($, j, 1) x= ...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_WORD_SIZE 80 bool is_vowel(char ch) { switch (ch) { case 'a': case 'A': case 'e': case 'E': case 'i': case 'I': case 'o': case 'O': case 'u': case 'U': return true; } return false; } bo...
parse arg minL iFID . if minL=='' | minL=="," then minL= 10 if iFID=='' | iFID=="," then iFID='unixdict.txt' do #=1 while lines(iFID)\==0 x= strip( linein( iFID) ) $.#= x en...
Translate the given C code snippet into REXX without altering its behavior.
#include<stdlib.h> #include<stdio.h> #define LEN 100 int main() { char **list; int num, i; scanf("%d",&num); list = (char**)malloc(num*sizeof(char*)); for(i=0;i<num;i++) { list[i] = (char*)malloc(LEN*sizeof(char)); fflush(stdin); fgets(list[i],LEN,stdin); } printf("\n"); for(i=0;i<...
#=linein() do j=1 for #; x.j=linein(); end call stuff exit stuff: do k=1 for #; call lineout ,x.k; end; return
Keep all operations the same but rewrite the snippet in REXX.
#define PI 3.14159265358979323846 #define ABS(x) (x<0?-x:x) double arc_length(double radius, double angle1, double angle2) { return (360 - ABS(angle2 - angle1)) * PI / 180 * radius; } void main() { printf("%.7f\n",arc_length(10, 10, 120)); }
parse arg radius angle1 angle2 . if radius=='' | radius=="," then radius= 10 if angle1=='' | angle1=="," then angle1= 10 if angle2=='' | angle2=="," then angle2= 120 say ' circle radius = ' radius say ' angle 1 = ' angle1"ΒΊ" say ' angle 2 = ' a...
Preserve the algorithm and functionality while converting the code from C to REXX.
#include <stdio.h> #include <stdlib.h> int compare(const void *a, const void *b) { int aa = *(const int *)a; int bb = *(const int *)b; if (aa < bb) return -1; if (aa > bb) return 1; return 0; } int main() { int a[] = {6, 81, 243, 14, 25, 49, 123, 69, 11}; int isize = sizeof(int); int a...
List = '6 81 243 14 25 49 123 69 11' Do Until words(list)=1 list=wordsort(list) Say 'Sorted list:' list Parse Var list a b c Say 'Two smallest:' a '+' b '=' (a+b) list=(a+b) c End Say 'Last item:' list Exit wordsort: Procedure * Sort the list of words supplied as argument. Return the sorted list *********...
Preserve the algorithm and functionality while converting the code from C to REXX.
#include <stdio.h> void lshift(int *l, size_t n) { int i, f; if (n < 2) return; f = l[0]; for (i = 0; i < n-1; ++i) l[i] = l[i+1]; l[n-1] = f; } int main() { int l[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; int i; size_t n = 9; printf("Original list Β : "); for (i = 0; i < n; ++i) pri...
parse arg n $ . if n=='' | n=="," then n= 3 if $=='' | $=="," then $= '[1,2,3,4,5,6,7,8,9]' $$= space( translate($, , '],[') ) $$= '['translate( subword($$, N+1) subword($$, 1, n), ',', " ")']' say 'shifting elements in the list by ' n ...
Write the same code in REXX as shown below in C.
#include <stdio.h> #define LIMIT 100000 int digitset(int num, int base) { int set; for (set = 0; num; num /= base) set |= 1 << num % base; return set; } int main() { int i, c = 0; for (i = 0; i < LIMIT; i++) if (digitset(i,10) == digitset(i,16)) printf("%6d%c", i, ++c%1...
parse arg n cols . if n=='' | n=="," then n = 100000 if cols=='' | cols=="," then cols= 10 w= 10 @hHex= ' decimal integers when displayed in decimal and' , "hexad...
Port the following code from C to REXX with equivalent syntax and logic.
#include <math.h> #include <stdio.h> #define DEG 0.017453292519943295769236907684886127134 #define RE 6371000.0 #define DD 0.001 #define FIN 10000000.0 static double rho(double a) { return exp(-a / 8500.0); } static double height(double a, double z, double d) { double aa = RE + a; ...
numeric digits (length(pi()) - length(.)) % 4 parse arg aLO aHI aBY oHT . if aLO=='' | aLO=="," then aLO= 0 if aHI=='' | aHI=="," then aHI= 90 if aBY=='' | aBY=="," then aBY= 5 if oHT=='' | oHT=="," then oHT= 13700 w= 30; ...
Generate an equivalent REXX version of this C code.
#include <stdio.h> #include <string.h> int main() { char word[128]; FILE *f = fopen("unixdict.txt","r"); if (!f) { fprintf(stderr, "Cannot open unixdict.txt\n"); return -1; } while (!feof(f)) { fgets(word, sizeof(word), f); if (strlen(word) > 12 && ...
parse arg $ minL iFID . if $=='' | $=="," then $= 'the' if minL=='' | minL=="," then minL= 12 if iFID=='' | iFID=="," then iFID='unixdict.txt' tell= minL>0; minL= abs(minL) @.= do #=1 ...
Translate this program into REXX but keep the logic exactly as in C.
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct node_t { char *elem; int length; struct node_t *next; } node; node *make_node(char *s) { node *t = malloc(sizeof(node)); t->elem = s; t->length = strlen(s); t->next = NULL; return t; } void append_node(node *hea...
parse arg z; z= space(z) if z==''|z=="," then z='baabababc baabc bbbabc' z= space(z); #= words(z) say 'There are ' # " words in the list: " z zr= reverse(z) @= word(zr, 1); m= length(@) do j=2 to #; ...
Produce a functionally identical REXX code for the snippet given in C.
#include <locale.h> #include <stdio.h> int main() { unsigned long long int trillion = 1000000000000; setlocale(LC_NUMERIC,""); printf("LocaleΒ : %s, One TrillionΒ :Β %'llu\n", setlocale(LC_CTYPE,NULL),trillion); return 0; }
pi= 3 . 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74945 pi= 3 . 14159_26535_89793_23846_26433_83279_50288_41971_69399_37510_58209_74945 pi = space( translate(pi, , ",_"), 0)
Please provide an equivalent version of this C code in REXX.
#include <stdio.h> #include <stdlib.h> #include <math.h> int compare(const void *a, const void *b) { int ia = *(int*)a; int ib = *(int*)b; return (ia>ib) - (ia<ib); } int main() { int pows[16]; int a, b, i=0; for (a=2; a<=5; a++) for (b=2; b<=5; b++) pows[i++] = pow(a,...
parse arg lo hi cols . if lo=='' | lo=="," then lo= 2 if hi=='' | hi=="," then hi= 5 if cols=='' | cols=="," then cols= 10 w= 11 title= ' distinct power integers, a^b, where a and b are: ' lo...
Maintain the same structure and functionality when rewriting this code in REXX.
#include <stdio.h> #include <string.h> char *uniques(char *str[], char *buf) { static unsigned counts[256]; unsigned i; char *s, *o = buf; memset(counts, 0, 256 * sizeof(unsigned)); for (; *str; str++) for (s = *str; *s; s++) counts[(unsigned) *s]++; for (i=0; i<25...
parse arg $ if $='' | $="," then $= '133252abcdeeffd' "a6789798st" 'yxcdfgxcyz' if $='' then do; say "***error*** no lists were specified."; exit 13; end @= do j=0 for 256; x= d2c(j) ...
Translate the given C code snippet into REXX without altering its behavior.
#define _XOPEN_SOURCE #include <stdio.h> #include <time.h> int main() { struct tm t[2]; strptime("2021-12-25", "%F", &t[0]); strptime("2022-01-01", "%F", &t[1]); for (int i=0; i<2; i++) { char buf[32]; strftime(buf, 32, "%F is a %A", &t[i]); puts(buf); } return 0; }
Call wkd 2021,12,25 Call wkd 2022,01,01 Exit wkd: Parse Arg y,m,d wd=.Array~of('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday') dt=.DateTime~new(y,m,d) say d'.'m'.'y 'is a' wd[dt~weekday] Return
Convert the following code from C to REXX, ensuring the logic remains intact.
while(1) puts("SPAM");
options replace format comments java crossref savelog symbols nobinary say say 'Loops/Infinite' loop label spam forever say 'SPAM' end spam
Translate this program into REXX but keep the logic exactly as in C.
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <locale.h> bool isPrime(int n) { if (n < 2) return false; if (n%2 == 0) return n == 2; if (n%3 == 0) return n == 3; int d = 5; while (d*d <= n) { if (n%d == 0) return false; d += 2; if (n%d == 0) return fal...
parse arg hip cols . if hip=='' | hip=="," then hip= 100 if cols=='' | cols=="," then cols= 10 call genP title= ' concatenation of two neighbor primes (P1, P2) in base ten that results in' , ...
Produce a functionally identical REXX code for the snippet given in C.
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <locale.h> bool isPrime(int n) { if (n < 2) return false; if (n%2 == 0) return n == 2; if (n%3 == 0) return n == 3; int d = 5; while (d*d <= n) { if (n%d == 0) return false; d += 2; if (n%d == 0) return fal...
parse arg hip cols . if hip=='' | hip=="," then hip= 100 if cols=='' | cols=="," then cols= 10 call genP title= ' concatenation of two neighbor primes (P1, P2) in base ten that results in' , ...
Maintain the same structure and functionality when rewriting this code in REXX.
#include <stdlib.h>
stemmed_array.= 0 stemmed_array.1 = '1st entry' stemmed_array.2 = '2nd entry' stemmed_array.6000 = 12 ** 2 stemmed_array.dog = stemmed_array.6000 / 2 drop stemmed_array.
Convert the following code from C to REXX, ensuring the logic remains intact.
#include <stdlib.h>
stemmed_array.= 0 stemmed_array.1 = '1st entry' stemmed_array.2 = '2nd entry' stemmed_array.6000 = 12 ** 2 stemmed_array.dog = stemmed_array.6000 / 2 drop stemmed_array.
Ensure the translated REXX code behaves exactly like the original C snippet.
double multiply(double a, double b) { return a * b; }
options replace format comments java crossref savelog symbols binary pi = 3.14159265358979323846264338327950 radiusY = 10 in2ft = 12 ft2yds = 3 in2mm = 25.4 mm2m = 1 / 1000 radiusM = multiply(multiply(radiusY, multiply(multiply(ft2yds, in2ft), in2mm)), mm2m) say "Area of a circle" radiusY "yds radius: "...
Produce a functionally identical REXX code for the snippet given in C.
#include <stdbool.h> #include <stdint.h> #include <stdio.h> #define PRIME_COUNT 100000 int64_t PRIMES[PRIME_COUNT]; size_t primeSize = 0; bool isPrime(int n) { size_t i = 0; for (i = 0; i < primeSize; i++) { int64_t p = PRIMES[i]; if (n == p) { return true; } if (n...
parse arg H . 1 . difs if H=='' | H=="," then H= 1000000 if difs='' then difs= 2 1 2.2 2.4 4.2 6.4.2 call genP H do j=1 for words(difs) dif= translate( word(difs, j),,.); dw= words(dif) do i=1 for dw; dif.i...
Port the provided C code into REXX while preserving the original functionality.
#include <stdio.h> #include <stdint.h> uint8_t prime(uint8_t n) { uint8_t f; if (n < 2) return 0; for (f = 2; f < n; f++) { if (n % f == 0) return 0; } return 1; } uint8_t digit_sum(uint8_t n, uint8_t base) { uint8_t s = 0; do {s += n % base;} while (n /= base); return s; } ...
parse arg n cols . if n=='' | n=="," then n= 200 if cols=='' | cols=="," then cols= 10 call genP w= 10 title= ' positive integers whose binary and ternary digit sums are pr...
Change the programming language of this snippet from C to REXX without modifying what it does.
#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 prime( int n ) { int p, pn=1; if(n==1) return 2; for(p=3;pn<n;p+=2) { if(isprime(p)) pn++; }...
Parse Version v Say v Call Time 'R' z=1 p.0=3 p.1=2 p.2=3 p.3=5 Do n=5 By 2 Until z=10001 If right(n,1)=5 Then Iterate Do i=2 To p.0 Until b**2>n b=p.i If n//b=0 Then Leave End If b**2>n Then Do z=p.0+1 p.z=n p.0=z End End Say z n time('E')
Port the provided C code into REXX while preserving the original functionality.
#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 prime( int n ) { int p, pn=1; if(n==1) return 2; for(p=3;pn<n;p+=2) { if(isprime(p)) pn++; }...
Parse Version v Say v Call Time 'R' z=1 p.0=3 p.1=2 p.2=3 p.3=5 Do n=5 By 2 Until z=10001 If right(n,1)=5 Then Iterate Do i=2 To p.0 Until b**2>n b=p.i If n//b=0 Then Leave End If b**2>n Then Do z=p.0+1 p.z=n p.0=z End End Say z n time('E')
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 . if hi=='' | hi=="," then hi= 1000 call genP w= 30; w2= w*2%3; pad= left('',w-w2) title= ' summation primes which the sum of primes up to P is also prime, P < ' , ...
Preserve the algorithm and functionality while converting the code from C to REXX.
#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 . if hi=='' | hi=="," then hi= 1000 call genP w= 30; w2= w*2%3; pad= left('',w-w2) title= ' summation primes which the sum of primes up to P is also prime, P < ' , ...
Produce a language-to-language conversion: from C to REXX, same semantics.
#include <sys/ioctl.h> #include <err.h> #include <fcntl.h> #include <stdio.h> #include <unistd.h> int main() { struct winsize ws; int fd; fd = open("/dev/tty", O_RDWR); if (fd < 0) err(1, "/dev/tty"); if (ioctl(fd, TIOCGWINSZ, &ws) < 0) err(1, "/dev/tty"); printf("%d rows by %d columns\n", ws.ws...
width = 'tput'( 'cols' ) height = 'tput'( 'lines' ) say 'The terminal is' width 'characters wide' say 'and has' height 'lines'
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> #include <stdbool.h> bool isPrime(int n) { int 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 false; d += 2; if (!(n%d)) return false; d += 4; } return tru...
parse arg hi cols . if hi=='' | hi=="," then hi= 1050 if cols=='' | cols=="," then cols= 10 call genP w= 10 @nsp= ' next special primes < ' commas(...
Change the following C code into REXX without altering its purpose.
#include <stdio.h> #include <stdbool.h> bool isPrime(int n) { int 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 false; d += 2; if (!(n%d)) return false; d += 4; } return tru...
parse arg hi cols . if hi=='' | hi=="," then hi= 1050 if cols=='' | cols=="," then cols= 10 call genP w= 10 @nsp= ' next special primes < ' commas(...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include<stdio.h> int main() { int num = 9876432,diff[] = {4,2,2,2},i,j,k=0; char str[10]; start:snprintf(str,10,"%d",num); for(i=0;str[i+1]!=00;i++){ if(str[i]=='0'||str[i]=='5'||num%(str[i]-'0')!=0){ num -= diff[k]; k = (k+1)%4; goto start; } for(j=i+1;str[j]!=00;j++) if(str[i]==str...
$= 7 * 8 * 9 t= 0 do #=9876432 % $ * $ by -$ if # // $ \==0 then iterate if verify(50, #, 'M') \==0 then iterate t= t+1 do j=1 ...
Keep all operations the same but rewrite the snippet in REXX.
#include<stdio.h> int main() { int num = 9876432,diff[] = {4,2,2,2},i,j,k=0; char str[10]; start:snprintf(str,10,"%d",num); for(i=0;str[i+1]!=00;i++){ if(str[i]=='0'||str[i]=='5'||num%(str[i]-'0')!=0){ num -= diff[k]; k = (k+1)%4; goto start; } for(j=i+1;str[j]!=00;j++) if(str[i]==str...
$= 7 * 8 * 9 t= 0 do #=9876432 % $ * $ by -$ if # // $ \==0 then iterate if verify(50, #, 'M') \==0 then iterate t= t+1 do j=1 ...
Port the provided C code into REXX while preserving the original functionality.
#include <stdlib.h> #include <stdio.h> #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) int jacobi(unsigned long a, unsigned long n) { if (a >= n) a %= n; int result = 1; while (a) { while ((a & 1) == 0) { a >>= 1; if ((n & 7) == 3 || (n & 7) == 5) result = -result; } SWAP(a, n); if ((a ...
parse arg rows cols . if rows='' | rows=="," then rows= 17 if cols='' | cols=="," then cols= 16 call hdrs do r=1 by 2 to rows; _= right(r, 3) do c=0 to cols ...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include <stdlib.h> #include <stdio.h> #define SWAP(a, b) (((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) int jacobi(unsigned long a, unsigned long n) { if (a >= n) a %= n; int result = 1; while (a) { while ((a & 1) == 0) { a >>= 1; if ((n & 7) == 3 || (n & 7) == 5) result = -result; } SWAP(a, n); if ((a ...
parse arg rows cols . if rows='' | rows=="," then rows= 17 if cols='' | cols=="," then cols= 16 call hdrs do r=1 by 2 to rows; _= right(r, 3) do c=0 to cols ...
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> double det_in(double **in, int n, int perm) { if (n == 1) return in[0][0]; double sum = 0, *m[--n]; for (int i = 0; i < n; i++) m[i] = in[i + 1] + 1; for (int i = 0, sgn = 1; i <= n; i++) { sum += sgn * (in[i][0] * det_in(m, n, perm)); if (i == n) ...
* Test the two functions determinant and permanent * using the matrix specifications shown for other languages * 21.05.2013 Walter Pachl **********************************************************************/ Call test ' 1 2', ' 3 4',2 Call test ' 1 2 3 4', ' 4 5 6 7', ' 7 8 9 ...
Produce a functionally identical REXX code for the snippet given in C.
#include <stdio.h> #include <stdlib.h> #include <string.h> double det_in(double **in, int n, int perm) { if (n == 1) return in[0][0]; double sum = 0, *m[--n]; for (int i = 0; i < n; i++) m[i] = in[i + 1] + 1; for (int i = 0, sgn = 1; i <= n; i++) { sum += sgn * (in[i][0] * det_in(m, n, perm)); if (i == n) ...
* Test the two functions determinant and permanent * using the matrix specifications shown for other languages * 21.05.2013 Walter Pachl **********************************************************************/ Call test ' 1 2', ' 3 4',2 Call test ' 1 2 3 4', ' 4 5 6 7', ' 7 8 9 ...
Write the same algorithm in REXX as shown in this C implementation.
#include <stdio.h> #include <string.h> int digitSum(int n) { int s = 0; do {s += n % 10;} while (n /= 10); return s; } int digitSumIsSubstring(int n) { char s_n[32], s_ds[32]; sprintf(s_n, "%d", n); sprintf(s_ds, "%d", digitSum(n)); return strstr(s_n, s_ds) != NULL; } int main() { int...
parse arg hi cols . if hi=='' | hi=="," then hi= 1000 if cols=='' | cols=="," then cols= 10 w= 10 @sdsN= ' integers whose sum of decimal digis of N is a substring of N, where N < ' , ...
Write the same algorithm in REXX as shown in this C implementation.
#include <stdio.h> #include <string.h> int digitSum(int n) { int s = 0; do {s += n % 10;} while (n /= 10); return s; } int digitSumIsSubstring(int n) { char s_n[32], s_ds[32]; sprintf(s_n, "%d", n); sprintf(s_ds, "%d", digitSum(n)); return strstr(s_n, s_ds) != NULL; } int main() { int...
parse arg hi cols . if hi=='' | hi=="," then hi= 1000 if cols=='' | cols=="," then cols= 10 w= 10 @sdsN= ' integers whose sum of decimal digis of N is a substring of N, where N < ' , ...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include<stdlib.h> #include<stdio.h> #include<time.h> void sattoloCycle(void** arr,int count){ int i,j; void* temp; if(count<2) return; for(i=count-1;i>=1;i--){ j = rand()%i; temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } int main(int argC,char* argV[]) { int i; if(argC==1) printf("UsageΒ : ...
parse arg a; say 'original:' space(a) do x=0 for words(a); @.x= word(a, x+1); end do #=x-1 by -1 to 1; j= random(0, #-1) parse value @.# @.j with @.j @.# end $= ...
Convert this C block to REXX, preserving its control flow and logic.
#include<stdlib.h> #include<stdio.h> #include<time.h> void sattoloCycle(void** arr,int count){ int i,j; void* temp; if(count<2) return; for(i=count-1;i>=1;i--){ j = rand()%i; temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } int main(int argC,char* argV[]) { int i; if(argC==1) printf("UsageΒ : ...
parse arg a; say 'original:' space(a) do x=0 for words(a); @.x= word(a, x+1); end do #=x-1 by -1 to 1; j= random(0, #-1) parse value @.# @.j with @.j @.# end $= ...
Translate this program into REXX but keep the logic exactly as in C.
#include <stdio.h> #include <stdlib.h> #include <sqlite3.h> const char *code = "CREATE TABLE address (\n" " addrID INTEGER PRIMARY KEY AUTOINCREMENT,\n" " addrStreet TEXT NOT NULL,\n" " addrCity TEXT NOT NULL,\n" " addrState TEXT NOT NULL,\n" " addrZIP TEXT NOT NULL)\n" ; int main() { sqlite3 *db = NULL; ...
options replace format comments java crossref symbols binary import java.sql.Connection import java.sql.Statement import java.sql.SQLException import java.sql.DriverManager class RTableCreate01 public properties private constant addressDDL = String '' - ' create table Address' - ' (' - ' addrID ...
Keep all operations the same but rewrite the snippet in REXX.
#include <stdio.h> #include <stdlib.h> int cycleSort(int * list, size_t l_len); void show_array(int * array, size_t a_len); int cycleSort(int * list, size_t l_len) { int writes = 0; for (int cycleStart = 0; cycleStart < l_len - 1; ++cycleStart) { int item = list[cycleStart]; int swap_tmp; ...
options replace format comments java crossref symbols nobinary runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Sort an array in place and return the number of writes. method cycleSort(array = Rexx[]) public static writes = 0 -- Loop through the array to ...
Maintain the same structure and functionality when rewriting this code in REXX.
#include <stdio.h> #include <stdlib.h> int cycleSort(int * list, size_t l_len); void show_array(int * array, size_t a_len); int cycleSort(int * list, size_t l_len) { int writes = 0; for (int cycleStart = 0; cycleStart < l_len - 1; ++cycleStart) { int item = list[cycleStart]; int swap_tmp; ...
options replace format comments java crossref symbols nobinary runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- Sort an array in place and return the number of writes. method cycleSort(array = Rexx[]) public static writes = 0 -- Loop through the array to ...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include <stdbool.h> #include <stdint.h> #include <stdio.h> bool isPrime(int64_t n) { int64_t i; if (n < 2) return false; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; if (n % 5 == 0) return n == 5; if (n % 7 == 0) return n == 7; if (n % 11 == 0) return n == 11; ...
parse arg $ . if $='' | $="," then $= 10 100 1000 10000 100000 1000000 10000000 w= length( commas( word($, words($) ) ) ) @found= ' twin prime pairs found under ' do i=1 for words($); x= word($, i) say right( commas(genP(x)), 20) @found...
Convert this C block to REXX, preserving its control flow and logic.
#include<stdio.h> int main() { FILE* fp = fopen("TAPE.FILE","w"); fprintf(fp,"This code should be able to write a file to magnetic tape.\n"); fprintf(fp,"The Wikipedia page on Magnetic tape data storage shows that magnetic tapes are still in use.\n"); fprintf(fp,"In fact, the latest format, at the time of writin...
dsName = 'TAPE.FILE' do j=1 for 100 call lineout dsName, 'this is record' j || "." end
Produce a language-to-language conversion: from C to REXX, same semantics.
#include <stdio.h> #include <stdlib.h> #include <gmodule.h> typedef int bool; int main() { int i, n, k = 0, next, *a; bool foundDup = FALSE; gboolean alreadyUsed; GHashTable* used = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable* used1000 = g_hash_table_new(g_direct_hash, g_direct_equ...
parse arg N h . if N=='' | N=="," then N= 15 if h=='' | h=="," then h= 1000 say "RecamΓ‘n's sequence for the first " N " numbers: " recaman(N) say; say "The first duplicate number in the RecamΓ‘n's sequence is: " ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> #include <stdlib.h> #include <gmodule.h> typedef int bool; int main() { int i, n, k = 0, next, *a; bool foundDup = FALSE; gboolean alreadyUsed; GHashTable* used = g_hash_table_new(g_direct_hash, g_direct_equal); GHashTable* used1000 = g_hash_table_new(g_direct_hash, g_direct_equ...
parse arg N h . if N=='' | N=="," then N= 15 if h=='' | h=="," then h= 1000 say "RecamΓ‘n's sequence for the first " N " numbers: " recaman(N) say; say "The first duplicate number in the RecamΓ‘n's sequence is: " ...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include <stdio.h> #include <stdlib.h> typedef struct func_t *func; typedef struct func_t { func (*fn) (func, func); func _; int num; } func_t; func new(func(*f)(func, func), func _) { func x = malloc(sizeof(func_t)); x->fn = f; x->_ = _; x->num = 0; ...
numeric digits 1000 say ' fib' Y(fib (50) ) say ' fib' Y(fib (12 11 10 9 8 7 6 5 4 3 2 1 0) ) say ' fact' Y(fact (60) ) say ' fact' Y(fact (0 1 2 3 4 5 6 7 8 9 10 ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <stdbool.h> typedef double Fp; typedef struct { Fp x, y, r; } Circle; Circle circles[] = { { 1.6417233788, 1.6121789534, 0.0848270516}, {-1.4944608174, 1.2077959613, 1.1039549836}, { 0.6110294452, -0.6907087527, 0.908916...
parse arg box dig . if box=='' | box==',' then box= 500 if dig=='' | dig==',' then dig= 12 numeric digits dig data = ' 1.6417233788 1.6121789534 0.0848270516', '-1.494460817...
Change the following C code into REXX without altering its purpose.
#include <stdio.h> #include <stdlib.h> #include <math.h> #include <time.h> #include <stdbool.h> typedef double Fp; typedef struct { Fp x, y, r; } Circle; Circle circles[] = { { 1.6417233788, 1.6121789534, 0.0848270516}, {-1.4944608174, 1.2077959613, 1.1039549836}, { 0.6110294452, -0.6907087527, 0.908916...
parse arg box dig . if box=='' | box==',' then box= 500 if dig=='' | dig==',' then dig= 12 numeric digits dig data = ' 1.6417233788 1.6121789534 0.0848270516', '-1.494460817...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> int main() { int n, b, d; unsigned long long i, j, sum, fact[12]; fact[0] = 1; for (n = 1; n < 12; ++n) { fact[n] = fact[n-1] * n; } for (b = 9; b <= 12; ++b) { printf("The factorions for base %d are:\n", b); for (i = 1; i < 1500000; ++i) { ...
parse arg LOb HIb lim . if LOb=='' | LOb=="," then LOb= 9 if HIb=='' | HIb=="," then HIb= 12 if lim=='' | lim=="," then lim= 1500000 - 1 do fact=0 to HIb; !.fact= !(fact) end do base=LOb to HIb @= 1 2...
Please provide an equivalent version of this C code in REXX.
#include <stdio.h> int main() { int n, b, d; unsigned long long i, j, sum, fact[12]; fact[0] = 1; for (n = 1; n < 12; ++n) { fact[n] = fact[n-1] * n; } for (b = 9; b <= 12; ++b) { printf("The factorions for base %d are:\n", b); for (i = 1; i < 1500000; ++i) { ...
parse arg LOb HIb lim . if LOb=='' | LOb=="," then LOb= 9 if HIb=='' | HIb=="," then HIb= 12 if lim=='' | lim=="," then lim= 1500000 - 1 do fact=0 to HIb; !.fact= !(fact) end do base=LOb to HIb @= 1 2...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> unsigned int divisor_sum(unsigned int n) { unsigned int total = 1, power = 2; unsigned int p; for (; (n & 1) == 0; power <<= 1, n >>= 1) { total += power; } for (p = 3; p * p <= n; p += 2) { unsigned int sum = 1; for (power = p; n % p == 0; powe...
parse arg n cols . if n=='' | n=="," then n= 100 if cols=='' | cols=="," then cols= 10 say ' index β”‚'center("sum of divisors", 102) say '───────┼'center("" , 102,'─') w= 10 $=; ...
Translate the given C code snippet into REXX without altering its behavior.
#include <stdio.h> unsigned int divisor_sum(unsigned int n) { unsigned int total = 1, power = 2; unsigned int p; for (; (n & 1) == 0; power <<= 1, n >>= 1) { total += power; } for (p = 3; p * p <= n; p += 2) { unsigned int sum = 1; for (power = p; n % p == 0; powe...
parse arg n cols . if n=='' | n=="," then n= 100 if cols=='' | cols=="," then cols= 10 say ' index β”‚'center("sum of divisors", 102) say '───────┼'center("" , 102,'─') w= 10 $=; ...
Convert this C block to REXX, preserving its control flow and logic.
#include <stdio.h> #include <stdlib.h> int isprime( int n ) { int i; if (n<2) return 0; for(i=2; i*i<=n; i++) { if (n % i == 0) {return 0;} } return 1; } int main(void) { int n = 0, p = 1; while (n<22) { printf( "%d ", n ); p++; if (isprime(p)) n+=1; } return 0; }
parse arg hi cols . if hi=='' | hi=="," then hi= 22 if cols=='' | cols=="," then cols= 10 call genP w= 10 title= ' number of primes that are (for all N) ≀ prime(22) whi...
Convert this C block to REXX, preserving its control flow and logic.
#include <stdio.h> #include <stdlib.h> int isprime( int n ) { int i; if (n<2) return 0; for(i=2; i*i<=n; i++) { if (n % i == 0) {return 0;} } return 1; } int main(void) { int n = 0, p = 1; while (n<22) { printf( "%d ", n ); p++; if (isprime(p)) n+=1; } return 0; }
parse arg hi cols . if hi=='' | hi=="," then hi= 22 if cols=='' | cols=="," then cols= 10 call genP w= 10 title= ' number of primes that are (for all N) ≀ prime(22) whi...
Convert this C block to REXX, preserving its control flow and logic.
#include <stdio.h> #include <string.h> #include <stdlib.h> int interactiveCompare(const void *x1, const void *x2) { const char *s1 = *(const char * const *)x1; const char *s2 = *(const char * const *)x2; static int count = 0; printf("(%d) Is %s <, ==, or > %s? Answer -1, 0, or 1: ", ++count, s1, s2); int res...
colors= 'violet red green indigo blue yellow orange' q= 0; #= 0; $= do j=1 for words(colors); q= inSort( word(colors, j), q) end say do i=1 for #; say ' query' right(i, length(#) )":" !.i end say say 'final orde...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdlib.h> #include <stdio.h> #include <gmp.h> void mpz_factors(mpz_t n) { int factors = 0; mpz_t s, m, p; mpz_init(s), mpz_init(m), mpz_init(p); mpz_set_ui(m, 3); mpz_set(p, n); mpz_sqrt(s, p); while (mpz_cmp(m, s) < 0) { if (mpz_divisible_p(p, m)) { gmp_printf("%Zd ", m); mpz...
parse arg n . if n=='' | n=="," then n= 9 numeric digits 20 do j=0 to n; f= 2** (2**j) + 1 say right('F'j, length(n) + 1)': ' f end say do k=0 to n; f= 2** (2**k) + 1; say ...
Convert the following code from C to REXX, ensuring the logic remains intact.
#include <stdio.h> #include <stdlib.h> void bead_sort(int *a, int len) { int i, j, max, sum; unsigned char *beads; # define BEAD(i, j) beads[i * max + j] for (i = 1, max = a[0]; i < len; i++) if (a[i] > max) max = a[i]; beads = calloc(1, max * len); for (i = 0; i < len; i++) for (j = 0; j < a[i]; j++) ...
options replace format comments java crossref symbols nobinary runSample(arg) return -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ method bead_sort(harry = Rexx[]) public static binary returns Rexx[] MIN_ = 'MIN' MAX_ = 'MAX' beads = Rexx 0 beads[MIN_] = 0 beads[MAX_] = 0...
Convert this C snippet to REXX and keep its semantics consistent.
#include <stdio.h> #include <math.h> int main() { const int N = 2; int base = 10; int c1 = 0; int c2 = 0; int k; for (k = 1; k < pow(base, N); k++) { c1++; if (k % (base - 1) == (k * k) % (base - 1)) { c2++; printf("%d ", k); } } printf(...
parse arg LO HI base . if LO=='' | LO=="," then do; LO=1; HI=1000; end if HI=='' | HI=="," then HI= LO if base=='' | base=="," then base= 10 numeric digits max(9, 2*length(HI**2) ) numbers= castOut(LO, HI, base) @cast_out= 'cast-ou...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> #include <math.h> int main() { const int N = 2; int base = 10; int c1 = 0; int c2 = 0; int k; for (k = 1; k < pow(base, N); k++) { c1++; if (k % (base - 1) == (k * k) % (base - 1)) { c2++; printf("%d ", k); } } printf(...
parse arg LO HI base . if LO=='' | LO=="," then do; LO=1; HI=1000; end if HI=='' | HI=="," then HI= LO if base=='' | base=="," then base= 10 numeric digits max(9, 2*length(HI**2) ) numbers= castOut(LO, HI, base) @cast_out= 'cast-ou...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include <stdio.h> #include <stdlib.h> #include <string.h> #define _XOPEN_SOURCE #define __USE_XOPEN #include <time.h> #define DB "database.csv" #define TRY(a) if (!(a)) {perror(#a);exit(1);} #define TRY2(a) if((a)<0) {perror(#a);exit(1);} #define FREE(a) if(a) {free(a);a=NULL;} #define sort_by(foo) \ static int b...
* 05.10.2014 *--------------------------------------------------------------------*/ x05='05'x mydb='sidb.txt' Say 'Enter your commands,Β ?, or end' Do Forever Parse Pull l Parse Var l command text Select When command='?' Then Call help When command='add' Then Do Parse Var text item ',' catego...
Rewrite the snippet below in REXX so it works the same as the original C code.
void runCode(const char *code) { int c_len = strlen(code); int i, bottles; unsigned accumulator=0; for(i=0;i<c_len;i++) { switch(code[i]) { case 'Q': printf("%s\n", code); break; case 'H': printf("Hello, world!\...
arg pgm . accumulator=0 do instructions=1 for length(pgm); ?=substr(pgm, instructions, 1) select when ?=='H' then say "Hello, world!" when ?=='Q' then...
Produce a functionally identical REXX code for the snippet given in C.
void runCode(const char *code) { int c_len = strlen(code); int i, bottles; unsigned accumulator=0; for(i=0;i<c_len;i++) { switch(code[i]) { case 'Q': printf("%s\n", code); break; case 'H': printf("Hello, world!\...
arg pgm . accumulator=0 do instructions=1 for length(pgm); ?=substr(pgm, instructions, 1) select when ?=='H' then say "Hello, world!" when ?=='Q' then...
Maintain the same structure and functionality when rewriting this code in REXX.
#!/usr/local/bin/script_gcc.sh #include <errno.h> #include <libgen.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> typedef char *STRING; typedef enum{FALSE=0, TRUE=1} BOOL; const STRING ENDCAT = NULL; #define DIALECT "c" const STRING ...
#!/usr/local/bin/regina say arg(1)
Produce a language-to-language conversion: from C to REXX, same semantics.
#!/usr/local/bin/script_gcc.sh #include <errno.h> #include <libgen.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> typedef char *STRING; typedef enum{FALSE=0, TRUE=1} BOOL; const STRING ENDCAT = NULL; #define DIALECT "c" const STRING ...
#!/usr/local/bin/regina say arg(1)
Can you help me rewrite this code in REXX instead of C, keeping it the same logically?
#include <stdio.h> unsigned int divisor_count(unsigned int n) { unsigned int total = 1; for (; (n & 1) == 0; n >>= 1) { ++total; } for (unsigned int p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ++count; } ...
parse arg LO HI cols . if LO=='' | LO=="," then LO= 1 if HI=='' | HI=="," then HI= LO + 100 - 1 if cols=='' | cols=="," then cols= 20 w= 2 + (HI>45359) say 'The number of divisors (tau) for integers up to ' n " (i...
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; for (; (n & 1) == 0; n >>= 1) { ++total; } for (unsigned int p = 3; p * p <= n; p += 2) { unsigned int count = 1; for (; n % p == 0; n /= p) { ++count; } ...
parse arg LO HI cols . if LO=='' | LO=="," then LO= 1 if HI=='' | HI=="," then HI= LO + 100 - 1 if cols=='' | cols=="," then cols= 20 w= 2 + (HI>45359) say 'The number of divisors (tau) for integers up to ' n " (i...
Preserve the algorithm and functionality while converting the code from C to REXX.
#include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { const int MU_MAX = 1000000; int i, j; int *mu; int sqroot; sqroot = (int)sqrt(MU_MAX); mu = malloc((MU_MAX + 1) * sizeof(int)); for (i = 0; i < MU_MAX;i++) { mu[i] = 1; } for (i = 2...
parse arg LO HI grp . if LO=='' | LO=="," then LO= 0 if HI=='' | HI=="," then HI= 199 if grp=='' | grp=="," then grp= 20 call genP HI say center(' The MΓΆ...
Produce a functionally identical REXX code for the snippet given in C.
#include <stdio.h> int main(){ int ptr=0, i=0, cell[7]; for( i=0; i<7; ++i) cell[i]=0; ptr+= 1; if(ptr>=7) perror("Program pointer overflow"); cell[ptr]+= 8; while(cell[ptr]) { ptr-= 1; if(ptr<0) perror("Program pointer underflow"); cell[ptr]+= 9; ...
@.=0 p =0 ! =0 parse arg $ if $='' then $=, "++++++++++ ...
Rewrite this program in REXX while keeping its functionality equivalent to the C version.
#include <stdio.h> int main(){ int ptr=0, i=0, cell[7]; for( i=0; i<7; ++i) cell[i]=0; ptr+= 1; if(ptr>=7) perror("Program pointer overflow"); cell[ptr]+= 8; while(cell[ptr]) { ptr-= 1; if(ptr<0) perror("Program pointer underflow"); cell[ptr]+= 9; ...
@.=0 p =0 ! =0 parse arg $ if $='' then $=, "++++++++++ ...
Write a version of this C function in REXX with identical behavior.
#include <stdio.h> int Gcd(int v1, int v2) { int a, b, r; if (v1 < v2) { a = v2; b = v1; } else { a = v1; b = v2; } do { r = a % b; if (r == 0) { break; } else { a = b; b = r; } } while (1 == 1); return b; } int NotInList(int num, int numtrip, int *tripletslist) { for...
parse arg n cols . if n=='' | n=="," then n= 50 if cols=='' | cols=="," then cols= 10 w= max(3, length( commas(n) ) ) @copt= ' coprime triplets where N < ' commas(n) if cols>0 then say ' index ...
Write the same algorithm in REXX as shown in this C implementation.
#include <stdio.h> int Gcd(int v1, int v2) { int a, b, r; if (v1 < v2) { a = v2; b = v1; } else { a = v1; b = v2; } do { r = a % b; if (r == 0) { break; } else { a = b; b = r; } } while (1 == 1); return b; } int NotInList(int num, int numtrip, int *tripletslist) { for...
parse arg n cols . if n=='' | n=="," then n= 50 if cols=='' | cols=="," then cols= 10 w= max(3, length( commas(n) ) ) @copt= ' coprime triplets where N < ' commas(n) if cols>0 then say ' index ...
Write the same algorithm in REXX as shown in this C implementation.
#include <stdio.h> #include <stdlib.h> int* mertens_numbers(int max) { int* m = malloc((max + 1) * sizeof(int)); if (m == NULL) return m; m[1] = 1; for (int n = 2; n <= max; ++n) { m[n] = 1; for (int k = 2; k <= n; ++k) m[n] -= m[n/k]; } return m; } int main...
parse arg LO HI grp eqZ xZ . if LO=='' | LO=="," then LO= 0 if HI=='' | HI=="," then HI= 199 if grp=='' | grp=="," then grp= 20 if eqZ=='' | eqZ=="," then eqZ= 1000 if xZ=='' | xZ=="," then xZ= 1000 call genP ...
Transform the following C implementation into REXX, maintaining the same output and logic.
#include <math.h> #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) { ...
numeric digits 20 parse arg n cols . if n=='' | n=="," then n= 50 if cols=='' | cols=="," then cols= 5 say ' index β”‚'center("product of divisors", 102) say '───────┼'center("" , 102,'─') w= max(...
Rewrite the snippet below in REXX so it works the same as the original C code.
#include <math.h> #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) { ...
numeric digits 20 parse arg n cols . if n=='' | n=="," then n= 50 if cols=='' | cols=="," then cols= 5 say ' index β”‚'center("product of divisors", 102) say '───────┼'center("" , 102,'─') w= max(...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <locale.h> #define LIMIT 1000000 #define LOWER_LIMIT 2500 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 = ...
parse arg n cols . if n=='' | n=="," then n= 2500 if cols=='' | cols=="," then cols= 10 nn= n; n= abs(n) call genP n w= 10 if cols>0 then say...
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 <locale.h> #define LIMIT 1000000 #define LOWER_LIMIT 2500 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 = ...
parse arg n cols . if n=='' | n=="," then n= 2500 if cols=='' | cols=="," then cols= 10 nn= n; n= abs(n) call genP n w= 10 if cols>0 then say...
Write the same algorithm in REXX as shown in this C implementation.
#include <stdio.h> #include <stdlib.h> #include <locale.h> int locale_ok = 0; wchar_t s_suits[] = L"β™ β™₯♦♣"; const char *s_suits_ascii[] = { "S", "H", "D", "C" }; const char *s_nums[] = { "WHAT", "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "OVERFLOW" }; typedef struct { int suit, number, _s;...
* 1) Build ordered Card deck * 2) Create shuffled stack * 3) Deal 5 cards to 4 players each * 4) show what cards have been dealt and what's left on the stack * 05.07.2012 Walter Pachl **********************************************************************/ colors='S H C D' ranks ='A 2 3 4 5 6 7 8 9 T J Q K' i=0 cards='...
Generate a REXX translation of this C snippet without changing its computational steps.
#include <stdio.h> int gcd(int a, int b) { int c; while (b) { c = a; a = b; b = c % b; } return a; } struct pair { int x, y; }; void printPair(struct pair const *p) { printf("{%d, %d}\n", p->x, p->y); } int main() { struct pair pairs[] = { {21,15}, {17,23}...
parse arg @ if @='' | @=="," then @= '21,15 17,23 36,12 18,29 60,15 21,22,25,143 -2,0 0,-3' do j=1 for words(@); say stuff= translate( word(@, j), , ',') cofactor= gcd(stuff) if cofactor==1 then say stuf...
Ensure the translated REXX code behaves exactly like the original C snippet.
#include <stdio.h> int gcd(int a, int b) { int c; while (b) { c = a; a = b; b = c % b; } return a; } struct pair { int x, y; }; void printPair(struct pair const *p) { printf("{%d, %d}\n", p->x, p->y); } int main() { struct pair pairs[] = { {21,15}, {17,23}...
parse arg @ if @='' | @=="," then @= '21,15 17,23 36,12 18,29 60,15 21,22,25,143 -2,0 0,-3' do j=1 for words(@); say stuff= translate( word(@, j), , ',') cofactor= gcd(stuff) if cofactor==1 then say stuf...
Translate this program into REXX but keep the logic exactly as in C.
#include<stdlib.h> #include<stdio.h> long totient(long n){ long tot = n,i; for(i=2;i*i<=n;i+=2){ if(n%i==0){ while(n%i==0) n/=i; tot-=tot/i; } if(i==2) i=1; } if(n>1) tot-=tot/n; return tot; } long* perfectTotients(long n){ long *ptList = (long*)malloc(n*sizeof(long)), m,count=0,su...
parse arg N . if N=='' | N=="," then N= 20 @.= . p= 0 $= do j=3 by 2 until p==N; s= phi(j) a= s ...
Port the following code from C to REXX with equivalent syntax and logic.
#include<stdlib.h> #include<stdio.h> long totient(long n){ long tot = n,i; for(i=2;i*i<=n;i+=2){ if(n%i==0){ while(n%i==0) n/=i; tot-=tot/i; } if(i==2) i=1; } if(n>1) tot-=tot/n; return tot; } long* perfectTotients(long n){ long *ptList = (long*)malloc(n*sizeof(long)), m,count=0,su...
parse arg N . if N=='' | N=="," then N= 20 @.= . p= 0 $= do j=3 by 2 until p==N; s= phi(j) a= s ...
Convert this C block to REXX, preserving its control flow and logic.
#include <stdint.h> #include <stdio.h> uint64_t factorial(uint64_t n) { uint64_t res = 1; if (n == 0) return res; while (n > 0) res *= n--; return res; } uint64_t lah(uint64_t n, uint64_t k) { if (k == 1) return factorial(n); if (k == n) return 1; if (k > n) return 0; if (k < 1 || n < ...
parse arg lim . if lim=='' | lim=="," then lim= 12 olim= lim lim= abs(lim) numeric digits max(9, 4*lim) max#.= 0 !.=. @.= ...
Port the following code from C to REXX with equivalent syntax and logic.
#include <stdint.h> #include <stdio.h> uint64_t factorial(uint64_t n) { uint64_t res = 1; if (n == 0) return res; while (n > 0) res *= n--; return res; } uint64_t lah(uint64_t n, uint64_t k) { if (k == 1) return factorial(n); if (k == n) return 1; if (k > n) return 0; if (k < 1 || n < ...
parse arg lim . if lim=='' | lim=="," then lim= 12 olim= lim lim= abs(lim) numeric digits max(9, 4*lim) max#.= 0 !.=. @.= ...
Change the programming language of this snippet from C to REXX without modifying what it does.
#include<stdio.h> int main() { int arr[5] = {0, 2, 11, 19, 90},sum = 21,i,j,check = 0; for(i=0;i<4;i++){ for(j=i+1;j<5;j++){ if(arr[i]+arr[j]==sum){ printf("[%d,%d]",i,j); check = 1; break; } } } if(check==0) printf("[]"); return 0; }
a=.array~of( -5, 26, 0, 2, 11, 19, 90) x=21 n=0 do i=1 To a~items Do j=i+1 To a~items If a[i]+a[j]=x Then Do Say '['||i-1||','||j-1||']' n=n+1 End End End If n=0 Then Say '[] - no items found'
Convert this C snippet to REXX and keep its semantics consistent.
#include<stdio.h> int main() { int arr[5] = {0, 2, 11, 19, 90},sum = 21,i,j,check = 0; for(i=0;i<4;i++){ for(j=i+1;j<5;j++){ if(arr[i]+arr[j]==sum){ printf("[%d,%d]",i,j); check = 1; break; } } } if(check==0) printf("[]"); return 0; }
a=.array~of( -5, 26, 0, 2, 11, 19, 90) x=21 n=0 do i=1 To a~items Do j=i+1 To a~items If a[i]+a[j]=x Then Do Say '['||i-1||','||j-1||']' n=n+1 End End End If n=0 Then Say '[] - no items found'