Instruction stringlengths 45 106 | input_code stringlengths 1 13.7k | output_code stringlengths 1 13.7k |
|---|---|---|
Write the same code in REXX as shown below in Python. | from itertools import product
xx = '-5 +5'.split()
pp = '2 3'.split()
texts = '-x**p -(x)**p (-x)**p -(x**p)'.split()
print('Integer variable exponentiation')
for x, p in product(xx, pp):
print(f' x,p = {x:2},{p}; ', end=' ')
x, p = int(x), int(p)
print('; '.join(f"{t} =={eval(t):4}" for t in texts))
pr... |
_= 'β'; ! = 'β'; mJunct= 'ββ«β'; bJunct= 'ββ¨β'
say @(' x ', 5) @(" p ", 5) !
say @('value', 5) @("value", 5) copies(! @('expression',10) @("result",6)" ", 4)
say @('' , 5, _) @("", 5, _)copies(mJunct || @('', 10, _) @("", 6, _) , 4)
do x=-5 to 5 by 10 ... |
Write the same algorithm in REXX as shown in this Python implementation. | import sys
HIST = {}
def trace(frame, event, arg):
for name,val in frame.f_locals.items():
if name not in HIST:
HIST[name] = []
else:
if HIST[name][-1] is val:
continue
HIST[name].append(val)
return trace
def undo(name):
HIST[name].pop(-1)
... |
varSet!.=0
call varSet 'fluid',min(0,-5/2,-1) ; say 'fluid=' fluid
call varSet 'fluid',3.14159 ; say 'fluid=' fluid
call varSet 'fluid',' Santa Claus' ; say 'fluid=' fluid
call varSet 'fluid',,999
say 'There were' result "assignments (sets) for the FLU... |
Produce a functionally identical REXX code for the snippet given in Python. |
from random import choice
import regex as re
import time
def generate_sequence(n: int ) -> str:
return "".join([ choice(['A','C','G','T']) for _ in range(n) ])
def dna_findall(needle: str, haystack: str) -> None:
if sum(1 for _ in re.finditer(needle, haystack, overlapped=True)) == 0:
print("No mat... |
parse arg totLen rndLen basePr oWidth Bevery rndDNA seed .
if totLen=='' | totLen=="," then totLen= 200
if rndLen=='' | rndLen=="," then rndLen= 4
if basePr=='' | basePr=="," then basePr= 'acgt'
if oWidth=='' | oWidth=="," then oWidth= 100
if Bevery=='' | Bevery=="," then Bevery= 10
if rndDNA=... |
Change the following Python code into REXX without altering its purpose. |
import sys
if len(sys.argv)!=2:
print("UsageΒ : python " + sys.argv[0] + " <filename>")
exit()
dataFile = open(sys.argv[1],"r")
fileData = dataFile.read().split('\n')
dataFile.close()
[print(i) for i in fileData[::-1]]
|
parse arg iFID .
if iFID=='' | iFID=="," then iFID='REVERSEF.TXT'
call lineout iFID
do #=1 while lines(iFID)>0
@.#= linein(iFID)
end
recs= # - 1 ... |
Rewrite the snippet below in REXX so it works the same as the original Python code. | def multiply(x, y):
return x * y
|
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: "... |
Transform the following Python implementation into REXX, maintaining the same output and logic. |
from itertools import permutations
for i in range(0,10):
if i!=1:
baseList = [1,1]
baseList.append(i)
[print(int(''.join(map(str,j)))) for j in sorted(set(permutations(baseList)))]
|
parse arg hi cols .
if hi=='' | hi=="," then hi= 1000
if cols=='' | cols=="," then cols= 10
w= 10
title= ' positive decimal integers which contain exactly two ones (1s) which are <' hi
say ' index β'center(title, ... |
Generate a REXX translation of this Python snippet without changing its computational steps. | LIST = ["1a3c52debeffd", "2b6178c97a938stf", "3ycxdb1fgxa2yz"]
print(sorted([ch for ch in set([c for c in ''.join(LIST)]) if all(w.count(ch) == 1 for w in LIST)]))
|
parse arg $
if $='' | $="," then $= '1a3c52debeffd' "2b6178c97a938stf" '3ycxdb1fgxa2yz'
if $='' then do; say "***error*** no lists were specified."; exit 13; end
#= words($); $$=
do i=1 for #; !.i= word($, i)
... |
Keep all operations the same but rewrite the snippet in REXX. |
from sympy import Sieve
def nsuccprimes(count, mx):
"return tuple of <count> successive primes <= mx (generator)"
sieve = Sieve()
sieve.extend(mx)
primes = sieve._list
return zip(*(primes[n:] for n in range(count)))
def check_value_diffs(diffs, values):
"Differences between successive values ... |
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... |
Write the same code in REXX as shown below in Python. |
def digitSumsPrime(n):
def go(bases):
return all(
isPrime(digitSum(b)(n))
for b in bases
)
return go
def digitSum(base):
def go(n):
q, r = divmod(n, base)
return go(q) + r if n else 0
return go
def main():
xs = [
... |
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... |
Keep all operations the same but rewrite the snippet in REXX. |
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def prime(n: int) -> int:
if n == 1:
return 2
p = 3
pn = 1
while pn < n:
if isPrime(p):
pn += 1
p += 2
return p-2
if __name__ == '__... |
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')
|
Change the following Python code into REXX without altering its purpose. |
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
def prime(n: int) -> int:
if n == 1:
return 2
p = 3
pn = 1
while pn < n:
if isPrime(p):
pn += 1
p += 2
return p-2
if __name__ == '__... |
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')
|
Rewrite the snippet below in REXX so it works the same as the original Python code. |
from itertools import accumulate, chain, takewhile
def primeSums():
return (
x for x in enumerate(
accumulate(
chain([(0, 0)], primes()),
lambda a, p: (p, p + a[1])
)
) if isPrime(x[1][1])
)
def main():
for x in take... |
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 < ' ,
... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. |
from itertools import accumulate, chain, takewhile
def primeSums():
return (
x for x in enumerate(
accumulate(
chain([(0, 0)], primes()),
lambda a, p: (p, p + a[1])
)
) if isPrime(x[1][1])
)
def main():
for x in take... |
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 < ' ,
... |
Transform the following Python implementation into REXX, maintaining the same output and logic. | import os
def get_windows_terminal():
from ctypes import windll, create_string_buffer
h = windll.kernel32.GetStdHandle(-12)
csbi = create_string_buffer(22)
res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
if not res: return 80, 25
import struct
(bufx, bufy, curx, cury, watt... | 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 Python snippet. |
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
if __name__ == '__main__':
p = 3
i = 2
print("2 3", end = " ");
while True:
if isPrime(p + i) == 1:
p += i
print(p, end = " ");
i +... |
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(... |
Port the provided Python code into REXX while preserving the original functionality. |
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
if __name__ == '__main__':
p = 3
i = 2
print("2 3", end = " ");
while True:
if isPrime(p + i) == 1:
p += i
print(p, end = " ");
i +... |
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(... |
Keep all operations the same but rewrite the snippet in REXX. |
from itertools import (chain, permutations)
from functools import (reduce)
from math import (gcd)
def main():
digits = [1, 2, 3, 4, 6, 7, 8, 9]
lcmDigits = reduce(lcm, digits)
sevenDigits = ((delete)(digits)(x) for x in [1, 4, 7])
print(
max(
(
... |
$= 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 ... |
Write the same code in REXX as shown below in Python. |
from itertools import (chain, permutations)
from functools import (reduce)
from math import (gcd)
def main():
digits = [1, 2, 3, 4, 6, 7, 8, 9]
lcmDigits = reduce(lcm, digits)
sevenDigits = ((delete)(digits)(x) for x in [1, 4, 7])
print(
max(
(
... |
$= 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 ... |
Ensure the translated REXX code behaves exactly like the original Python snippet. | def jacobi(a, n):
if n <= 0:
raise ValueError("'n' must be a positive integer.")
if n % 2 == 0:
raise ValueError("'n' must be odd.")
a %= n
result = 1
while a != 0:
while a % 2 == 0:
a /= 2
n_mod_8 = n % 8
if n_mod_8 in (3, 5):
... |
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
... |
Translate the given Python code snippet into REXX without altering its behavior. | def jacobi(a, n):
if n <= 0:
raise ValueError("'n' must be a positive integer.")
if n % 2 == 0:
raise ValueError("'n' must be odd.")
a %= n
result = 1
while a != 0:
while a % 2 == 0:
a /= 2
n_mod_8 = n % 8
if n_mod_8 in (3, 5):
... |
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
... |
Can you help me rewrite this code in REXX instead of Python, keeping it the same logically? | from itertools import permutations
from operator import mul
from math import fsum
from spermutations import spermutations
def prod(lst):
return reduce(mul, lst, 1)
def perm(a):
n = len(a)
r = range(n)
s = permutations(r)
return fsum(prod(a[i][sigma[i]] for i in r) for sigma in s)
def det(a):
... |
* 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 Python. | from itertools import permutations
from operator import mul
from math import fsum
from spermutations import spermutations
def prod(lst):
return reduce(mul, lst, 1)
def perm(a):
n = len(a)
r = range(n)
s = permutations(r)
return fsum(prod(a[i][sigma[i]] for i in r) for sigma in s)
def det(a):
... |
* 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 a version of this Python function in REXX with identical behavior. | Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> x = [n for n in range(1000) if str(sum(int(d) for d in str(n))) in str(n)]
>>> len(x)
48
>>> for i in range(0, len(x), (stride:= 10)): print(str(x[i... |
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 code in REXX as shown below in Python. | Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> x = [n for n in range(1000) if str(sum(int(d) for d in str(n))) in str(n)]
>>> len(x)
48
>>> for i in range(0, len(x), (stride:= 10)): print(str(x[i... |
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 < ' ,
... |
Transform the following Python implementation into REXX, maintaining the same output and logic. | >>> from random import randrange
>>> def sattoloCycle(items):
for i in range(len(items) - 1, 0, -1):
j = randrange(i)
items[j], items[i] = items[i], items[j]
>>>
>>> for _ in range(10):
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
sattoloCycle(lst)
print(lst)
[5, 8, 1, 2, 6, 4, 3, 9, 10, 7]
[5, 9, 8, 10, 4, ... |
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
$=
... |
Generate a REXX translation of this Python snippet without changing its computational steps. | >>> from random import randrange
>>> def sattoloCycle(items):
for i in range(len(items) - 1, 0, -1):
j = randrange(i)
items[j], items[i] = items[i], items[j]
>>>
>>> for _ in range(10):
lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
sattoloCycle(lst)
print(lst)
[5, 8, 1, 2, 6, 4, 3, 9, 10, 7]
[5, 9, 8, 10, 4, ... |
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
$=
... |
Preserve the algorithm and functionality while converting the code from Python to REXX. | >>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> conn.execute()
<sqlite3.Cursor object at 0x013265C0>
>>>
|
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 ... |
Preserve the algorithm and functionality while converting the code from Python to REXX. | def cycleSort(vector):
"Sort a vector in place and return the number of writes."
writes = 0
for cycleStart, item in enumerate(vector):
pos = cycleStart
for item2 in vector[cycleStart + 1:]:
if item2 < item:
pos += 1
if pos == c... |
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 ... |
Preserve the algorithm and functionality while converting the code from Python to REXX. | def cycleSort(vector):
"Sort a vector in place and return the number of writes."
writes = 0
for cycleStart, item in enumerate(vector):
pos = cycleStart
for item2 in vector[cycleStart + 1:]:
if item2 < item:
pos += 1
if pos == c... |
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 ... |
Convert this Python block to REXX, preserving its control flow and logic. | primes = [2, 3, 5, 7, 11, 13, 17, 19]
def count_twin_primes(limit: int) -> int:
global primes
if limit > primes[-1]:
ram_limit = primes[-1] + 90000000 - len(primes)
reasonable_limit = min(limit, primes[-1] ** 2, ram_limit) - 1
while reasonable_limit < limit:
ram_limit = pr... |
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... |
Translate this program into REXX but keep the logic exactly as in Python. | >>> with open('/dev/tape', 'w') as t: t.write('Hi Tape!\n')
...
>>>
|
dsName = 'TAPE.FILE'
do j=1 for 100
call lineout dsName, 'this is record' j || "."
end
|
Keep all operations the same but rewrite the snippet in REXX. | from itertools import islice
class Recamans():
"RecamΓ‘n's sequence generator callable class"
def __init__(self):
self.a = None
self.n = None
def __call__(self):
"RecamΓ‘n's sequence generator"
nxt = 0
a, n = {nxt}, 0
self.a = a
self.n = n
... |
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: " ... |
Write the same code in REXX as shown below in Python. | from itertools import islice
class Recamans():
"RecamΓ‘n's sequence generator callable class"
def __init__(self):
self.a = None
self.n = None
def __call__(self):
"RecamΓ‘n's sequence generator"
nxt = 0
a, n = {nxt}, 0
self.a = a
self.n = n
... |
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 the snippet below in REXX so it works the same as the original Python code. | >>> Y = lambda f: (lambda x: x(x))(lambda y: f(lambda *args: y(y)(*args)))
>>> fac = lambda f: lambda n: (1 if n<2 else n*f(n-1))
>>> [ Y(fac)(i) for i in range(10) ]
[1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880]
>>> fib = lambda f: lambda n: 0 if n == 0 else (1 if n == 1 else f(n-1) + f(n-2))
>>> [ Y(fib)(i) for i i... |
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 ... |
Write the same algorithm in REXX as shown in this Python implementation. | from collections import namedtuple
Circle = namedtuple("Circle", "x y r")
circles = [
Circle( 1.6417233788, 1.6121789534, 0.0848270516),
Circle(-1.4944608174, 1.2077959613, 1.1039549836),
Circle( 0.6110294452, -0.6907087527, 0.9089162485),
Circle( 0.3844862411, 0.2923344616, 0.2375743054),
Circ... |
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... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | from collections import namedtuple
Circle = namedtuple("Circle", "x y r")
circles = [
Circle( 1.6417233788, 1.6121789534, 0.0848270516),
Circle(-1.4944608174, 1.2077959613, 1.1039549836),
Circle( 0.6110294452, -0.6907087527, 0.9089162485),
Circle( 0.3844862411, 0.2923344616, 0.2375743054),
Circ... |
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 Python snippet. | fact = [1]
for n in range(1, 12):
fact.append(fact[n-1] * n)
for b in range(9, 12+1):
print(f"The factorions for base {b} are:")
for i in range(1, 1500000):
fact_sum = 0
j = i
while j > 0:
d = j % b
fact_sum += fact[d]
j = j//b
if fact_su... |
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... |
Generate a REXX translation of this Python snippet without changing its computational steps. | fact = [1]
for n in range(1, 12):
fact.append(fact[n-1] * n)
for b in range(9, 12+1):
print(f"The factorions for base {b} are:")
for i in range(1, 1500000):
fact_sum = 0
j = i
while j > 0:
d = j % b
fact_sum += fact[d]
j = j//b
if fact_su... |
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... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | def factorize(n):
assert(isinstance(n, int))
if n < 0:
n = -n
if n < 2:
return
k = 0
while 0 == n%2:
k += 1
n //= 2
if 0 < k:
yield (2,k)
p = 3
while p*p <= n:
k = 0
while 0 == n%p:
k += 1
n //... |
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 Python code snippet into REXX without altering its behavior. | def factorize(n):
assert(isinstance(n, int))
if n < 0:
n = -n
if n < 2:
return
k = 0
while 0 == n%2:
k += 1
n //= 2
if 0 < k:
yield (2,k)
p = 3
while p*p <= n:
k = 0
while 0 == n%p:
k += 1
n //... |
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
$=; ... |
Change the following Python code into REXX without altering its purpose. | def _insort_right(a, x, q):
lo, hi = 0, len(a)
while lo < hi:
mid = (lo+hi)//2
q += 1
less = input(f"{q:2}: IS {x:>6} LESS-THAN {a[mid]:>6}Β ? y/n: ").strip().lower() == 'y'
if less: hi = mid
else: lo = mid+1
a.insert(lo, x)
return q
def order(items):
or... |
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... |
Maintain the same structure and functionality when rewriting this code in REXX. | def factors(x):
factors = []
i = 2
s = int(x ** 0.5)
while i < s:
if x % i == 0:
factors.append(i)
x = int(x / i)
s = int(x ** 0.5)
i += 1
factors.append(x)
return factors
print("First 10 Fermat numbers:")
for i in range(10):
fermat = 2 **... |
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
... |
Generate an equivalent REXX version of this Python code. |
from itertools import zip_longest
def beadsort(l):
return list(map(sum, zip_longest(*[[1] * e for e in l], fillvalue=0)))
print(beadsort([5,3,1,7,4,1,1]))
|
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... |
Transform the following Python implementation into REXX, maintaining the same output and logic. |
def CastOut(Base=10, Start=1, End=999999):
ran = [y for y in range(Base-1) if y%(Base-1) == (y*y)%(Base-1)]
x,y = divmod(Start, Base-1)
while True:
for n in ran:
k = (Base-1)*x + n
if k < Start:
continue
if k > End:
return
yield k
x += 1
for V in CastOut(Base=1... |
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... |
Translate this program into REXX but keep the logic exactly as in Python. |
import argparse
from argparse import Namespace
import datetime
import shlex
def parse_args():
'Set up, parse, and return arguments'
parser = argparse.ArgumentParser(epilog=globals()['__doc__'])
parser.add_argument('command', choices='add pl plc pa'.split(),
help=)
par... |
* 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... |
Translate this program into REXX but keep the logic exactly as in Python. |
import sys
print " ".join(sys.argv[1:])
| #!/usr/local/bin/regina
say arg(1)
|
Write a version of this Python function in REXX with identical behavior. |
import sys
print " ".join(sys.argv[1:])
| #!/usr/local/bin/regina
say arg(1)
|
Port the following code from Python to REXX with equivalent syntax and logic. | def factorize(n):
assert(isinstance(n, int))
if n < 0:
n = -n
if n < 2:
return
k = 0
while 0 == n%2:
k += 1
n //= 2
if 0 < k:
yield (2,k)
p = 3
while p*p <= n:
k = 0
while 0 == n%p:
k += 1
n //... |
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... |
Change the following Python code into REXX without altering its purpose. | def factorize(n):
assert(isinstance(n, int))
if n < 0:
n = -n
if n < 2:
return
k = 0
while 0 == n%2:
k += 1
n //= 2
if 0 < k:
yield (2,k)
p = 3
while p*p <= n:
k = 0
while 0 == n%p:
k += 1
n //... |
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... |
Write a version of this Python function in REXX with identical behavior. |
def isPrime(n) :
if (n < 2) :
return False
for i in range(2, n + 1) :
if (i * i <= n and n % i == 0) :
return False
return True
def mobius(N) :
if (N == 1) :
return 1
p = 0
for i in range(1, N + 1) :
if... |
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ΓΆ... |
Rewrite the snippet below in REXX so it works the same as the original Python code. |
def Gcd(v1, v2):
a, b = v1, v2
if (a < b):
a, b = v2, v1
r = 1
while (r != 0):
r = a % b
if (r != 0):
a = b
b = r
return b
a = [1, 2]
n = 3
while (n < 50):
gcd1 = Gcd(n, a[-1])
gcd2 = Gcd(n, a[-2])
if (gcd1 == 1 a... |
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 ... |
Translate the given Python code snippet into REXX without altering its behavior. |
def Gcd(v1, v2):
a, b = v1, v2
if (a < b):
a, b = v2, v1
r = 1
while (r != 0):
r = a % b
if (r != 0):
a = b
b = r
return b
a = [1, 2]
n = 3
while (n < 50):
gcd1 = Gcd(n, a[-1])
gcd2 = Gcd(n, a[-2])
if (gcd1 == 1 a... |
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 ... |
Produce a functionally identical REXX code for the snippet given in Python. | def mertens(count):
m = [None, 1]
for n in range(2, count+1):
m.append(1)
for k in range(2, n+1):
m[n] -= m[n//k]
return m
ms = mertens(1000)
print("The first 99 Mertens numbers are:")
print(" ", end=' ')
col = 1
for n in ms[1:100]:
print("{:2d}".format(n), end='... |
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 ... |
Port the following code from Python to REXX with equivalent syntax and logic. | def product_of_divisors(n):
assert(isinstance(n, int) and 0 < n)
ans = i = j = 1
while i*i <= n:
if 0 == n%i:
ans *= i
j = n//i
if j != i:
ans *= j
i += 1
return ans
if __name__ == "__main__":
print([product_of_divisors(n) for ... |
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(... |
Generate a REXX translation of this Python snippet without changing its computational steps. | def product_of_divisors(n):
assert(isinstance(n, int) and 0 < n)
ans = i = j = 1
while i*i <= n:
if 0 == n%i:
ans *= i
j = n//i
if j != i:
ans *= j
i += 1
return ans
if __name__ == "__main__":
print([product_of_divisors(n) for ... |
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(... |
Convert this Python snippet to REXX and keep its semantics consistent. | import random
class Card(object):
suits = ("Clubs","Hearts","Spades","Diamonds")
pips = ("2","3","4","5","6","7","8","9","10","Jack","Queen","King","Ace")
def __init__(self, pip,suit):
self.pip=pip
self.suit=suit
def __str__(self):
return "%s %s"%(self.pip,self.suit)
class De... |
* 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='... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. |
from math import gcd
def coprime(a, b):
return 1 == gcd(a, b)
def main():
print([
xy for xy in [
(21, 15), (17, 23), (36, 12),
(18, 29), (60, 15)
]
if coprime(*xy)
])
if __name__ == '__main__':
main()
|
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 Python. |
from math import gcd
def coprime(a, b):
return 1 == gcd(a, b)
def main():
print([
xy for xy in [
(21, 15), (17, 23), (36, 12),
(18, 29), (60, 15)
]
if coprime(*xy)
])
if __name__ == '__main__':
main()
|
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... |
Change the programming language of this snippet from Python to REXX without modifying what it does. | from math import gcd
from functools import lru_cache
from itertools import islice, count
@lru_cache(maxsize=None)
def Ο(n):
return sum(1 for k in range(1, n + 1) if gcd(n, k) == 1)
def perfect_totient():
for n0 in count(1):
parts, n = 0, n0
while n != 1:
n = Ο(n)
parts... |
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 Python to REXX with equivalent syntax and logic. | from math import gcd
from functools import lru_cache
from itertools import islice, count
@lru_cache(maxsize=None)
def Ο(n):
return sum(1 for k in range(1, n + 1) if gcd(n, k) == 1)
def perfect_totient():
for n0 in count(1):
parts, n = 0, n0
while n != 1:
n = Ο(n)
parts... |
parse arg N .
if N=='' | N=="," then N= 20
@.= .
p= 0
$=
do j=3 by 2 until p==N; s= phi(j)
a= s ... |
Can you help me rewrite this code in REXX instead of Python, keeping it the same logically? | from math import (comb,
factorial)
def lah(n, k):
if k == 1:
return factorial(n)
if k == n:
return 1
if k > n:
return 0
if k < 1 or n < 1:
return 0
return comb(n, k) * factorial(n - 1) // factorial(k - 1)
def main():
print("Unsigned Lah numbe... |
parse arg lim .
if lim=='' | lim=="," then lim= 12
olim= lim
lim= abs(lim)
numeric digits max(9, 4*lim)
max#.= 0
!.=.
@.=
... |
Translate the given Python code snippet into REXX without altering its behavior. | from math import (comb,
factorial)
def lah(n, k):
if k == 1:
return factorial(n)
if k == n:
return 1
if k > n:
return 0
if k < 1 or n < 1:
return 0
return comb(n, k) * factorial(n - 1) // factorial(k - 1)
def main():
print("Unsigned Lah numbe... |
parse arg lim .
if lim=='' | lim=="," then lim= 12
olim= lim
lim= abs(lim)
numeric digits max(9, 4*lim)
max#.= 0
!.=.
@.=
... |
Maintain the same structure and functionality when rewriting this code in REXX. | def two_sum(arr, num):
i = 0
j = len(arr) - 1
while i < j:
if arr[i] + arr[j] == num:
return (i, j)
if arr[i] + arr[j] < num:
i += 1
else:
j -= 1
return None
numbers = [0, 2, 11, 19, 90]
print(two_sum(numbers, 21))
print(two_sum(numbers, 25))... | 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'
|
Ensure the translated REXX code behaves exactly like the original Python snippet. | def two_sum(arr, num):
i = 0
j = len(arr) - 1
while i < j:
if arr[i] + arr[j] == num:
return (i, j)
if arr[i] + arr[j] < num:
i += 1
else:
j -= 1
return None
numbers = [0, 2, 11, 19, 90]
print(two_sum(numbers, 21))
print(two_sum(numbers, 25))... | 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'
|
Maintain the same structure and functionality when rewriting this code in REXX. |
def cocktailshiftingbounds(A):
beginIdx = 0
endIdx = len(A) - 1
while beginIdx <= endIdx:
newBeginIdx = endIdx
newEndIdx = beginIdx
for ii in range(beginIdx,endIdx):
if A[ii] > A[ii + 1]:
A[ii+1], A[ii] = A[ii], A[ii+1]
n... |
call gen
call show 'before sort'
say copies('β', 101)
call cocktailSort #
call show ' after sort'
exit
cocktailSort: proc... |
Port the following code from Python to REXX with equivalent syntax and logic. | from itertools import count, islice
def primes(_cache=[2, 3]):
yield from _cache
for n in count(_cache[-1]+2, 2):
if isprime(n):
_cache.append(n)
yield n
def isprime(n, _seen={0: False, 1: False}):
def _isprime(n):
for p in primes():
if p*p > n:
... |
parse arg n x hp .
if n=='' | n=="," then n= 35
if x=='' | x=="," then x= 600
if hp=='' | hp=="," then hp= 10000000
u= 0
eds=4; ed.1= 1; ed.2= 3; ed.3= 7; ed.4= 9
call genP hp ... |
Write a version of this Python function in REXX with identical behavior. | def tau(n):
assert(isinstance(n, int) and 0 < n)
ans, i, j = 0, 1, 1
while i*i <= n:
if 0 == n%i:
ans += 1
j = n//i
if j != i:
ans += 1
i += 1
return ans
def is_tau_number(n):
assert(isinstance(n, int))
if n <= 0:
retur... |
parse arg n cols .
if n=='' | n=="," then n= 100
if cols=='' | cols=="," then cols= 10
w= max(8, length(n) )
@tau= ' the first ' commas(n) " tau numbers "
say ' index β'center(@tau, 1 + cols*(w+1) )
say 'ββββββββΌ'cente... |
Ensure the translated REXX code behaves exactly like the original Python snippet. |
from itertools import takewhile
def primesWithGivenDigitSum(below, n):
return list(
takewhile(
lambda x: below > x,
(
x for x in primes()
if n == sum(int(c) for c in str(x))
)
)
)
def main():
matches = pri... |
parse arg hi cols target .
if hi=='' | hi=="," then hi= 5000
if cols=='' | cols=="," then cols= 10
if target=='' | target=="," then target= 25
call genP
w= 10
title= ' primes tha... |
Please provide an equivalent version of this Python code in REXX. |
from itertools import takewhile
def primesWithGivenDigitSum(below, n):
return list(
takewhile(
lambda x: below > x,
(
x for x in primes()
if n == sum(int(c) for c in str(x))
)
)
)
def main():
matches = pri... |
parse arg hi cols target .
if hi=='' | hi=="," then hi= 5000
if cols=='' | cols=="," then cols= 10
if target=='' | target=="," then target= 25
call genP
w= 10
title= ' primes tha... |
Port the following code from Python to REXX with equivalent syntax and logic. | from collections import deque
def prime_digits_sum(r):
q = deque([(r, 0)])
while q:
r, n = q.popleft()
for d in 2, 3, 5, 7:
if d >= r:
if d == r: yield n + d
break
q.append((r - d, (n + d) * 10))
print(*prime_digits_sum(13))
|
parse arg LO HI COLS .
if LO=='' | LO=="," then LO= 337
if HI=='' | HI=="," then HI= 322222
if cols=='' | cols=="," then cols= 10
w= 10
title= ' decimal numbers found whose digits are ... |
Please provide an equivalent version of this Python code in REXX. | from collections import deque
def prime_digits_sum(r):
q = deque([(r, 0)])
while q:
r, n = q.popleft()
for d in 2, 3, 5, 7:
if d >= r:
if d == r: yield n + d
break
q.append((r - d, (n + d) * 10))
print(*prime_digits_sum(13))
|
parse arg LO HI COLS .
if LO=='' | LO=="," then LO= 337
if HI=='' | HI=="," then HI= 322222
if cols=='' | cols=="," then cols= 10
w= 10
title= ' decimal numbers found whose digits are ... |
Convert the following code from Python to REXX, ensuring the logic remains intact. | 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 hp .
if N=='' | N=="," then N= 19
if hp=='' | hp=="," then hip= 1000000
call genP
q= 024568
found= 0; $=
do j=1 until... |
Transform the following Python implementation into REXX, maintaining the same output and logic. |
def isPrime(v):
if v <= 1:
return False
if v < 4:
return True
if v % 2 == 0:
return False
if v < 9:
return True
if v % 3 == 0:
return False
else:
r = round(pow(v,0.5))
f = 5
while f <= r:
if v % f == 0 or v % (f + 2) == 0:
return False
f += 6
return ... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 10000
if cols=='' | cols=="," then cols= 10
w= 10
call genP
title= ' Frobenius numbers that a... |
Keep all operations the same but rewrite the snippet in REXX. |
def isPrime(v):
if v <= 1:
return False
if v < 4:
return True
if v % 2 == 0:
return False
if v < 9:
return True
if v % 3 == 0:
return False
else:
r = round(pow(v,0.5))
f = 5
while f <= r:
if v % f == 0 or v % (f + 2) == 0:
return False
f += 6
return ... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 10000
if cols=='' | cols=="," then cols= 10
w= 10
call genP
title= ' Frobenius numbers that a... |
Please provide an equivalent version of this Python code in REXX. | from itertools import permutations
in_order = lambda s: all(x <= s[i+1] for i,x in enumerate(s[:-1]))
perm_sort = lambda s: (p for p in permutations(s) if in_order(p)).next()
|
options replace format comments java crossref symbols nobinary
import java.util.List
import java.util.ArrayList
numeric digits 20
class RSortingPermutationsort public
properties private static
iterations
maxIterations
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
met... |
Maintain the same structure and functionality when rewriting this code in REXX. | def root(a, b):
if b < 2:
return b
a1 = a - 1
c = 1
d = (a1 * c + b // (c ** a1)) // a
e = (a1 * d + b // (d ** a1)) // a
while c not in (d, e):
c, d, e = d, e, (a1 * e + b // (e ** a1)) // a
return min(d, e)
print("First 2,001 digits of the square root of two:\n{}".format(... |
parse arg num root digs .
if num=='' | num=="," then num= 2
if root=='' | root=="," then root= 2
if digs=='' | digs=="," then digs=2001
numeric digits digs
say 'number=' num
say ' root=' root... |
Port the following code from Python to REXX with equivalent syntax and logic. | def root(a, b):
if b < 2:
return b
a1 = a - 1
c = 1
d = (a1 * c + b // (c ** a1)) // a
e = (a1 * d + b // (d ** a1)) // a
while c not in (d, e):
c, d, e = d, e, (a1 * e + b // (e ** a1)) // a
return min(d, e)
print("First 2,001 digits of the square root of two:\n{}".format(... |
parse arg num root digs .
if num=='' | num=="," then num= 2
if root=='' | root=="," then root= 2
if digs=='' | digs=="," then digs=2001
numeric digits digs
say 'number=' num
say ' root=' root... |
Generate a REXX translation of this Python snippet without changing its computational steps. | from sympy.ntheory.generate import primorial
from sympy.ntheory import isprime
def fortunate_number(n):
i = 3
primorial_ = primorial(n)
while True:
if isprime(primorial_ + i):
return i
i += 2
fortunate_numbers = set()
for i in range(1, 76):
fortunate_numbers.... |
numeric digits 12
parse arg n cols .
if n=='' | n=="," then n= 8
if cols=='' | cols=="," then cols= 10
call genP n**2
pp.= 1
do i=1 for n+1; im= i - 1; pp.i= pp.im * @.i
end
i=i-1; call genp pp.... |
Port the following code from Python to REXX with equivalent syntax and logic. |
def meaning_of_life():
return 42
if __name__ == "__main__":
print("Main: The meaning of life is %s" % meaning_of_life())
|
parse source . howInvoked @fn
say 'This program ('@fn") was invoked as a: " howInvoked
if howInvoked\=='COMMAND' then do
say 'This program ('@fn") wasn't invoked via a command."
exit 12
end
... |
Port the provided Python code into REXX while preserving the original functionality. |
def meaning_of_life():
return 42
if __name__ == "__main__":
print("Main: The meaning of life is %s" % meaning_of_life())
|
parse source . howInvoked @fn
say 'This program ('@fn") was invoked as a: " howInvoked
if howInvoked\=='COMMAND' then do
say 'This program ('@fn") wasn't invoked via a command."
exit 12
end
... |
Maintain the same structure and functionality when rewriting this code in REXX. | import ast
class CallCountingVisitor(ast.NodeVisitor):
def __init__(self):
self.calls = {}
def visit_Call(self, node):
if isinstance(node.func, ast.Name):
fun_name = node.func.id
call_count = self.calls.get(fun_name, 0)
self.calls[fun_name] = call_count + 1... | fid='pgm.rex'
cnt.=0
funl=''
Do While lines(fid)>0
l=linein(fid)
Do Until p=0
p=pos('(',l)
If p>0 Then Do
do i=p-1 To 1 By -1 While is_tc(substr(l,i,1))
End
fn=substr(l,i+1,p-i-1)
If fn<>'' Then
Call store fn
l=substr(l,p+1)
End
End
End
Do While funl<>''
... |
Generate a REXX translation of this Python snippet without changing its computational steps. | >>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> c = conn.cursor()
>>> c.execute()
<sqlite3.Cursor object at 0x013263B0>
>>>
c.execute()
<sqlite3.Cursor object at 0x013263B0>
>>> for t in [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00),
('2006-0... | id = 000112222
table.id.!firstname = 'Robert'
table.id.!middlename = 'Jon'
table.id.!lastname = 'Smith'
table.id.!dob = '06/09/1946'
table.id.!gender = 'm'
table.id.!phone = '(111)-222-3333'
table.id.!addr = '123 Elm Drive\Apartment 6A'
table.id.!town = 'Gotham City'... |
Translate this program into REXX but keep the logic exactly as in Python. | >>> import sqlite3
>>> conn = sqlite3.connect(':memory:')
>>> c = conn.cursor()
>>> c.execute()
<sqlite3.Cursor object at 0x013263B0>
>>>
c.execute()
<sqlite3.Cursor object at 0x013263B0>
>>> for t in [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
('2006-04-05', 'BUY', 'MSOFT', 1000, 72.00),
('2006-0... | id = 000112222
table.id.!firstname = 'Robert'
table.id.!middlename = 'Jon'
table.id.!lastname = 'Smith'
table.id.!dob = '06/09/1946'
table.id.!gender = 'm'
table.id.!phone = '(111)-222-3333'
table.id.!addr = '123 Elm Drive\Apartment 6A'
table.id.!town = 'Gotham City'... |
Produce a language-to-language conversion: from Python to REXX, same semantics. | nicePrimes( s, e ) = { local( m );
forprime( p = s, e,
m = p; \\
while( m > 9, \\ m == p mod 9
m = sumdigits( m ) ); \\
if( isprime( m ),
print1( p, " " ) ) );
}
|
n=1000
prime = .Array~new(n)~fill(.true)~~remove(1)
p.=0
Do i = 2 to n
If prime[i] = .true Then Do
Do j = i * i to n by i
prime~remove(j)
End
p.i=1
End
End
z=0
ol=''
Do i=500 To 1000
If p.i then Do
dr=digroot(i)
If p.dr Then Do
ol=ol' 'i'('dr')'
z=z+1
If z//10=0... |
Change the following Python code into REXX without altering its purpose. | nicePrimes( s, e ) = { local( m );
forprime( p = s, e,
m = p; \\
while( m > 9, \\ m == p mod 9
m = sumdigits( m ) ); \\
if( isprime( m ),
print1( p, " " ) ) );
}
|
n=1000
prime = .Array~new(n)~fill(.true)~~remove(1)
p.=0
Do i = 2 to n
If prime[i] = .true Then Do
Do j = i * i to n by i
prime~remove(j)
End
p.i=1
End
End
z=0
ol=''
Do i=500 To 1000
If p.i then Do
dr=digroot(i)
If p.dr Then Do
ol=ol' 'i'('dr')'
z=z+1
If z//10=0... |
Keep all operations the same but rewrite the snippet in REXX. | import sys
import calendar
year = 2013
if len(sys.argv) > 1:
try:
year = int(sys.argv[-1])
except ValueError:
pass
for month in range(1, 13):
last_sunday = max(week[-1] for week in calendar.monthcalendar(year, month))
print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_sun... |
parse arg yyyy
do j=1 for 12
_ = lastDOW('Sunday', j, yyyy)
say right(_,4)'-'right(j,2,0)"-"left(word(_,2),2)
end
exit
β lastDOW: procedure to return the date of the last day-of-week of β
β ... |
Port the following code from Python to REXX with equivalent syntax and logic. | import sys
import calendar
year = 2013
if len(sys.argv) > 1:
try:
year = int(sys.argv[-1])
except ValueError:
pass
for month in range(1, 13):
last_sunday = max(week[-1] for week in calendar.monthcalendar(year, month))
print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_sun... |
parse arg yyyy
do j=1 for 12
_ = lastDOW('Sunday', j, yyyy)
say right(_,4)'-'right(j,2,0)"-"left(word(_,2),2)
end
exit
β lastDOW: procedure to return the date of the last day-of-week of β
β ... |
Convert this Python block to REXX, preserving its control flow and logic. | from random import choice, shuffle
from copy import deepcopy
def rls(n):
if n <= 0:
return []
else:
symbols = list(range(n))
square = _rls(symbols)
return _shuffle_transpose_shuffle(square)
def _shuffle_transpose_shuffle(matrix):
square = deepcopy(matrix)
shuffle(squar... |
parse arg N seed .
if N=='' | N=="," then N= 5
if datatype(seed, 'W') then call random ,,seed
w= length(N - 1)
$=
do i=0 for N; $= $ right(i, w, '_')
end
z= ... |
Produce a functionally identical REXX code for the snippet given in Python. |
from itertools import chain, groupby
from os.path import expanduser
from functools import reduce
def main():
print('\n'.join(
concatMap(circularGroup)(
anagrams(3)(
lines(readFile('~/mitWords.txt'))
)
)
))
def anagrams(n):
... |
parse arg iFID L .
if iFID==''|iFID=="," then iFID= 'wordlist.10k'
if L==''| L=="," then L= 3
#= 0
@.=
do r=0 while lines(iFID) \== 0
parse upper ... |
Maintain the same structure and functionality when rewriting this code in REXX. | from itertools import count, islice
def _basechange_int(num, b):
if num == 0:
return [0]
result = []
while num != 0:
num, d = divmod(num, b)
result.append(d)
return result[::-1]
def fairshare(b=2):
for i in count():
yield sum(_basechange_int(i, b)) % b
if __na... |
parse arg n g
if n=='' | n=="," then n= 25
if g='' | g="," then g= 2 3 5 11
do p=1 for words(g); r= word(g, p)
$= 'base' right(r, 2)': '
do j=0 for... |
Preserve the algorithm and functionality while converting the code from Python to REXX. | from collections import deque
from itertools import dropwhile, islice, takewhile
from textwrap import wrap
from typing import Iterable, Iterator
Digits = str
def esthetic_nums(base: int) -> Iterator[int]:
queue: deque[tuple[int, int]] = deque()
queue.extendleft((d, d) for d in range(1, base))
whi... |
parse arg baseL baseH range
if baseL=='' | baseL=="," then baseL= 2
if baseH=='' | baseH=="," then baseH=16
if range=='' | range=="," then range=1000..9999
do radix=baseL to baseH; #= 0; if radix<2 then iterate
start= radix * 4; stop = rad... |
Convert the following code from Python to REXX, ensuring the logic remains intact. | from operator import itemgetter
DEBUG = False
def spermutations(n):
sign = 1
p = [[i, 0 if i == 0 else -1]
for i in range(n)]
if DEBUG: print '
yield tuple(pp[0] for pp in p), sign
while any(pp[1] for pp in p):
i1, (n1, d1) = max(((i, pp) for i, pp in enumerate(p) i... |
Parse Arg things
e.=''
Select
When things='?' Then
Call help
When things='' Then
things=4
When words(things)>1 Then Do
elements=things
things=words(things)
Do i=0 By 1 While elements<>''
Parse Var elements e.i elements
End
End
Otherwise
If datatype(things)<>'NUM' Then... |
Rewrite the snippet below in REXX so it works the same as the original Python code. | import random
random.seed()
attributes_total = 0
count = 0
while attributes_total < 75 or count < 2:
attributes = []
for attribute in range(0, 6):
rolls = []
for roll in range(0, 4):
result = random.randint(1, 6)
rolls.append(result)
sorted_rol... |
Generates 4 random, whole values between 1 and 6.
Saves the sum of the 3 largest values.
Generates a total of 6 values this way.
Displays the total, and all 6 values once finished.
*/
Do try=1 By 1
ge15=0
sum=0
ol=''
Do i=1 To 6
rl=''
Do j=1 To 4
rl=rl (random(5)+1)
End
rl=wordsort(rl)
... |
Please provide an equivalent version of this Python code in REXX. | 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 sequence(max_n=None):
n = 0
while True:
n += 1
ii = 0
if max_n is not No... |
parse arg N .
if N=='' | N=="," then N= 15
say 'ββdivisorsββ ββsmallest number with N divisorsββ'
@.=
do i=1 for N; z= 1 + (i\==1)
do j=z by z
if @.... |
Convert this Python snippet to REXX and keep its semantics consistent. |
bar = 'βββββ
βββ'
barcount = len(bar)
def sparkline(numbers):
mn, mx = min(numbers), max(numbers)
extent = mx - mn
sparkline = ''.join(bar[min([barcount - 1,
int((n - mn) / extent * barcount)])]
for n in numbers)
return mn, mx, sparkline
if __... |
options replace format comments java crossref symbols nobinary
runSample(arg)
return
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
method sparkline(spark) private static
spark = spark.changestr(',', ' ')
bars = '\u2581 \u2582 \u2583 \u2584 \u2585 \u2586 \u2587 \u2588'
barK = ... |
Keep all operations the same but rewrite the snippet in REXX. | def longest_increasing_subsequence(X):
N = len(X)
P = [0] * N
M = [0] * (N+1)
L = 0
for i in range(N):
lo = 1
hi = L
while lo <= hi:
mid = (lo+hi)//2
if (X[M[mid]] < X[i]):
lo = mid+1
else:
hi = mid-1
... |
$.=; $.1= 3 2 6 4 5 1
$.2= 0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15
do j=1 while $.j\==''; say
say ' input: ' $.j
call LIS $.j
say 'output: ' result
end
exi... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | from macropy.core.macros import *
from macropy.core.quotes import macros, q, ast, u
macros = Macros()
@macros.expr
def expand(tree, **kw):
addition = 10
return q[lambda x: x * ast[tree] + u[addition]]
|
β The REXX language doesn't allow for the changing or overriding of β
β syntax per se, but any of the built-in-functions (BIFs) can be β
β overridden by just specifying your own. β
β β
β To use the REXX's version o... |
Produce a functionally identical REXX code for the snippet given in Python. |
import urllib.request
from collections import Counter
urllib.request.urlretrieve("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt", "unixdict.txt")
dictionary = open("unixdict.txt","r")
wordList = dictionary.read().split('\n')
dictionary.close()
filteredWords = [chosenWord for chosenWord in wordList if ... |
parse arg minL iFID .
if minL=='' | minL=="," then minL= 9
if iFID=='' | iFID=="," then iFID='unixdict.txt'
#= 0; @.=; !.= 0
do recs=0 while lines(iFID)\==0
x= strip( linein( iFID) )
if leng... |
Generate an equivalent REXX version of this Python code. | >>> name = raw_input("Enter a variable name: ")
Enter a variable name: X
>>> globals()[name] = 42
>>> X
42
|
parse arg newVar newValue
say 'Arguments as they were entered via the command line: ' newVar newValue
say
call value newVar, newValue
say 'The newly assigned value (as per the VALUE bif)------' newVar value(newVar)
|
Generate an equivalent REXX version of this Python code. |
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
if __name__ == '__main__':
for p in range(3, 999):
if not isPrime(p):
continue
for q in range(p+1, 1000//p):
if not isPrime(q):
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 1000
if cols=='' | cols=="," then cols= 10
call genP
w= 10
@oss= ' odd squarefree semiprimes... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.