Instruction
stringlengths
45
106
input_code
stringlengths
1
13.7k
output_code
stringlengths
1
13.7k
Preserve the algorithm and functionality while converting the code from Python to REXX.
from itertools import izip def gen_row(w, s): def gen_seg(o, sp): if not o: return [[2] * sp] return [[2] * x + o[0] + tail for x in xrange(1, sp - len(o) + 2) for tail in gen_seg(o[1:], sp - x)] return [x[1:] for x in gen_seg([[1] * i for i in ...
Parse Arg fn Parse Var fn ou'.' maxpn = 10000 output = ou'.out.txt' cc = linein(fn) rows = words(cc) dd = linein(fn) cols = words(dd) char = '0ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk' cntr = 0 Do i = 1 To rows rowpp.i = CV(cc,i) cntr = cntr + sum...
Ensure the translated REXX code behaves exactly like the original Python snippet.
from itertools import izip def gen_row(w, s): def gen_seg(o, sp): if not o: return [[2] * sp] return [[2] * x + o[0] + tail for x in xrange(1, sp - len(o) + 2) for tail in gen_seg(o[1:], sp - x)] return [x[1:] for x in gen_seg([[1] * i for i in ...
Parse Arg fn Parse Var fn ou'.' maxpn = 10000 output = ou'.out.txt' cc = linein(fn) rows = words(cc) dd = linein(fn) cols = words(dd) char = '0ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk' cntr = 0 Do i = 1 To rows rowpp.i = CV(cc,i) cntr = cntr + sum...
Ensure the translated REXX code behaves exactly like the original Python snippet.
import mpmath as mp with mp.workdps(72): def integer_term(n): p = 532 * n * n + 126 * n + 9 return (p * 2**5 * mp.factorial(6 * n)) / (3 * mp.factorial(n)**6) def exponent_term(n): return -(mp.mpf("6.0") * n + 3) def nthterm(n): return integer_term(n) * mp.mpf("10.0")**ex...
numeric digits length( pi() ) + length(.); w= 102 say $( , 3) $( , w%2) $('power', 5) $( , w) say $('N', 3) $('integer term', w%2) $('of 10', 5) $('Nth term', w) say $( , 3, "─") $( , w%2, "─") $( ...
Change the programming language of this snippet from Python to REXX without modifying what it does.
import mpmath as mp with mp.workdps(72): def integer_term(n): p = 532 * n * n + 126 * n + 9 return (p * 2**5 * mp.factorial(6 * n)) / (3 * mp.factorial(n)**6) def exponent_term(n): return -(mp.mpf("6.0") * n + 3) def nthterm(n): return integer_term(n) * mp.mpf("10.0")**ex...
numeric digits length( pi() ) + length(.); w= 102 say $( , 3) $( , w%2) $('power', 5) $( , w) say $('N', 3) $('integer term', w%2) $('of 10', 5) $('Nth term', w) say $( , 3, "─") $( , w%2, "─") $( ...
Convert the following code from Python to REXX, ensuring the logic remains intact.
from __future__ import print_function def add_reverse(num, max_iter=1000): i, nums = 0, {num} while True: i, num = i+1, num + reverse_int(num) nums.add(num) if reverse_int(num) == num or i >= max_iter: break return nums def reverse_int(num): return int(str(num)...
parse arg high limit . if high='' | high=="," then high= 10000 if limit='' | limit=="," then limit= 500 numeric digits limit % 2 T.= 0; @.= T.; #.=@.; w= length(high) $= do j=1 for hig...
Maintain the same structure and functionality when rewriting this code in REXX.
from __future__ import print_function def add_reverse(num, max_iter=1000): i, nums = 0, {num} while True: i, num = i+1, num + reverse_int(num) nums.add(num) if reverse_int(num) == num or i >= max_iter: break return nums def reverse_int(num): return int(str(num)...
parse arg high limit . if high='' | high=="," then high= 10000 if limit='' | limit=="," then limit= 500 numeric digits limit % 2 T.= 0; @.= T.; #.=@.; w= length(high) $= do j=1 for hig...
Convert the following code from Python to REXX, ensuring the logic remains intact.
import re from fractions import Fraction from pprint import pprint as pp equationtext = def parse_eqn(equationtext=equationtext): eqn_re = re.compile(r) found = eqn_re.findall(equationtext) machins, part = [], [] for lhs, sign, mult, numer, denom in eqn_re.findall(equationtext): if lhs and ...
* 09.04.2014 Walter Pachl the REXX solution adapted for ooRexx * which provides a function package rxMath *--------------------------------------------------------------------*/ Numeric Digits 16 Numeric Fuzz 3; pi=rxCalcpi(); a.='' a.1 = 'pi/4 = rxCalcarctan(1/2,16,'R') + rxC...
Port the provided Python code into REXX while preserving the original functionality.
import re from fractions import Fraction from pprint import pprint as pp equationtext = def parse_eqn(equationtext=equationtext): eqn_re = re.compile(r) found = eqn_re.findall(equationtext) machins, part = [], [] for lhs, sign, mult, numer, denom in eqn_re.findall(equationtext): if lhs and ...
* 09.04.2014 Walter Pachl the REXX solution adapted for ooRexx * which provides a function package rxMath *--------------------------------------------------------------------*/ Numeric Digits 16 Numeric Fuzz 3; pi=rxCalcpi(); a.='' a.1 = 'pi/4 = rxCalcarctan(1/2,16,'R') + rxC...
Translate the given Python code snippet into REXX without altering its behavior.
from math import factorial as fact from random import randrange from textwrap import wrap def identity_perm(n): return list(range(n)) def unranker1(n, r, pi): while n > 0: n1, (rdivn, rmodn) = n-1, divmod(r, n) pi[n1], pi[rmodn] = pi[rmodn], pi[n1] n = n1 r = rdivn return ...
parse arg N y seed . if N=='' | N=="," then N= 4 if y=='' | y=="," then y= 17 if datatype(seed,'W') then call random ,,seed permutes= permSets(N) w= length(permutes) @.= do p=0 f...
Generate a REXX translation of this Python snippet without changing its computational steps.
from math import factorial as fact from random import randrange from textwrap import wrap def identity_perm(n): return list(range(n)) def unranker1(n, r, pi): while n > 0: n1, (rdivn, rmodn) = n-1, divmod(r, n) pi[n1], pi[rmodn] = pi[rmodn], pi[n1] n = n1 r = rdivn return ...
parse arg N y seed . if N=='' | N=="," then N= 4 if y=='' | y=="," then y= 17 if datatype(seed,'W') then call random ,,seed permutes= permSets(N) w= length(permutes) @.= do p=0 f...
Generate a REXX translation of this Python snippet without changing its computational steps.
from math import log, modf, floor def p(l, n, pwr=2): l = int(abs(l)) digitcount = floor(log(l, 10)) log10pwr = log(pwr, 10) raised, found = -1, 0 while found < n: raised += 1 firstdigits = floor(10**(modf(log10pwr * raised)[0] + digitcount)) if firstdigits == l: ...
parse arg L n b . if L=='' | L=="," then L= 12 if n=='' | n=="," then n= 1 if b=='' | b=="," then b= 2 LL= length(L) fd= left(L, 1) fr= substr(L, 2) ...
Write the same algorithm in REXX as shown in this Python implementation.
from math import log, modf, floor def p(l, n, pwr=2): l = int(abs(l)) digitcount = floor(log(l, 10)) log10pwr = log(pwr, 10) raised, found = -1, 0 while found < n: raised += 1 firstdigits = floor(10**(modf(log10pwr * raised)[0] + digitcount)) if firstdigits == l: ...
parse arg L n b . if L=='' | L=="," then L= 12 if n=='' | n=="," then n= 1 if b=='' | b=="," then b= 2 LL= length(L) fd= left(L, 1) fr= substr(L, 2) ...
Convert this Python block to REXX, preserving its control flow and logic.
import random def is_Prime(n): if n!=int(n): return False n=int(n) if n==0 or n==1 or n==4 or n==6 or n==8 or n==9: return False if n==2 or n==3 or n==5 or n==7: return True s = 0 d = n-1 while d%2==0: d>>=1 s+=1 assert(2**s * d == n-1...
parse arg n . if n=='' | n=="," then n= 50 numeric digits n big= copies(9, digits() ) @.= '2nd'; @.1= '1st' do t=1 to -1 by -2; usum= 0; vsum= 0; s= 0 #...
Port the provided Python code into REXX while preserving the original functionality.
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23] def isPrime(n): if n < 2: return False for i in primes: if n == i: return True if n % i == 0: return False if i * i > n: return True print "Oops,", n, " is too large" def init(): s = 24 w...
numeric digits 200 parse arg LOx HIx LOn HIn . if LOx=='' | LOx=="," then LOx= 1 if HIx=='' | HIx=="," then HIx= LOx + 24 if LOn=='' | LOn=="," then LOn= 2 if HIn=='' | HIn=="," then HIn= LOn + 27 call genP HIn ...
Transform the following Python implementation into REXX, maintaining the same output and logic.
from itertools import combinations as cmb def isP(n): if n == 2: return True if n % 2 == 0: return False return all(n % x > 0 for x in range(3, int(n ** 0.5) + 1, 2)) def genP(n): p = [2] p.extend([x for x in range(3, n + 1, 2) if isP(x)]) return p data = [ (99809, 1), ...
parse arg what do until what=='' parse var what x n what; parse var x x '-' y parse var n n '-' m if x=='' | x=="," then x= 19 if y=='' | y=="," then y= x if n=='' | n==",...
Translate this program into REXX but keep the logic exactly as in Python.
computed = {} def sterling1(n, k): key = str(n) + "," + str(k) if key in computed.keys(): return computed[key] if n == k == 0: return 1 if n > 0 and k == 0: return 0 if k > n: return 0 result = sterling1(n - 1, k - 1) + (n - 1) * sterling1(n - 1, k) computed[key] = result return result print("Unsigne...
parse arg lim . if lim=='' | lim=="," then lim= 12 olim= lim lim= abs(lim) numeric digits max(9, 2*lim) @.=; @.0.0= 1 do n=0 for...
Please provide an equivalent version of this Python code in REXX.
computed = {} def sterling1(n, k): key = str(n) + "," + str(k) if key in computed.keys(): return computed[key] if n == k == 0: return 1 if n > 0 and k == 0: return 0 if k > n: return 0 result = sterling1(n - 1, k - 1) + (n - 1) * sterling1(n - 1, k) computed[key] = result return result print("Unsigne...
parse arg lim . if lim=='' | lim=="," then lim= 12 olim= lim lim= abs(lim) numeric digits max(9, 2*lim) @.=; @.0.0= 1 do n=0 for...
Keep all operations the same but rewrite the snippet in REXX.
from __future__ import print_function from shapely.geometry import LineString if __name__=="__main__": line = LineString([(0,0),(1,0.1),(2,-0.1),(3,5),(4,6),(5,7),(6,8.1),(7,9),(8,9),(9,9)]) print (line.simplify(1.0, preserve_topology=False))
parse arg epsilon pts if epsilon='' | epsilon="," then epsilon= 1 if pts='' then pts= '(0,0) (1,0.1) (2,-0.1) (3,5) (4,6) (5,7) (6,8.1) (7,9) (8,9) (9,9)' pts= space(pts) say ' error threshold: ' epsilon say ' points spe...
Convert this Python snippet to REXX and keep its semantics consistent.
from __future__ import print_function from shapely.geometry import LineString if __name__=="__main__": line = LineString([(0,0),(1,0.1),(2,-0.1),(3,5),(4,6),(5,7),(6,8.1),(7,9),(8,9),(9,9)]) print (line.simplify(1.0, preserve_topology=False))
parse arg epsilon pts if epsilon='' | epsilon="," then epsilon= 1 if pts='' then pts= '(0,0) (1,0.1) (2,-0.1) (3,5) (4,6) (5,7) (6,8.1) (7,9) (8,9) (9,9)' pts= space(pts) say ' error threshold: ' epsilon say ' points spe...
Port the following code from Python to REXX with equivalent syntax and logic.
v1 = PVector(5, 7) v2 = PVector(2, 3) println('{} {} {} {}\n'.format( v1.x, v1.y, v1.mag(), v1.heading())) println(v1 + v2) println(v1 - v2) println(v1 * 11) println(v1 / 2) println('') println(v1.sub(v1)) println(v1.add(v2)) println(v1.mult(10)) println(v1.div(10))
v=.vector~new(12,-3); Say "v=.vector~new(12,-3) =>" v~print v~ab(1,1,6,4); Say "v~ab(1,1,6,4) =>" v~print v~al(45,2); Say "v~al(45,2) =>" v~print w=v~'+'(v); Say "w=v~'+'(v) =>" w~print x=v~'-'(w); Say "x=v~'-'(w) =>" x~print y=x~'*'(3); ...
Keep all operations the same but rewrite the snippet in REXX.
class Point: b = 7 def __init__(self, x=float('inf'), y=float('inf')): self.x = x self.y = y def copy(self): return Point(self.x, self.y) def is_zero(self): return self.x > 1e20 or self.x < -1e20 def neg(self): return Point(self.x, -self.y) def dbl(s...
numeric digits 100 a= func(1) ; say ' a = ' show(a) b= func(2) ; say ' b = ' show(b) c= add(a, b) ; say ' c = (a+b) =' show(c) d= neg(c) ...
Rewrite this program in REXX while keeping its functionality equivalent to the Python version.
class Point: b = 7 def __init__(self, x=float('inf'), y=float('inf')): self.x = x self.y = y def copy(self): return Point(self.x, self.y) def is_zero(self): return self.x > 1e20 or self.x < -1e20 def neg(self): return Point(self.x, -self.y) def dbl(s...
numeric digits 100 a= func(1) ; say ' a = ' show(a) b= func(2) ; say ' b = ' show(b) c= add(a, b) ; say ' c = (a+b) =' show(c) d= neg(c) ...
Transform the following Python implementation into REXX, maintaining the same output and logic.
import math def test_func(x): return math.cos(x) def mapper(x, min_x, max_x, min_to, max_to): return (x - min_x) / (max_x - min_x) * (max_to - min_to) + min_to def cheb_coef(func, n, min, max): coef = [0.0] * n for i in xrange(n): f = func(mapper(math.cos(math.pi * (i + 0.5) / n), -1, 1, min,...
numeric digits length( pi() ) - length(.) parse arg a b N . if a=='' | a=="," then a= 0 if b=='' | b=="," then b= 1 if N=='' | N=="," then N= 10 fac= 2 / N; pin= pi / N Dma= (b-a) / 2 ...
Generate an equivalent REXX version of this Python code.
import math def test_func(x): return math.cos(x) def mapper(x, min_x, max_x, min_to, max_to): return (x - min_x) / (max_x - min_x) * (max_to - min_to) + min_to def cheb_coef(func, n, min, max): coef = [0.0] * n for i in xrange(n): f = func(mapper(math.cos(math.pi * (i + 0.5) / n), -1, 1, min,...
numeric digits length( pi() ) - length(.) parse arg a b N . if a=='' | a=="," then a= 0 if b=='' | b=="," then b= 1 if N=='' | N=="," then N= 10 fac= 2 / N; pin= pi / N Dma= (b-a) / 2 ...
Port the following code from Python to REXX with equivalent syntax and logic.
def bwt(s): assert "\002" not in s and "\003" not in s, "Input string cannot contain STX and ETX characters" s = "\002" + s + "\003" table = sorted(s[i:] + s[:i] for i in range(len(s))) last_column = [row[-1:] for row in table] return "".join(last_column) def ibwt(r): table =...
$.= parse arg $.1 if $.1='' then do; $.1= "banana" $.2= "BANANA" $.3= "appellee" $.4= "dogwood" $.5= "TO BE OR NOT TO BE OR WANT TO BE O...
Please provide an equivalent version of this Python code in REXX.
def bwt(s): assert "\002" not in s and "\003" not in s, "Input string cannot contain STX and ETX characters" s = "\002" + s + "\003" table = sorted(s[i:] + s[:i] for i in range(len(s))) last_column = [row[-1:] for row in table] return "".join(last_column) def ibwt(r): table =...
$.= parse arg $.1 if $.1='' then do; $.1= "banana" $.2= "BANANA" $.3= "appellee" $.4= "dogwood" $.5= "TO BE OR NOT TO BE OR WANT TO BE O...
Translate this program into REXX but keep the logic exactly as in Python.
import random def riffleShuffle(va, flips): nl = va for n in range(flips): cutPoint = len(nl)/2 + random.choice([-1, 1]) * random.randint(0, len(va)/10) left = nl[0:cutPoint] right = nl[cutPoint:] del nl[:] while (len(left) > 0 and len(right) > 0): ...
call create; call show 'new deck' call create; call riffle 1 call show 'riffle shuffle' call create; call overhand 1/5 call show 'overhand shuffle' call create; call barnYard 13 ca...
Produce a language-to-language conversion: from Python to REXX, same semantics.
import random def riffleShuffle(va, flips): nl = va for n in range(flips): cutPoint = len(nl)/2 + random.choice([-1, 1]) * random.randint(0, len(va)/10) left = nl[0:cutPoint] right = nl[cutPoint:] del nl[:] while (len(left) > 0 and len(right) > 0): ...
call create; call show 'new deck' call create; call riffle 1 call show 'riffle shuffle' call create; call overhand 1/5 call show 'overhand shuffle' call create; call barnYard 13 ca...
Please provide an equivalent version of this Python code in REXX.
from itertools import accumulate, chain, count, islice from fractions import Fraction def faulhaberTriangle(m): def go(rs, n): def f(x, y): return Fraction(n, x) * y xs = list(map(f, islice(count(2), m), rs)) return [Fraction(1 - sum(xs), 1)] + xs return list(accum...
Numeric Digits 100 Do r=0 To 20 ra=r-1 If r=0 Then f.r.1=1 Else Do rsum=0 Do c=2 To r+1 ca=c-1 f.r.c=fdivide(fmultiply(f.ra.ca,r),c) rsum=fsum(rsum,f.r.c) End f.r.1=fsubtract(1,rsum) End End Do r=0 To 9 ol='' Do c=1 To r+1 ol=ol right(f.r.c,5) End Say ol...
Write the same algorithm in REXX as shown in this Python implementation.
try: import psyco psyco.full() except ImportError: pass MAX_N = 300 BRANCH = 4 ra = [0] * MAX_N unrooted = [0] * MAX_N def tree(br, n, l, sum = 1, cnt = 1): global ra, unrooted, MAX_N, BRANCH for b in xrange(br + 1, BRANCH + 1): sum += n if sum >= MAX_N: return ...
parse arg nodes . if nodes=='' | nodes=="," then nodes= 100 rooted. = 0; rooted.0= 1; rooted.1= 1 unrooted. = 0; unrooted.0= 1; unrooted.1= 1 numeric digits max(9, nodes % 2) w= length(nodes) say right(0, w) u...
Transform the following Python implementation into REXX, maintaining the same output and logic.
try: import psyco psyco.full() except ImportError: pass MAX_N = 300 BRANCH = 4 ra = [0] * MAX_N unrooted = [0] * MAX_N def tree(br, n, l, sum = 1, cnt = 1): global ra, unrooted, MAX_N, BRANCH for b in xrange(br + 1, BRANCH + 1): sum += n if sum >= MAX_N: return ...
parse arg nodes . if nodes=='' | nodes=="," then nodes= 100 rooted. = 0; rooted.0= 1; rooted.1= 1 unrooted. = 0; unrooted.0= 1; unrooted.1= 1 numeric digits max(9, nodes % 2) w= length(nodes) say right(0, w) u...
Produce a functionally identical REXX code for the snippet given in Python.
import re _vowels = 'AEIOU' def replace_at(text, position, fromlist, tolist): for f, t in zip(fromlist, tolist): if text[position:].startswith(f): return ''.join([text[:position], t, text[position+len(f):]]) return text def replace_e...
return strip( left(key, 6) )
Port the provided Python code into REXX while preserving the original functionality.
import re _vowels = 'AEIOU' def replace_at(text, position, fromlist, tolist): for f, t in zip(fromlist, tolist): if text[position:].startswith(f): return ''.join([text[:position], t, text[position+len(f):]]) return text def replace_e...
return strip( left(key, 6) )
Produce a functionally identical REXX code for the snippet given in Python.
Import-Module ActiveDirectory $searchData = "user name" $searchBase = "DC=example,DC=com" get-aduser -Filter((DistinguishedName -eq $searchdata) -or (UserPrincipalName -eq $searchdata) -or (SamAccountName -eq $searchdata)) -SearchBase $searchBase
options replace format comments java crossref symbols binary import org.apache.directory.ldap.client.api.LdapConnection import org.apache.directory.ldap.client.api.LdapNetworkConnection import org.apache.directory.shared.ldap.model.cursor.EntryCursor import org.apache.directory.shared.ldap.model.entry.Entry import or...
Convert this Python block to REXX, preserving its control flow and logic.
def isPrime(n): if n < 2: return False if n % 2 == 0: return n == 2 if n % 3 == 0: return n == 3 d = 5 while d * d <= n: if n % d == 0: return False d += 2 if n % d == 0: return False d += 4 return True def genera...
parse arg N . if N=='' | N=="," then N= 1000000 Np= N+1; w= length(N-1) H= N* (2**max(4, (w%2+1) ) ) @.= . #= 1 do j=3 by 2; ...
Generate an equivalent REXX version of this Python code.
def bags(n,cache={}): if not n: return [(0, "")] upto = sum([bags(x) for x in range(n-1, 0, -1)], []) return [(c+1, '('+s+')') for c,s in bagchain((0, ""), n-1, upto)] def bagchain(x, n, bb, start=0): if not n: return [x] out = [] for i in range(start, len(bb)): c,s = bb[i] if c <= n: out += bagchain((x[0]...
parse arg N . if N=='' | N=="," then N=5 if N>5 then do; say N "isn't supported for this program at this time."; exit 13; end nn= N + N - 1 numeric digits 200 numeric digits max(9, 1 + le...
Maintain the same structure and functionality when rewriting this code in REXX.
from __future__ import print_function def lgen(even=False, nmax=1000000): start = 2 if even else 1 n, lst = 1, list(range(start, nmax + 1, 2)) lenlst = len(lst) yield lst[0] while n < lenlst and lst[n] < lenlst: yield lst[n] n, lst = n + 1, [j for i,j in enumerate(lst, 1) if i % lst...
parse arg bot top func _ . if func=='' then func= 'lucky' s= left('s', bot\==top & top\==",") say func 'number's":" bot top '───►' $lucky(bot, top, func, _) exit 0 $lucky: arg x,y,f,?; if y=='' | y=="," then ...
Ensure the translated REXX code behaves exactly like the original Python snippet.
from __future__ import division import matplotlib.pyplot as plt import random mean, stddev, size = 50, 4, 100000 data = [random.gauss(mean, stddev) for c in range(size)] mn = sum(data) / size sd = (sum(x*x for x in data) / size - (sum(data) / size) ** 2) ** 0.5 print("Sample mean = %g; Stddev = %g; max = %g;...
numeric digits 20 parse arg n seed . if n=='' | n=="," then n= 10000 if datatype(seed, 'W') then call random ,,seed call pi do g=1 for n; #.g= sqrt( -2 * ln( rand() ) ) * c...
Port the provided Python code into REXX while preserving the original functionality.
def getA004290(n): if n < 2: return 1 arr = [[0 for _ in range(n)] for _ in range(n)] arr[0][0] = 1 arr[0][1] = 1 m = 0 while True: m += 1 if arr[m - 1][-10 ** m % n] == 1: break arr[m][0] = 1 for k in range(1, n): arr[m][k] = max([...
numeric digits 30; w= length( commas( copies(1, digits()))) parse arg list if list=='' then list= 1..10 95..105 297 say center(' N ', 9, "─") center(' B10 ', w, "─") center(' multiplier ', w, "─") do i=1 for words(list) z= word(list, i); LO= z; HI= z if po...
Please provide an equivalent version of this Python code in REXX.
from itertools import chain, count, islice, repeat from functools import reduce from math import sqrt from time import time def weirds(): def go(n): ds = descPropDivs(n) d = sum(ds) - n return [n] if 0 < d and not hasSum(d, ds) else [] return concatMap(go)(count(1)) def hasS...
parse arg n cols . if n=='' | n=="," then n= 25 if cols=='' | cols=="," then cols= 10 w= 10 if cols>0 then say ' index β”‚'center(' weird numbers', 1 + cols*(w+1) ) if cols>0 then say '───────┼'center("" ...
Translate this program into REXX but keep the logic exactly as in Python.
def validate(diagram): rawlines = diagram.splitlines() lines = [] for line in rawlines: if line != '': lines.append(line) if len(lines) == 0: print('diagram has no non-empty lines!') return None width = len(line...
numeric digits 100 er= '***error*** illegal input txt' parse arg iFID test . if iFID=='' | iFID=="," then iFID= 'ASCIIART.TXT' if test=='' | test=="," then test= 'cafe8050800000808080000a' w= 0; wb= 0; !.= 0; ...
Produce a language-to-language conversion: from Python to REXX, same semantics.
def divisors(n): divs = [1] for ii in range(2, int(n ** 0.5) + 3): if n % ii == 0: divs.append(ii) divs.append(int(n / ii)) divs.append(n) return list(set(divs)) def is_prime(n): return len(divisors(n)) == 2 def primes(): ii = 1 while True: ii += 1...
parse arg N . if N=='' | N=="," then N= 15 if N>=50 then numeric digits 10 w= 50 say '─divisors─' center("the Nth number with exactly N divisors", w, '─') @.1= 2; ...
Ensure the translated REXX code behaves exactly like the original Python snippet.
import readline while True: try: print(input('> ')) except: break
trace off signal on syntax; signal on noValue cmdX='ATTRIB CAL CHDIR COPY DEL DIR ECHO EDIT FC FIND KEDIT LLL MEM MKDIR MORE REM REXX', 'RMDIR SET TYPE VER XCOPY' cls= 'CLS' @hist.= '*** command not defi...
Change the following Python code into REXX without altering its purpose.
import sys class UserInput: def __init__(self,chunk): self.formFeed = int(chunk[0]) self.lineFeed = int(chunk[1]) self.tab = int(chunk[2]) self.space = int(chunk[3]) def __str__(self): return "(ff=%d; lf=%d; tb=%d; sp%d)" % (self.formFeed,self.lineFeed,self.tab,self.spa...
parse arg iFID . if iFID=='' | iFID=="," then iFID= 'JIT.TXT' $= 'abcdefghijklmnopqrstuvwxyz'; _=$; upper _; $= "0123456789"$ || _; $$=$ || xrange() prompt= '────────── enter four positive integers or Quit' pag=1; lin=1; FF= 'c'x @.= ...
Transform the following Python implementation into REXX, maintaining the same output and logic.
import logging, logging.handlers LOG_FILENAME = "logdemo.log" FORMAT_STRING = "%(levelname)s:%(asctime)s:%(name)s:%(funcName)s:line-%(lineno)d: %(message)s" LOGLEVEL = logging.DEBUG def print_squares(number): logger.info("In print_squares") for i in range(number): print("square of {0} is {1}".format(...
trace i parse arg maxDiv . if maxDiv=='' | maxDiv=="," then maxDiv= 1000 say 'maximum random divisor is:' maxDiv total= 0 do j=1 to 100 total= total + j/random(maxDiv) end say 'total=' total
Write a version of this Python function in REXX with identical behavior.
states = { 'ready':{ 'prompt' : 'Machine ready: (d)eposit, or (q)uit?', 'responses' : ['d','q']}, 'waiting':{ 'prompt' : 'Machine waiting: (s)elect, or (r)efund?', 'responses' : ['s','r']}, 'dispense' : { 'prompt'...
10: say "Press D (deposit) or Q (quit)" 20: $=inkey(); upper $ if $=="D" then signal 50 if $=="Q" then exit signal 20 50: say "Press S (select) or R (refund)" 60: $=inkey(); ...
Convert this Python snippet to REXX and keep its semantics consistent.
from sympy import divisors from sympy.combinatorics.subsets import Subset def isZumkeller(n): d = divisors(n) s = sum(d) if not s % 2 and max(d) <= s/2: for x in range(1, 2**len(d)): if sum(Subset.unrank_binary(x, d).subset) == s/2: return True return False def ...
parse arg n m v . if n=='' | n=="," then n= 220 if m=='' | m=="," then m= 40 if v=='' | v=="," then v= 40 @zum= ' Zumkeller numbers are: ' sw= linesize() - 1 say if n>0 then sa...
Produce a functionally identical REXX code for the snippet given in Python.
import re as RegEx def Commatize( _string, _startPos=0, _periodLen=3, _separator="," ): outString = "" strPos = 0 matches = RegEx.findall( "[0-9]*", _string ) for match in matches[:-1]: if not match: outString += _string[ strPos ] strPos += 1 else: if len(match) > _periodLen: leadIn = match[:_st...
@. = @.1= "pi=3.14159265358979323846264338327950288419716939937510582097494459231" @.2= "The author has two Z$100000000000000 Zimbabwe notes (100 trillion)." @.3= "-in Aus$+1411.8millions" @.4= "===US$0017440 millions=== (in 2000 dollars)" @.5= "123.e8000 is pretty big." @.6= "The land area of the earth is 57268900(2...
Translate the given Python code snippet into REXX without altering its behavior.
from math import floor, sqrt from datetime import datetime def main(): start = datetime.now() for i in xrange(1, 10 ** 11): if rare(i): print "found a rare:", i end = datetime.now() print "time elapsed:", end - start def is_square(n): s = floor(sqrt(n + 0.5)) return s * s == n def reverse(n): return ...
numeric digits 20; w= digits() + digits() % 3 parse arg many . if many=='' | many=="," then many= 5 @g= 2002 2112 2222 2332 2442 2552 2662 2772 2882 2992 4000 4010 4030 4050 4070 4090 4100 , 4110 4120 4140 4160 4180 4210 4230 4250 4270 4290 4300 4320 4340 4360 4380...
Convert the following code from Python to REXX, ensuring the logic remains intact.
class Parent(object): __priv = 'private' def __init__(self, name): self.name = name def __repr__(self): return '%s(%s)' % (type(self).__name__, self.name) def doNothing(self): pass import re class Child(Parent): __rePrivate = re.compile('^_(Child|Parent)...
d.1='' d.2='a23' d.3='101' d.4='123' d.5='12345678901234567890' d.6='abc' d.7='aBc' d.8='1' d.9='0' d.10='Walter' d.11='ABC' d.12='f23' d.13='123' t.1='A' t.2='B' t.3='I' t.4='L' t.5='M' t.6='N' t.7='O' t.8='S' t.9='U' t.10='V' t.11='W' t.12=...
Transform the following Python implementation into REXX, maintaining the same output and logic.
from __future__ import print_function class Node(object): def __init__(self): self.edges = {} self.link = None self.len = 0 class Eertree(object): def __init__(self): self.nodes = [] self.rto = Node() self.rte = Node() self.rto.link = self.rte.link = self.rto; self.rto.len = -1 self.r...
parse arg x . if x=='' | x=="," then x= 'eertree' L= length(x) @.= . $= do j=1 for L do k=1 for ...
Transform the following Python implementation into REXX, maintaining the same output and logic.
from __future__ import print_function class Node(object): def __init__(self): self.edges = {} self.link = None self.len = 0 class Eertree(object): def __init__(self): self.nodes = [] self.rto = Node() self.rte = Node() self.rto.link = self.rte.link = self.rto; self.rto.len = -1 self.r...
parse arg x . if x=='' | x=="," then x= 'eertree' L= length(x) @.= . $= do j=1 for L do k=1 for ...
Convert this Python block to REXX, preserving its control flow and logic.
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" def convertToBase58(num): sb = '' while (num > 0): r = num % 58 sb = sb + ALPHABET[r] num = num // 58; return sb[::-1] s = 25420294593250030202636073700053352635053786165627414518 b = convertToBase58(s) print("...
s="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" Numeric Digits 100 k='00010966776006953D5567439E5E39F86A0D273BEED61967F6'x n=c2d(k) o='' Do Until n=0 rem=n//58 n=n%58 o=o||substr(s,rem+1,1) End o=o||substr(s,1,1) Say reverse(o)
Ensure the translated REXX code behaves exactly like the original Python snippet.
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" def convertToBase58(num): sb = '' while (num > 0): r = num % 58 sb = sb + ALPHABET[r] num = num // 58; return sb[::-1] s = 25420294593250030202636073700053352635053786165627414518 b = convertToBase58(s) print("...
s="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" Numeric Digits 100 k='00010966776006953D5567439E5E39F86A0D273BEED61967F6'x n=c2d(k) o='' Do Until n=0 rem=n//58 n=n%58 o=o||substr(s,rem+1,1) End o=o||substr(s,1,1) Say reverse(o)
Rewrite the snippet below in REXX so it works the same as the original Python code.
import random, sys def makerule(data, context): rule = {} words = data.split(' ') index = context for word in words[index:]: key = ' '.join(words[index-context:index]) if key in rule: rule[key].append(word) else: rule[key] = [word] index...
parse arg ord fin iFID seed . if ord=='' | ord=="," then ord= 3 if fin=='' | fin=="," then fin= 300 if iFID=='' |iFID=="," then iFID='alice_oz.txt' if datatype(seed, 'W') then call random ,,seed sw = linesize() - 1 $= space( linein(iF...
Write a version of this Python function in REXX with identical behavior.
from string import ascii_uppercase from itertools import product from re import findall def uniq(seq): seen = {} return [seen.setdefault(x, x) for x in seq if x not in seen] def partition(seq, n): return [seq[i : i + n] for i in xrange(0, len(seq), n)] def playfair(key, from_ = 'J', to = None): if ...
options replace format comments java crossref symbols nobinary -- input arguments: -- encipher/decipher IQ-switch key text -- encipher/decipher - -- a character E, D (default E; . is an alias for E) -- IQ-switch - -- a character I, Q (default I for I==J, Q for exclude Q; . is an alias for I) -- ...
Translate the given Python code snippet into REXX without altering its behavior.
from string import ascii_uppercase from itertools import product from re import findall def uniq(seq): seen = {} return [seen.setdefault(x, x) for x in seq if x not in seen] def partition(seq, n): return [seq[i : i + n] for i in xrange(0, len(seq), n)] def playfair(key, from_ = 'J', to = None): if ...
options replace format comments java crossref symbols nobinary -- input arguments: -- encipher/decipher IQ-switch key text -- encipher/decipher - -- a character E, D (default E; . is an alias for E) -- IQ-switch - -- a character I, Q (default I for I==J, Q for exclude Q; . is an alias for I) -- ...
Convert this Python block to REXX, preserving its control flow and logic.
from itertools import (chain) def stringParse(lexicon): return lambda s: Node(s)( tokenTrees(lexicon)(s) ) def tokenTrees(wds): def go(s): return [Node(s)([])] if s in wds else ( concatMap(nxt(s))(wds) ) def nxt(s): return lambda w: parse( ...
parse arg a '/' x; a=space(a); x=space(x) if a=='' | a=="," then a= 'abcd abbc abcbcd acdbc abcdd' if x=='' | x=="," then x= 'a bc abc cd b' na= words(a) nx= words(x) say nx ' dictionary words: ' x a...
Change the following Python code into REXX without altering its purpose.
hex2bin = dict('{:x} {:04b}'.format(x,x).split() for x in range(16)) bin2hex = dict('{:b} {:x}'.format(x,x).split() for x in range(16)) def float_dec2bin(d): neg = False if d < 0: d = -d neg = True hx = float(d).hex() p = hx.index('p') bn = ''.join(hex2bin.get(char, char) for char i...
parse arg number toBase inBase digits . if toBase=='' | toBase=="," then toBase= 10 if inBase=='' | inBase=="," then inBase= 10 if digits=='' | digits=="," then digits= 60 if number=='' | number=="," then call err "no number specified." if \datatype(toBase, 'W') then call err "invalid...
Translate this program into REXX but keep the logic exactly as in Python.
hex2bin = dict('{:x} {:04b}'.format(x,x).split() for x in range(16)) bin2hex = dict('{:b} {:x}'.format(x,x).split() for x in range(16)) def float_dec2bin(d): neg = False if d < 0: d = -d neg = True hx = float(d).hex() p = hx.index('p') bn = ''.join(hex2bin.get(char, char) for char i...
parse arg number toBase inBase digits . if toBase=='' | toBase=="," then toBase= 10 if inBase=='' | inBase=="," then inBase= 10 if digits=='' | digits=="," then digits= 60 if number=='' | number=="," then call err "no number specified." if \datatype(toBase, 'W') then call err "invalid...
Transform the following Python implementation into REXX, maintaining the same output and logic.
import math import random INFINITY = 1 << 127 MAX_INT = 1 << 31 class Parameters: def __init__(self, omega, phip, phig): self.omega = omega self.phip = phip self.phig = phig class State: def __init__(self, iter, gbpos, gbval, min, max, parameters, pos, vel, bpos, bval, nParticles, nDi...
* Test for McCormick function *--------------------------------------------------------------------*/ Numeric Digits 16 Parse Value '-.5 -1.5 1' With x y d fmin=1e9 Call refine x,y Do r=1 To 10 d=d/5 Call refine xmin,ymin End Say 'which is better (less) than' Say ' f(-.54719,-1.54719)='f(-.54719,-1.54719)...
Produce a language-to-language conversion: from Python to REXX, same semantics.
from itertools import islice def posd(): "diff between position numbers. 1, 2, 3... interleaved with 3, 5, 7..." count, odd = 1, 3 while True: yield count yield odd count, odd = count + 1, odd + 2 def pos_gen(): "position numbers. 1 3 2 5 7 4 9 ..." val = 1 diff = posd...
numeric digits 1000 parse arg lo hi . if lo=='' | lo=="," then lo= 0 if hi=='' | hi=="," then hi= lo @.= 0; @.0= 1; @.1= 1; @.2= 2; @.3= 3; @.4= 5 !.= @.; !.1= 1; !.3= 1; !.5= 1; !.7= 1; !.9= 1 w= length( commas(h...
Rewrite the snippet below in REXX so it works the same as the original Python code.
def reverse(n): u = 0 while n: u = 10 * u + n % 10 n = int(n / 10) return u c = 0 for n in range(1, 200): u = reverse(n) s = True for d in range (1, n): if n % d == 0: b = reverse(d) if u % b != 0: s = False if s: ...
parse arg hi cols . if hi=='' | hi=="," then hi= 200 if cols=='' | cols=="," then cols= 10 w= 10 title= ' special divisors N that reverse(D) divides reverse(N) for all divisors' , ' D of N, where N <...
Can you help me rewrite this code in REXX instead of Python, keeping it the same logically?
def hpo2(n): return n & (-n) def lhpo2(n): q = 0 m = hpo2(n) while m%2 == 0: m = m >> 1 q += 1 return q def nimsum(x,y): return x ^ y def nimprod(x,y): if x < 2 or y < 2: return x * y h = hpo2(x) if x > h: return nimprod(h, y) ^ nimprod(x^h, y) if hp...
numeric digits 40; d= digits() % 8 parse arg sz aa bb . if sz=='' | sz=="," then sz= 15 if aa=='' | aa=="," then aa= 21508 if bb=='' | bb=="," then bb= 42689 w= max(4,length(sz)); @.= '+'; @.1= "*"; _= '═' != 'β•‘';...
Translate this program into REXX but keep the logic exactly as in Python.
from __future__ import print_function from __future__ import division def extended_synthetic_division(dividend, divisor): out = list(dividend) normalizer = divisor[0] for i in xrange(len(dividend)-(len(divisor)-1)): out[i] /= normalizer coef...
call set_dd '1 0 0 0 -1' Call set_dr '1 1 1 1' Call set_dd '1 -12 0 -42' Call set_dr '1 -3' q.0=0 Say list_dd '/' list_dr do While dd.0>=dr.0 q=dd.1/dr.1 Do j=1 To dr.0 dd.j=dd.j-q*dr.j End Call set_q q Call shift_dd End say 'Quotient:' mk_list_q() 'Remainder:' mk_list_dd() Exit set_dd: Parse Arg l...
Ensure the translated REXX code behaves exactly like the original Python snippet.
from __future__ import print_function from __future__ import division def extended_synthetic_division(dividend, divisor): out = list(dividend) normalizer = divisor[0] for i in xrange(len(dividend)-(len(divisor)-1)): out[i] /= normalizer coef...
call set_dd '1 0 0 0 -1' Call set_dr '1 1 1 1' Call set_dd '1 -12 0 -42' Call set_dr '1 -3' q.0=0 Say list_dd '/' list_dr do While dd.0>=dr.0 q=dd.1/dr.1 Do j=1 To dr.0 dd.j=dd.j-q*dr.j End Call set_q q Call shift_dd End say 'Quotient:' mk_list_q() 'Remainder:' mk_list_dd() Exit set_dd: Parse Arg l...
Maintain the same structure and functionality when rewriting this code in REXX.
import random TRAINING_LENGTH = 2000 class Perceptron: def __init__(self,n): self.c = .01 self.weights = [random.uniform(-1.0, 1.0) for _ in range(n)] def feed_forward(self, inputs): weighted_inputs = [] for i in range(len(inputs)): weighted_inputs.append(inpu...
Call init Call time 'R' try=0 Call show 0 Do d=1 To dots x=x.d y=y.d Parse Value x y 1 with inputs.0 inputs.1 inputs.2 answer.d=sign(y-f(x)) Select When f(x)<y Then r='<' When f(x)>y Then r='>' Otherwise r='=' End training.d=x y 1 answer.d End Do try=1 To tries Call time 'R' zz...
Produce a language-to-language conversion: from Python to REXX, same semantics.
from __future__ import print_function import os import hashlib import datetime def FindDuplicateFiles(pth, minSize = 0, hashName = "md5"): knownFiles = {} for root, dirs, files in os.walk(pth): for fina in files: fullFina = os.path.join(root, fina) isSymLink = os.path.isli...
sep=center(' files are identical in size and content: ',79,"═") tFID= 'c:\TEMP\FINDDUP.TMP' arg maxSize aDir if maxSize='' | maxSize="," then maxSize=1000000 aDir=strip(aDir) if right(aDir,1)\=='\' then aDir=aDir"\" "...
Convert this Python snippet to REXX and keep its semantics consistent.
from __future__ import annotations import functools import gzip import json import logging import platform import re from collections import Counter from collections import defaultdict from typing import Any from typing import Iterator from typing import Iterable from typing import List from typing import Mapping ...
parse arg iFID . if iFID=='' | iFID="," then iFID= 'BARELANG.HTM' call lineout iFID call linein ifid,1,0 noLa= 0; bare= 0; header=; heads= !.= 0 do re...
Produce a functionally identical REXX code for the snippet given in Python.
from itertools import count from pprint import pformat import re import heapq def pal_part_gen(odd=True): for i in count(1): fwd = str(i) rev = fwd[::-1][1:] if odd else fwd[::-1] yield int(fwd + rev) def pal_ordered_gen(): yield from heapq.merge(pal_part_gen(odd=True), pal_part_gen(o...
numeric digits 20 parse arg palGaps if palGaps='' then palGaps= 20 100@@15 1000@@10 do until palGaps=''; parse var palGaps stuff palGaps; call palGap stuff end exit 0 palGap: pr...
Write a version of this Python function in REXX with identical behavior.
from itertools import count from pprint import pformat import re import heapq def pal_part_gen(odd=True): for i in count(1): fwd = str(i) rev = fwd[::-1][1:] if odd else fwd[::-1] yield int(fwd + rev) def pal_ordered_gen(): yield from heapq.merge(pal_part_gen(odd=True), pal_part_gen(o...
numeric digits 20 parse arg palGaps if palGaps='' then palGaps= 20 100@@15 1000@@10 do until palGaps=''; parse var palGaps stuff palGaps; call palGap stuff end exit 0 palGap: pr...
Write the same algorithm in REXX as shown in this Python implementation.
from numpy import log def sieve_of_Sundaram(nth, print_all=True): assert nth > 0, "nth must be a positive integer" k = int((2.4 * nth * log(nth)) // 2) integers_list = [True] * k for i in range(1, k): j = i while i + j + 2 * i * j < k: integers_list[i + j + 2 * i * j]...
parse arg n cols . if n=='' | n=="," then n= 100 if cols=='' | cols=="," then cols= 10 @.= .; lim= 16 * n do j=1 for n; do k=1 for n until _>lim; _= j + k + 2*j*k; @._= end ...
Maintain the same structure and functionality when rewriting this code in REXX.
from sympy import sieve primelist = list(sieve.primerange(2,1000000)) listlen = len(primelist) pindex = 1 old_diff = -1 curr_list=[primelist[0]] longest_list=[] while pindex < listlen: diff = primelist[pindex] - primelist[pindex-1] if diff > old_diff: curr_list.append(primelist[pindex]) i...
parse arg hi cols . if hi=='' | hi=="," then hi= 1000000 if cols=='' | cols=="," then cols= 10 call genP w= 10 call fRun 1; call show 1 call fRun 0; call...
Translate the given Python code snippet into REXX without altering its behavior.
def pad_like(max_n=8, t=15): start = [[], [1, 1, 1]] for n in range(2, max_n+1): this = start[n-1][:n+1] while len(this) < t: this.append(sum(this[i] for i in range(-2, -n - 2, -1))) start.append(this) return start[2:] def pr(p): print(.strip()) fo...
parse arg n m . if n=='' | n=="," then n= 15 if m=='' | m=="," then m= 8 w.= 1 do #=2 for m-1 @.= 0; @.0= 1; @.1= 1; @.2= 1 $= @.0 ...
Convert the following code from Python to REXX, ensuring the logic remains intact.
from itertools import count, islice from _pydecimal import getcontext, Decimal def metallic_ratio(b): m, n = 1, 1 while True: yield m, n m, n = m*b + n, m def stable(b, prec): def to_decimal(b): for m,n in metallic_ratio(b): yield Decimal(m)/Decimal(n) getcontext()...
parse arg n bLO bHI digs . if n=='' | n=="," then n= 15 if bLO=='' | bLO=="," then bLO= 0 if bHI=='' | bHI=="," then bHI= 9 if digs=='' | digs=="," then digs= 32 numeric digits digs + length(.) metals= 'platinum ...
Port the provided Python code into REXX while preserving the original functionality.
from itertools import count, islice from _pydecimal import getcontext, Decimal def metallic_ratio(b): m, n = 1, 1 while True: yield m, n m, n = m*b + n, m def stable(b, prec): def to_decimal(b): for m,n in metallic_ratio(b): yield Decimal(m)/Decimal(n) getcontext()...
parse arg n bLO bHI digs . if n=='' | n=="," then n= 15 if bLO=='' | bLO=="," then bLO= 0 if bHI=='' | bHI=="," then bHI= 9 if digs=='' | digs=="," then digs= 32 numeric digits digs + length(.) metals= 'platinum ...
Please provide an equivalent version of this Python code in REXX.
import os,sys,zlib,urllib.request def h ( str,x=9 ): for c in str : x = ( x*33 + ord( c )) & 0xffffffffff return x def cache ( func,*param ): n = 'cache_%x.bin'%abs( h( repr( param ))) try : return eval( zlib.decompress( open( n,'rb' ).read())) except : pass s = func( *param ) ...
lower: procedure; parse arg a; @= 'abcdefghijklmnopqrstuvwxyz'; @u= @; upper @u return translate(a, @, @u)
Rewrite the snippet below in REXX so it works the same as the original Python code.
from random import shuffle, choice from itertools import product, accumulate from numpy import floor, sqrt class ADFGVX: def __init__(self, spoly, k, alph='ADFGVX'): self.polybius = list(spoly.upper()) self.pdim = int(floor(sqrt(len(self.polybius)))) self.key = list(k.upper()) ...
cls eol=x2c(0D0A) ; msg="ATTACKAT1200AM" keyword= upper('lifeguard') ; cyph= 'ADFGVX' s_sort= keyword ; new_key= '' do while length(s_sort) > 0 nmax= 0 do i=1 to length(s_sort) ch= substr(s_sort,i,1) num= c2d(ch) if num > nmax then do nmax= num ...
Convert this Python block to REXX, preserving its control flow and logic.
from random import shuffle, choice from itertools import product, accumulate from numpy import floor, sqrt class ADFGVX: def __init__(self, spoly, k, alph='ADFGVX'): self.polybius = list(spoly.upper()) self.pdim = int(floor(sqrt(len(self.polybius)))) self.key = list(k.upper()) ...
cls eol=x2c(0D0A) ; msg="ATTACKAT1200AM" keyword= upper('lifeguard') ; cyph= 'ADFGVX' s_sort= keyword ; new_key= '' do while length(s_sort) > 0 nmax= 0 do i=1 to length(s_sort) ch= substr(s_sort,i,1) num= c2d(ch) if num > nmax then do nmax= num ...
Generate a REXX translation of this Python snippet without changing its computational steps.
Plataanstraat 5 split as (Plataanstraat, 5) Straat 12 split as (Straat, 12) Straat 12 II split as (Straat, 12 II) Dr. J. Straat 12 split as (Dr. J. Straat , 12) Dr. J. Straat 12 a split as (Dr. J. Straat, 12 a) Dr. J. Straat 12-14 split as (Dr. J. Straat, 12...
!= 'β”‚' $= "Plataanstraat 5" ! , "Straat 12" ! , "Straat 12 II" ! , "Dr. J. Straat 12" ! , "Dr. J. Straat 12 a" ! , "Dr. J. Straat 12-14" ! , ...
Write a version of this Python function in REXX with identical behavior.
import sys if len(sys.argv)!=2: print("UsageΒ : python " + sys.argv[0] + " <whole number>") exit() numLimit = int(sys.argv[1]) resultSet = {} base = 1 while len(resultSet)!=numLimit: result = base**base for i in range(0,numLimit): if str(i) in str(result) and i not in resultSet: ...
numeric digits 200 parse arg hi cols . if hi=='' | hi=="," then hi= 51 if cols=='' | cols=="," then cols= 10 w= 6 title=' smallest positive integer K where K**K contains N, 0 ...
Convert the following code from Python to REXX, ensuring the logic remains intact.
from datetime import date from calendar import isleap def weekday(d): days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] dooms = [ [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5], [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] ] c = d.year // 100 r = d...
parse arg $ if $='' | $="," then $= , '01/06/1800 03/29/1875 12/07/1915 12/23/1970 05/14/2043 04/02/2077 04/02/2101' d= 'Sun Mon Tues Wednes Thurs Fri Satur' y.0= 3 7 7 4 2 6 4 1 5 3 7 5 y.1= 4 1 7 4 2 6 4 1 5 3 7 5...
Convert the following code from Python to REXX, ensuring the logic remains intact.
from datetime import date from calendar import isleap def weekday(d): days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"] dooms = [ [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5], [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] ] c = d.year // 100 r = d...
parse arg $ if $='' | $="," then $= , '01/06/1800 03/29/1875 12/07/1915 12/23/1970 05/14/2043 04/02/2077 04/02/2101' d= 'Sun Mon Tues Wednes Thurs Fri Satur' y.0= 3 7 7 4 2 6 4 1 5 3 7 5 y.1= 4 1 7 4 2 6 4 1 5 3 7 5...
Rewrite the snippet below in REXX so it works the same as the original Python code.
import numpy as np from numpy.linalg import inv a = np.array([[1., 2., 3.], [4., 1., 6.],[ 7., 8., 9.]]) ainv = inv(a) print(a) print(ainv)
Parse Arg seed nn If seed='' Then seed=23345 If nn='' Then nn=5 If seed='?' Then Do Say 'rexx gjmi seed n computes a random matrix with n rows and columns' Say 'Default is 23345 5' Exit End Numeric Digits 50 Call random 1,2,seed a='' Do i=1 To nn**2 a=a random(9)+1 End n2=words(a) Do n=2 To n2/2 If n**...
Convert this Python block to REXX, preserving its control flow and logic.
import numpy as np from numpy.linalg import inv a = np.array([[1., 2., 3.], [4., 1., 6.],[ 7., 8., 9.]]) ainv = inv(a) print(a) print(ainv)
Parse Arg seed nn If seed='' Then seed=23345 If nn='' Then nn=5 If seed='?' Then Do Say 'rexx gjmi seed n computes a random matrix with n rows and columns' Say 'Default is 23345 5' Exit End Numeric Digits 50 Call random 1,2,seed a='' Do i=1 To nn**2 a=a random(9)+1 End n2=words(a) Do n=2 To n2/2 If n**...
Convert this Python block to REXX, preserving its control flow and logic.
import math import collections triple = collections.namedtuple('triple', 'm fm simp') def _quad_simpsons_mem(f: callable, a: float , fa: float, b: float, fb: float)->tuple: m = a + (b - a) / 2 fm = f(m) simp = abs(b - a) / 6 * (fa + 4*fm + fb) return triple(m, fm, simp,) def _quad_asr(f: ca...
numeric digits length( pi() ) - length(.) a= 0; b= 1; f= 'SIN' sinx= quadAsr('SIN',a,b,"1e" || (-digits() + 1) ) say "Simpson's integration of sine from " a ' to ' b ' = ' sinx exit pi: pi= 3.1415926535897...
Convert this Python block to REXX, preserving its control flow and logic.
import math import collections triple = collections.namedtuple('triple', 'm fm simp') def _quad_simpsons_mem(f: callable, a: float , fa: float, b: float, fb: float)->tuple: m = a + (b - a) / 2 fm = f(m) simp = abs(b - a) / 6 * (fa + 4*fm + fb) return triple(m, fm, simp,) def _quad_asr(f: ca...
numeric digits length( pi() ) - length(.) a= 0; b= 1; f= 'SIN' sinx= quadAsr('SIN',a,b,"1e" || (-digits() + 1) ) say "Simpson's integration of sine from " a ' to ' b ' = ' sinx exit pi: pi= 3.1415926535897...
Generate an equivalent REXX version of this Python code.
import random board = [[" " for x in range(8)] for y in range(8)] piece_list = ["R", "N", "B", "Q", "P"] def place_kings(brd): while True: rank_white, file_white, rank_black, file_black = random.randint(0,7), random.randint(0,7), random.randint(0,7), random.randint(0,7) diff_list = [abs(rank_white - rank_black)...
parse arg seed CBs . if datatype(seed,'W') then call random ,,seed if CBs=='' | CBs=="," then CBs=1 do boards=1 for abs(CBs) if sign(CBs)\==CBs then do; say; say center(' board' board...
Produce a language-to-language conversion: from Python to REXX, same semantics.
from math import prod def superFactorial(n): return prod([prod(range(1,i+1)) for i in range(1,n+1)]) def hyperFactorial(n): return prod([i**i for i in range(1,n+1)]) def alternatingFactorial(n): return sum([(-1)**(n-i)*prod(range(1,i+1)) for i in range(1,n+1)]) def exponentialFactorial(n): if n in...
numeric digits 1000 call hdr 'super'; do j=0 to 9; $= $ sf(j); end; call tell call hdr 'hyper'; do j=0 to 9; $= $ hf(j); end; call tell call hdr 'alternating '; do j=0 to 9; $= $ af(j); end; call tell call hdr 'exp...
Translate this program into REXX but keep the logic exactly as in Python.
from numpy import Inf class MaxTropical: def __init__(self, x=0): self.x = x def __str__(self): return str(self.x) def __add__(self, other): return MaxTropical(max(self.x, other.x)) def __mul__(self, other): return MaxTropical(self.x + other.x) def __pow__(s...
call negInf; @x= '(x)'; @a= '(+)'; @h= '(^)'; @e= 'expression'; @c= 'comparison' numeric digits 1000 x= 2 ; y= -2 ; say is(@x) LS(x) RS(y) $Mul(x,y) x= -0.001 ; y= nInf ; say is(@a) LS(x) RS(y) $Add(x,y) ...
Keep all operations the same but rewrite the snippet in REXX.
from itertools import permutations numList = [2,3,1] baseList = [] for i in numList: for j in range(0,i): baseList.append(i) stringDict = {'A':2,'B':3,'C':1} baseString="" for i in stringDict: for j in range(0,stringDict[i]): baseString+=i print("Permutations for " + str(baseList) + "Β :...
parse arg g if g='' | g="," then g= 2 3 1 #= words(g) @= left('ABCDEFGHIJKLMNOPQRSTUVWXYZ', #) LO= HI= do i=1 for #...
Produce a functionally identical REXX code for the snippet given in Python.
from sympy import isprime, lcm, factorint, primerange from functools import reduce def pisano1(m): "Simple definition" if m < 2: return 1 lastn, n = 0, 1 for i in range(m ** 2): lastn, n = n, (lastn + n) % m if lastn == 0 and n == 1: return i + 1 return 1 def p...
numeric digits 500 parse arg lim.1 lim.2 lim.3 . if lim.1=='' | lim.1=="," then lim.1= 15 - 1 if lim.2=='' | lim.2=="," then lim.2= 180 - 1 if lim.3=='' | lim.3=="," then lim.3= 180 call Fib do i=1 fo...
Port the following code from Python to REXX with equivalent syntax and logic.
from functools import reduce from operator import mul from decimal import * getcontext().prec = MAX_PREC def expand(num): suffixes = [ ('greatgross', 7, 12, 3), ('gross', 2, 12, 2), ('dozens', 3, 12, 1), ('pairs', 4, 2, 1), ('scores', 3, 20, 1), ('googols',...
numeric digits 2000 @.=; @.1= '2greatGRo 24Gros 288Doz 1,728pairs 172.8SCOre' @.2= '1,567 +1.567k 0.1567e-2m' @.3= '25.123kK 25.123m 2.5123e-00002G' @.4= '25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei' @.5= '-.25123e-34Vikki 2e-77gooGols' ...
Change the programming language of this snippet from Python to REXX without modifying what it does.
from functools import reduce from operator import mul from decimal import * getcontext().prec = MAX_PREC def expand(num): suffixes = [ ('greatgross', 7, 12, 3), ('gross', 2, 12, 2), ('dozens', 3, 12, 1), ('pairs', 4, 2, 1), ('scores', 3, 20, 1), ('googols',...
numeric digits 2000 @.=; @.1= '2greatGRo 24Gros 288Doz 1,728pairs 172.8SCOre' @.2= '1,567 +1.567k 0.1567e-2m' @.3= '25.123kK 25.123m 2.5123e-00002G' @.4= '25.123kiKI 25.123Mi 2.5123e-00002Gi +.25123E-7Ei' @.5= '-.25123e-34Vikki 2e-77gooGols' ...
Write the same code in REXX as shown below in Python.
print( "{:19.16f} {:19.16f}".format( minkowski(minkowski_inv(4.04145188432738056)), minkowski_inv(minkowski(4.04145188432738056)), ) )
numeric digits 40 say fmt( mink( 0.5 * (1+sqrt(5) ) ) ) fmt( 5/3 ) say fmt( minkI(-5/9) ) fmt( (sqrt(13) - 7) / 6) say fmt( mink( minkI(0.718281828) ) ) fmt( mink( minkI(.1213141516171819) ) ) exit 0 floor: proc...
Produce a functionally identical REXX code for the snippet given in Python.
import inflect def count_letters(word): count = 0 for letter in word: if letter != ',' and letter !='-' and letter !=' ': count += 1 return count def split_with_spaces(sentence): sentence_list = [] curr_word = "" for c in sentence: if...
@= 'Four is the number of letters in the first word of this sentence,' parse arg N M if N='' | N="," then N= 201 if M='' | M="," then M=1000 10000 100000 1000000 @abcU= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'...
Transform the following Python implementation into REXX, maintaining the same output and logic.
from mpmath import mp heegner = [19,43,67,163] mp.dps = 50 x = mp.exp(mp.pi*mp.sqrt(163)) print("calculated Ramanujan's constant: {}".format(x)) print("Heegner numbers yielding 'almost' integers:") for i in heegner: print(" for {}: {} ~ {} error: {}".format(str(i),mp.exp(mp.pi*mp.sqrt(i)),round(mp.exp(mp.pi*mp.sqrt...
d= min( length(pi()), length(e()) ) - length(.) parse arg digs sDigs . 1 . . $ if digs=='' | digs=="," then digs= d if sDigs=='' | sDigs=="," then sDigs= d % 2 if $='' | $="," then $= 19 43 67 163 digs= min( digs, d) sDigs= min(sDigs, d...
Convert this Python snippet to REXX and keep its semantics consistent.
from mpmath import mp heegner = [19,43,67,163] mp.dps = 50 x = mp.exp(mp.pi*mp.sqrt(163)) print("calculated Ramanujan's constant: {}".format(x)) print("Heegner numbers yielding 'almost' integers:") for i in heegner: print(" for {}: {} ~ {} error: {}".format(str(i),mp.exp(mp.pi*mp.sqrt(i)),round(mp.exp(mp.pi*mp.sqrt...
d= min( length(pi()), length(e()) ) - length(.) parse arg digs sDigs . 1 . . $ if digs=='' | digs=="," then digs= d if sDigs=='' | sDigs=="," then sDigs= d % 2 if $='' | $="," then $= 19 43 67 163 digs= min( digs, d) sDigs= min(sDigs, d...
Generate an equivalent REXX version of this Python code.
Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import __future__ >>> __future__.all_feature_names ['nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement', 'print_function', 'unicode_literals'...
options wordlist;
Ensure the translated REXX code behaves exactly like the original Python snippet.
try: from functools import reduce except: pass def topx(data, tops=None): 'Extract the set of top-level(s) in topological order' for k, v in data.items(): v.discard(k) if tops is None: tops = toplevels(data) return _topx(data, tops, [], set()) def _topx(data, tops, _sofar, _sofar...
parse arg job jobL.=; stage.=; #.=0; @.=; JL= tree.=; tree.1= ' top1 des1 ip1 ip2 ' tree.2= ' top2 des1 ip2 ip3 ' tree.3= ...