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. |
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... |
Preserve the algorithm and functionality while converting the code from Python to REXX. |
from operator import le
from itertools import takewhile
def monotonicDigits(base):
def go(n):
return monotonic(le)(
showIntAtBase(base)(digitFromInt)(n)('')
)
return go
def monotonic(op):
def go(xs):
return all(map(op, xs, xs[1:]))
return go
def ... |
parse arg n cols .
if n=='' | n=="," then n= 1000
if cols=='' | cols=="," then cols= 10
call genP
w= 10
title= ' primes whose decimal di... |
Please provide an equivalent version of this Python code in REXX. |
from operator import le
from itertools import takewhile
def monotonicDigits(base):
def go(n):
return monotonic(le)(
showIntAtBase(base)(digitFromInt)(n)('')
)
return go
def monotonic(op):
def go(xs):
return all(map(op, xs, xs[1:]))
return go
def ... |
parse arg n cols .
if n=='' | n=="," then n= 1000
if cols=='' | cols=="," then cols= 10
call genP
w= 10
title= ' primes whose decimal di... |
Port the following code from Python to REXX with equivalent syntax and logic. | from fractions import Fraction
from math import floor
from itertools import islice, groupby
def cw():
a = Fraction(1)
while True:
yield a
a = 1 / (2 * floor(a) + 1 - a)
def r2cf(rational):
num, den = rational.numerator, rational.denominator
while den:
num, (digit, den) = den, ... |
numeric digits 2000
parse arg LO HI te .
if LO=='' | LO=="," then LO= 1
if HI=='' | HI=="," then HI= 20
if te=='' | te=="," then te= '/'
if datatype(LO, 'W') then call CW_terms
if pos('/', te)>0 ... |
Transform the following Python implementation into REXX, maintaining the same output and logic. | from fractions import Fraction
from math import floor
from itertools import islice, groupby
def cw():
a = Fraction(1)
while True:
yield a
a = 1 / (2 * floor(a) + 1 - a)
def r2cf(rational):
num, den = rational.numerator, rational.denominator
while den:
num, (digit, den) = den, ... |
numeric digits 2000
parse arg LO HI te .
if LO=='' | LO=="," then LO= 1
if HI=='' | HI=="," then HI= 20
if te=='' | te=="," then te= '/'
if datatype(LO, 'W') then call CW_terms
if pos('/', te)>0 ... |
Transform the following Python implementation into REXX, maintaining the same output and logic. | from __future__ import print_function
def order_disjoint_list_items(data, items):
itemindices = []
for item in set(items):
itemcount = items.count(item)
lastindex = [-1]
for i in range(itemcount):
lastindex.append(data.index(item, lastindex[-1] + 1))
it... |
used = '0'x
@. =
@.1 = " the cat sat on the mat | mat cat "
@.2 = " the cat sat on the mat | cat mat "
@.3 = " A B C A B C A B C | C A C A " ... |
Port the following code from Python to REXX with equivalent syntax and logic. | for i in range(65,123):
check = 1
for j in range(2,i):
if i%j == 0:
check = 0
if check==1:
print(chr(i),end='')
|
parse arg iFID .
if iFID=='' | iFID=="," then iFID='unixdict.txt'
call genPrimes
say 'reading the dictionary file: ' iFID
say
#= 0
do recs=0 while lines(iFID)\==0
x= stri... |
Transform the following Python implementation into REXX, maintaining the same output and logic. | for i in range(65,123):
check = 1
for j in range(2,i):
if i%j == 0:
check = 0
if check==1:
print(chr(i),end='')
|
parse arg iFID .
if iFID=='' | iFID=="," then iFID='unixdict.txt'
call genPrimes
say 'reading the dictionary file: ' iFID
say
#= 0
do recs=0 while lines(iFID)\==0
x= stri... |
Rewrite the snippet below in REXX so it works the same as the original Python code. |
from itertools import takewhile
def palindromicPrimes():
def p(n):
s = str(n)
return s == s[::-1]
return (n for n in primes() if p(n))
def main():
print('\n'.join(
str(x) for x in takewhile(
lambda n: 1000 > n,
palindromicPrimes()
)
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 1000
if cols=='' | cols=="," then cols= 10
call genP
w= max(8, length( commas(hi) ) )
title= ' palindromic primes in base ten that ar... |
Transform the following Python implementation into REXX, maintaining the same output and logic. |
from itertools import takewhile
def palindromicPrimes():
def p(n):
s = str(n)
return s == s[::-1]
return (n for n in primes() if p(n))
def main():
print('\n'.join(
str(x) for x in takewhile(
lambda n: 1000 > n,
palindromicPrimes()
)
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 1000
if cols=='' | cols=="," then cols= 10
call genP
w= max(8, length( commas(hi) ) )
title= ' palindromic primes in base ten that ar... |
Rewrite the snippet below in REXX so it works the same as the original Python code. |
from functools import reduce
from itertools import count, islice
def sylvester():
def go(n):
return 1 + reduce(
lambda a, x: a * go(x),
range(0, n),
1
) if 0 != n else 2
return map(go, count(0))
def main():
print("First 10 terms of OEI... |
parse arg n .
if n=='' | n=="," then n= 10
numeric digits max(9, 2**(n-7) * 13 + 1)
@.0= 2
$= 0
do j=0 for n; jm= j - 1
if j>0 then @.j= @.jm**2 - @.jm + 1
say 'S... |
Generate a REXX translation of this Python snippet without changing its computational steps. | from fractions import Fraction
def harmonic_series():
n, h = Fraction(1), Fraction(1)
while True:
yield h
h += 1 / (n + 1)
n += 1
if __name__ == '__main__':
from itertools import islice
for n, d in (h.as_integer_ratio() for h in islice(harmonic_series(), 20)):
print(n,... |
parse arg digs sums high ints
if digs='' | digs="," then digs= 80
if sums='' | sums="," then sums= 20
if high='' | high="," then high= 10
if ints='' | ints="," then ints= 1 2 3 4 5 6 7 8 9 10
w= length(sums) + 2
numeric digi... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | python
Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f(string1, string2, separator):
return separator.join([string1, '', string2])
>>> f('Rosetta', 'Code', ':')
'Rosetta::Code'
>>>
|
say f(a,b,c)
exit
f:return arg(1)arg(3)arg(3)arg(2)
|
Write the same algorithm in REXX as shown in this Python implementation. | >>> def eval_with_x(code, a, b):
return eval(code, {'x':b}) - eval(code, {'x':a})
>>> eval_with_x('2 ** x', 3, 5)
24
| say evalWithX("x**2", 2)
say evalWithX("x**2", 3.1415926)
::routine evalWithX
use arg expression, x
-- X now has the value of the second argument
interpret "return" expression
|
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | >>> def eval_with_x(code, a, b):
return eval(code, {'x':b}) - eval(code, {'x':a})
>>> eval_with_x('2 ** x', 3, 5)
24
| say evalWithX("x**2", 2)
say evalWithX("x**2", 3.1415926)
::routine evalWithX
use arg expression, x
-- X now has the value of the second argument
interpret "return" expression
|
Produce a functionally identical REXX code for the snippet given in Python. | >>> exec
10
| a = .array~of(1, 2, 3)
ins = "loop num over a; say num; end"
interpret ins
|
Write the same code in REXX as shown below in Python. | >>> exec
10
| a = .array~of(1, 2, 3)
ins = "loop num over a; say num; end"
interpret ins
|
Produce a functionally identical REXX code for the snippet given in Python. | def rank(x): return int('a'.join(map(str, [1] + x)), 11)
def unrank(n):
s = ''
while n: s,n = "0123456789a"[n%11] + s, n//11
return map(int, s.split('a'))[1:]
l = [1, 2, 3, 10, 100, 987654321]
print l
n = rank(l)
print n
l = unrank(n)
print l
|
parse arg $
if $='' | $="," then $=3 14 159 265358979323846
$= translate( space($), ',', " ")
numeric digits max(9, 2 * length($) )
say 'original list=' $
N= rank($); s... |
Maintain the same structure and functionality when rewriting this code in REXX. | import random
print(random.sample(range(1, 21), 20))
|
parse arg n cols seed .
if n=='' | n=="," then n= 20
if cols=='' | cols=="," then cols= 10
if datatype(seed, 'W') then call random ,,seed
w= 6
title= ' random integers (1 βββΊ ' n") with no repeats"
say ' index β'center(title, 1 + ... |
Change the following Python code into REXX without altering its purpose. | from sympy import isprime
def print50(a, width=8):
for i, n in enumerate(a):
print(f'{n: {width},}', end='\n' if (i + 1) % 10 == 0 else '')
def generate_cyclops(maxdig=9):
yield 0
for d in range((maxdig + 1) // 2):
arr = [str(i) for i in range(10**d, 10**(d+1)) if not('0' in str(i))]
... |
parse arg n cols .
if n=='' | n=="," then n= 50
if cols=='' | cols=="," then cols= 10
call genP
w= max(10, length( commas(@.#) ) )
pri?= 0; bli?= 0; pal?= 0; call 0 ' first ' commas(n) ... |
Write the same algorithm in REXX as shown in this Python implementation. |
def conjugate(infinitive):
if not infinitive[-3:] == "are":
print("'", infinitive, "' non prima coniugatio verbi.\n", sep='')
return False
stem = infinitive[0:-3]
if len(stem) == 0:
print("\'", infinitive, "\' non satis diu conjugatus\n", sep='')
return False
p... |
parse arg verbs
if verbs='' | verbs="," then verbs= 'amare dare'
suffix= 'o as at amus atis ant'
#= words(verbs)
do j=1 for #; say
$= word(verbs, j); $$= $; upper $$
if \datatype($, 'M') then call ser "the follo... |
Can you help me rewrite this code in REXX instead of Python, keeping it the same logically? |
def conjugate(infinitive):
if not infinitive[-3:] == "are":
print("'", infinitive, "' non prima coniugatio verbi.\n", sep='')
return False
stem = infinitive[0:-3]
if len(stem) == 0:
print("\'", infinitive, "\' non satis diu conjugatus\n", sep='')
return False
p... |
parse arg verbs
if verbs='' | verbs="," then verbs= 'amare dare'
suffix= 'o as at amus atis ant'
#= words(verbs)
do j=1 for #; say
$= word(verbs, j); $$= $; upper $$
if \datatype($, 'M') then call ser "the follo... |
Produce a functionally identical REXX code for the snippet given in Python. |
def prime(limite, mostrar):
global columna
columna = 0
for n in range(limite):
strn = str(n)
if isPrime(n) and ('123' in str(n)):
columna += 1
if mostrar == True:
print(n, end=" ");
if columna % 8 == 0:
... |
parse arg hi cols str .
if hi=='' | hi=="," then hi= 100000
if cols=='' | cols=="," then cols= 10
if str=='' | str=="," then str= 123
call genP
w= 10
title= ' primes N ... |
Translate the given Python code snippet into REXX without altering its behavior. |
def prime(limite, mostrar):
global columna
columna = 0
for n in range(limite):
strn = str(n)
if isPrime(n) and ('123' in str(n)):
columna += 1
if mostrar == True:
print(n, end=" ");
if columna % 8 == 0:
... |
parse arg hi cols str .
if hi=='' | hi=="," then hi= 100000
if cols=='' | cols=="," then cols= 10
if str=='' | str=="," then str= 123
call genP
w= 10
title= ' primes N ... |
Convert this Python snippet to REXX and keep its semantics consistent. |
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, 5499, 2):
if not isPrime(p+6):
continue
if not isPrime(p+2):
continue
if not isPrime(p):
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 5500
if cols=='' | cols=="," then cols= 4
call genP hi + 6
do p=1 while @.p<hi
end
w= 30
__= ' '; @trip= ' prime tr... |
Write the same algorithm in REXX as shown in this Python implementation. |
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, 5499, 2):
if not isPrime(p+6):
continue
if not isPrime(p+2):
continue
if not isPrime(p):
... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 5500
if cols=='' | cols=="," then cols= 4
call genP hi + 6
do p=1 while @.p<hi
end
w= 30
__= ' '; @trip= ' prime tr... |
Convert this Python snippet to REXX and keep its semantics consistent. |
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
if __name__ == '__main__':
print("p q pq+2")
print("-----------------------")
for p in range(2, 499):
if not isPrime(p):
continue
q = p... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 500
if cols=='' | cols=="," then cols= 10
call genP hi+50
do p=1 while @.p<hi
end
call genP @.p * @.q + 2
w= 10 ... |
Please provide an equivalent version of this Python code in REXX. |
def isPrime(n):
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
if __name__ == '__main__':
print("p q pq+2")
print("-----------------------")
for p in range(2, 499):
if not isPrime(p):
continue
q = p... |
parse arg hi cols .
if hi=='' | hi=="," then hi= 500
if cols=='' | cols=="," then cols= 10
call genP hi+50
do p=1 while @.p<hi
end
call genP @.p * @.q + 2
w= 10 ... |
Maintain the same structure and functionality when rewriting this code in REXX. | import math
print("working...")
list = [(3,4,34,25,9,12,36,56,36),(2,8,81,169,34,55,76,49,7),(75,121,75,144,35,16,46,35)]
Squares = []
def issquare(x):
for p in range(x):
if x == p*p:
return 1
for n in range(3):
for m in range(len(list[n])):
if issquare(list[n][m]):
Squares.append(list[n][m])
Squares.sor... | Parse Version v
Say v
l.1=.array~of(3,4,34,25,9,12,36,56,36)
l.2=.array~of(2,8,81,169,34,55,76,49,7)
l.3=.array~of(75,121,75,144,35,16,46,35)
st.0=0
Do li=1 To 3
Do e over l.li
If is_square(e) Then
Call store s
End
End
Call Show
Exit
is_square:
Parse Arg x
Do i=1 By 1 UNtil i**2>x
if i**2=x Then Re... |
Translate the given Python code snippet into REXX without altering its behavior. | import math
print("working...")
list = [(3,4,34,25,9,12,36,56,36),(2,8,81,169,34,55,76,49,7),(75,121,75,144,35,16,46,35)]
Squares = []
def issquare(x):
for p in range(x):
if x == p*p:
return 1
for n in range(3):
for m in range(len(list[n])):
if issquare(list[n][m]):
Squares.append(list[n][m])
Squares.sor... | Parse Version v
Say v
l.1=.array~of(3,4,34,25,9,12,36,56,36)
l.2=.array~of(2,8,81,169,34,55,76,49,7)
l.3=.array~of(75,121,75,144,35,16,46,35)
st.0=0
Do li=1 To 3
Do e over l.li
If is_square(e) Then
Call store s
End
End
Call Show
Exit
is_square:
Parse Arg x
Do i=1 By 1 UNtil i**2>x
if i**2=x Then Re... |
Can you help me rewrite this code in REXX instead of Python, keeping it the same logically? |
from typing import List, Tuple, Dict, Set
from itertools import cycle, islice
from collections import Counter
import re
import random
import urllib
dict_fname = 'unixdict.txt'
dict_url1 = 'http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'
dict_url2 = 'https://raw.githubusercontent.com/dwyl/english-words/maste... |
signal on halt
parse arg iFID seed .
if iFID=='' | iFID=="," then iFID='unixdict.txt'
if datatype(seed, 'W') then call random ,,seed
call read
call IDs
first= random(1, min(100000, starters) )
list= $$$.first
say; say eye "OK, ... |
Ensure the translated REXX code behaves exactly like the original Python snippet. |
var x = 0
var y = 0
There are also multi-line comments
Everything inside of
]
discard
|
NetRexx comment block
*/
-- NetRexx line comment
|
Please provide an equivalent version of this Python code in REXX. |
revision = "October 13th 2020"
elements = (
"hydrogen helium lithium beryllium boron carbon nitrogen oxygen fluorine "
"neon sodium magnesium aluminum silicon phosphorous sulfur chlorine argon "
"potassium calcium scandium titanium vanadium chromium manganese iron "
"cobalt nickel copper zinc gall... |
$= 'hydrogen helium lithium beryllium boron carbon' ,
'nitrogen oxygen fluorine neon sodium magnesium' ,
'aluminum silicon phosphorous sulfur chlorine argon' ,
'potassium calcium scandium titanium vanadium chromi... |
Generate a REXX translation of this Python snippet without changing its computational steps. | def makechange(denominations = [1,2,5,10,20,50,100,200], total = 988):
print(f"Available denominations: {denominations}. Total is to be: {total}.")
coins, remaining = sorted(denominations, reverse=True), total
for n in range(len(coins)):
coinsused, remaining = divmod(remaining, coins[n])
if ... |
parse arg $ coins
if $='' | $="," then $= 988
if coins='' | coins="," then coins= 1 2 5 10 20 50 100 200
#= words(coins)
w= 0
do j=1 for #; @.j= word(coins, j)
... |
Translate this program into REXX but keep the logic exactly as in Python. |
def longestPalindromes(s):
k = s.lower()
palindromes = [
palExpansion(k)(ab) for ab
in palindromicNuclei(k)
]
maxLength = max([
len(x) for x in palindromes
]) if palindromes else 1
return (
[
x for x in palindromes if maxLength == len(x)
... |
parse arg s
if s==''|s=="," then s='babaccd rotator reverse forever several palindrome abaracadaraba'
do i=1 for words(s); x= word(s, i)
L= length(x); m= 0
do LL=2 f... |
Generate an equivalent REXX version of this Python code. | def get_next_character(f):
c = f.read(1)
while c:
while True:
try:
yield c.decode('utf-8')
except UnicodeDecodeError:
c += f.read(1)
else:
c = f.read(1)
break
with open("input.txt","rb") as f:
for c in get_next_character(f):
... |
options replace format comments java crossref symbols nobinary
numeric digits 20
runSample(arg)
return
-- ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
method readCharacters(fName) public static binary returns String
slurped = String('')
slrp = StringBuilder()
fr = Reader null
... |
Please provide an equivalent version of this Python code in REXX. |
import sys, os
import random
import time
def print_there(x, y, text):
sys.stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text))
sys.stdout.flush()
class Ball():
def __init__(self):
self.x = 0
self.y = 0
def update(self):
self.x += random.randint(0,1)
self... |
trace off
if !all(arg()) then exit
signal on halt
parse arg rows balls freeze seed .
if rows =='' | rows=="," then rows= 0
if balls=='' | balls=="," then balls= 100
if freeze=='' | fre... |
Convert the following code from Python to REXX, ensuring the logic remains intact. |
from itertools import count
def firstSquareWithPrefix(n):
pfx = str(n)
lng = len(pfx)
return int(
next(
s for s in (
str(x * x) for x in count(0)
)
if pfx == s[0:lng]
)
)
def main():
print('\n'.join([
str(... |
numeric digits 20
parse arg n cols .
if n=='' | n=="," then n= 50
if cols=='' | cols=="," then cols= 10
w= 10
say ' index β'center(" smallest squares that begin with N < " n, ... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. |
from itertools import count
def firstSquareWithPrefix(n):
pfx = str(n)
lng = len(pfx)
return int(
next(
s for s in (
str(x * x) for x in count(0)
)
if pfx == s[0:lng]
)
)
def main():
print('\n'.join([
str(... |
numeric digits 20
parse arg n cols .
if n=='' | n=="," then n= 50
if cols=='' | cols=="," then cols= 10
w= 10
say ' index β'center(" smallest squares that begin with N < " n, ... |
Write a version of this Python function in REXX with identical behavior. |
def circle_sort_backend(A:list, L:int, R:int)->'sort A in place, returning the number of swaps':
n = R-L
if n < 2:
return 0
swaps = 0
m = n//2
for i in range(m):
if A[R-(i+1)] < A[L+i]:
(A[R-(i+1)], A[L+i],) = (A[L+i], A[R-(i+1)],)
swaps += 1
if ... |
parse arg x
if x='' | x="," then x= 6 7 8 9 2 5 3 4 1
call make_array 'before sort:'
call circleSort #
call make_list ' after sort:'
exit
circleSort: d... |
Produce a language-to-language conversion: from Python to REXX, same semantics. | import urllib.request
from collections import Counter
GRID =
def getwords(url='http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'):
"Return lowercased words of 3 to 9 characters"
words = urllib.request.urlopen(url).read().decode().strip().lower().split()
return (w for w in words if 2 < len(w) < 10)
... |
parse arg grid minL iFID .
if grid==''|grid=="," then grid= 'ndeokgelw'
if minL==''|minL=="," then minL= 3
if iFID==''|iFID=="," then iFID= 'UNIXDICT.TXT'
oMinL= minL; minL= abs(minL)
gridU= grid; upper gridU
Lg= length(grid); ... |
Change the programming language of this snippet from Python to REXX without modifying what it does. | def getitem(s, depth=0):
out = [""]
while s:
c = s[0]
if depth and (c == ',' or c == '}'):
return out,s
if c == '{':
x = getgroup(s[1:], depth+1)
if x:
out,s = [a+b for a in out for b in x[0]], x[1]
continue
if c... |
* Brace expansion
* 26.07.2016
* s.* holds the set of strings
*--------------------------------------------------------------------*/
text.1='{,{,gotta have{ ,\, again\, }}more }cowbell!'
text.2='~/{Downloads,Pictures}
text.3='It{{em,alic}iz,erat}e{d,}, please. '
text.4='{}} some }{,{\\{ edge, edge} \,}{ cases, {here}... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | from itertools import islice
class INW():
def __init__(self, **wheels):
self._wheels = wheels
self.isect = {name: self._wstate(name, wheel)
for name, wheel in wheels.items()}
def _wstate(self, name, wheel):
"Wheel state holder"
assert all(val in... |
@.=
parse arg lim @.1
if lim='' | lim="," then lim= 20
if @.1='' | @.1="," then do; @.1= ' A: 1 2 3 '
@.2= ' A: 1 B 2, B: 3 4 '
@.3= ' A: 1 D D, D: 6... |
Convert the following code from Python to REXX, ensuring the logic remains intact. | from itertools import islice
class INW():
def __init__(self, **wheels):
self._wheels = wheels
self.isect = {name: self._wstate(name, wheel)
for name, wheel in wheels.items()}
def _wstate(self, name, wheel):
"Wheel state holder"
assert all(val in... |
@.=
parse arg lim @.1
if lim='' | lim="," then lim= 20
if @.1='' | @.1="," then do; @.1= ' A: 1 2 3 '
@.2= ' A: 1 B 2, B: 3 4 '
@.3= ' A: 1 D D, D: 6... |
Generate an equivalent REXX version of this Python code. | def get_pixel_colour(i_x, i_y):
import win32gui
i_desktop_window_id = win32gui.GetDesktopWindow()
i_desktop_window_dc = win32gui.GetWindowDC(i_desktop_window_id)
long_colour = win32gui.GetPixel(i_desktop_window_dc, i_x, i_y)
i_colour = int(long_colour)
win32gui.ReleaseDC(i_desktop_window_id,i_desktop_window_dc)
... |
parse value cursor() with r c .
hue=scrRead(r, c, 1, 'A')
if hue=='00'x then color= 'black'
if hue=='01'x then color= 'darkblue'
if hue=='02'x then color= 'darkgreen'
if hue=='03'x then color= 'darkturquoise'
if hue=='04'x then color= 'darkred' ... |
Write a version of this Python function in REXX with identical behavior. | from collections import namedtuple
from math import sqrt
Pt = namedtuple('Pt', 'x, y')
Circle = Cir = namedtuple('Circle', 'x, y, r')
def circles_from_p1p2r(p1, p2, r):
'Following explanation at http://mathforum.org/library/drmath/view/53027.html'
if r == 0.0:
raise ValueError('radius of zero')
(x... |
a.=''
a.1=0.1234 0.9876 0.8765 0.2345 2
a.2=0.0000 2.0000 0.0000 0.0000 1
a.3=0.1234 0.9876 0.1234 0.9876 2
a.4=0.1234 0.9876 0.8765 0.2345 0.5
a.5=0.1234 0.9876 0.1234 0.9876 0
Say ' x1 y1 x2 y2 radius cir1x cir1y cir2x cir2y'
Say ' ------ ------ ------ ------ ------ ... |
Maintain the same structure and functionality when rewriting this code in REXX. | from collections import namedtuple
from math import sqrt
Pt = namedtuple('Pt', 'x, y')
Circle = Cir = namedtuple('Circle', 'x, y, r')
def circles_from_p1p2r(p1, p2, r):
'Following explanation at http://mathforum.org/library/drmath/view/53027.html'
if r == 0.0:
raise ValueError('radius of zero')
(x... |
a.=''
a.1=0.1234 0.9876 0.8765 0.2345 2
a.2=0.0000 2.0000 0.0000 0.0000 1
a.3=0.1234 0.9876 0.1234 0.9876 2
a.4=0.1234 0.9876 0.8765 0.2345 0.5
a.5=0.1234 0.9876 0.1234 0.9876 0
Say ' x1 y1 x2 y2 radius cir1x cir1y cir2x cir2y'
Say ' ------ ------ ------ ------ ------ ... |
Change the following Python code into REXX without altering its purpose. | from __future__ import division
import math
from operator import mul
from itertools import product
from functools import reduce
def fac(n):
step = lambda x: 1 + x*4 - (x//2)*2
maxq = int(math.floor(math.sqrt(n)))
d = 1
q = n % 2 == 0 and 2 or 3
while q <= maxq and n % q != 0:
q = st... |
parse arg N .
if N=='' | N=="," then N= 25
!.0= 1260; !.1= 11453481; !.2= 115672; !.3= 124483; !.4= 105264
!.5= 1395; !.6= 126846; !.7= 1827; !.8= 110758; !.9= 156289
L= length(N); aN= abs(N)
numeric digits max(9,... |
Port the provided Python code into REXX while preserving the original functionality. | import random
n = 52
Black, Red = 'Black', 'Red'
blacks = [Black] * (n // 2)
reds = [Red] * (n // 2)
pack = blacks + reds
random.shuffle(pack)
black_stack, red_stack, discard = [], [], []
while pack:
top = pack.pop()
if top == Black:
black_stack.append(pack.pop())
else:
red_stack.appen... |
parse arg trials # shuffs seed .
if trials=='' | trials=="," then trials= 1000
if #=='' | #=="," then #= 52
if shuffs=='' | shuffs=="," then shuffs= #%4
if datatype(seed, 'W') then call random ,,seed
ok=0
... |
Preserve the algorithm and functionality while converting the code from Python to REXX. | import random
n = 52
Black, Red = 'Black', 'Red'
blacks = [Black] * (n // 2)
reds = [Red] * (n // 2)
pack = blacks + reds
random.shuffle(pack)
black_stack, red_stack, discard = [], [], []
while pack:
top = pack.pop()
if top == Black:
black_stack.append(pack.pop())
else:
red_stack.appen... |
parse arg trials # shuffs seed .
if trials=='' | trials=="," then trials= 1000
if #=='' | #=="," then #= 52
if shuffs=='' | shuffs=="," then shuffs= #%4
if datatype(seed, 'W') then call random ,,seed
ok=0
... |
Translate this program into REXX but keep the logic exactly as in Python. |
def _init():
"digit sections for forming numbers"
digi_bits = .strip()
lines = [[d.replace('.', ' ') for d in ln.strip().split()]
for ln in digi_bits.strip().split('\n')
if '
formats = '<2 >2 <2 >2'.split()
digits = [[f"{dig:{f}}" for dig in line]
for f,... |
parse arg m
if m='' | m="," then m= 0 1 20 300 4000 5555 6789 9393
$.=; nnn= words(m)
do j=1 for nnn; z= word(m, j)
if \datatype(z, 'W') then call serr "number isn't numeric: " z
if \datatype(... |
Produce a language-to-language conversion: from Python to REXX, same semantics. |
def _init():
"digit sections for forming numbers"
digi_bits = .strip()
lines = [[d.replace('.', ' ') for d in ln.strip().split()]
for ln in digi_bits.strip().split('\n')
if '
formats = '<2 >2 <2 >2'.split()
digits = [[f"{dig:{f}}" for dig in line]
for f,... |
parse arg m
if m='' | m="," then m= 0 1 20 300 4000 5555 6789 9393
$.=; nnn= words(m)
do j=1 for nnn; z= word(m, j)
if \datatype(z, 'W') then call serr "number isn't numeric: " z
if \datatype(... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | :- initialization(main).
faces([a,k,q,j,10,9,8,7,6,5,4,3,2]).
face(F) :- faces(Fs), member(F,Fs).
suit(S) :- member(S, ['β₯','β¦','β£','β ']).
best_hand(Cards,H) :-
straight_flush(Cards,C) -> H = straight-flush(C)
; many_kind(Cards,F,4) -> H = four-of-a-kind(F)
; full_house(Cards,F1,F2) -> H = full-house(F1... |
* 10.12.2013 Walter Pachl
*--------------------------------------------------------------------*/
d.1='2h 2d 2s ks qd'; x.1='three-of-a-kind'
d.2='2h 5h 7d 8s 9d'; x.2='high-card'
d.3='ah 2d 3s 4s 5s'; x.3='straight'
d.4='2h 3h 2d 3s 3d'; x.4='full-house'
d.5='2h 7h 2d 3s 3d'; x.5='two-pair'
d.6='2h 7h 7d 7s 7c'; x.6... |
Convert this Python block to REXX, preserving its control flow and logic. | :- initialization(main).
faces([a,k,q,j,10,9,8,7,6,5,4,3,2]).
face(F) :- faces(Fs), member(F,Fs).
suit(S) :- member(S, ['β₯','β¦','β£','β ']).
best_hand(Cards,H) :-
straight_flush(Cards,C) -> H = straight-flush(C)
; many_kind(Cards,F,4) -> H = four-of-a-kind(F)
; full_house(Cards,F1,F2) -> H = full-house(F1... |
* 10.12.2013 Walter Pachl
*--------------------------------------------------------------------*/
d.1='2h 2d 2s ks qd'; x.1='three-of-a-kind'
d.2='2h 5h 7d 8s 9d'; x.2='high-card'
d.3='ah 2d 3s 4s 5s'; x.3='straight'
d.4='2h 3h 2d 3s 3d'; x.4='full-house'
d.5='2h 7h 2d 3s 3d'; x.5='two-pair'
d.6='2h 7h 7d 7s 7c'; x.6... |
Change the programming language of this snippet from Python to REXX without modifying what it does. | from functools import wraps
from turtle import *
def memoize(obj):
cache = obj.cache = {}
@wraps(obj)
def memoizer(*args, **kwargs):
key = str(args) + str(kwargs)
if key not in cache:
cache[key] = obj(*args, **kwargs)
return cache[key]
return memoizer
@memoize
def f... |
parse arg order .
if order=='' | order=="," then order= 23
tell= order>=0
s= FibWord( abs(order) )
x= 0; maxX= 0; dx= 0; b= ' '; @. = b; xp= 0
y=... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | from __future__ import print_function
import random
from time import sleep
first = random.choice([True, False])
you = ''
if first:
me = ''.join(random.sample('HT'*3, 3))
print('I choose first and will win on first seeing {} in the list of tosses'.format(me))
while len(you) != 3 or any(ch not in 'HT' for c... |
__= copies('β', 9)
signal on halt
parse arg # seed .
if #=='' | #=="," then #= 3
if datatype(seed,'W') then call random ,,seed
wins=0; do games=1
call gam... |
Generate a REXX translation of this Python snippet without changing its computational steps. | def nonoblocks(blocks, cells):
if not blocks or blocks[0] == 0:
yield [(0, 0)]
else:
assert sum(blocks) + len(blocks)-1 <= cells, \
'Those blocks will not fit in those cells'
blength, brest = blocks[0], blocks[1:]
minspace4rest = sum(1+b for b in brest)
... |
$.=; $.1= 5 2 1
$.2= 5
$.3= 10 8
$.4= 15 2 3 2 3
$.5= 5 2 3
do i=1 while $.i\==''
parse var $.i N blocks
N= strip(N); blocks= space(blocks)
call nono ... |
Can you help me rewrite this code in REXX instead of Python, keeping it the same logically? | def nonoblocks(blocks, cells):
if not blocks or blocks[0] == 0:
yield [(0, 0)]
else:
assert sum(blocks) + len(blocks)-1 <= cells, \
'Those blocks will not fit in those cells'
blength, brest = blocks[0], blocks[1:]
minspace4rest = sum(1+b for b in brest)
... |
$.=; $.1= 5 2 1
$.2= 5
$.3= 10 8
$.4= 15 2 3 2 3
$.5= 5 2 3
do i=1 while $.i\==''
parse var $.i N blocks
N= strip(N); blocks= space(blocks)
call nono ... |
Write the same code in REXX as shown below in Python. |
import inflect
import time
before = time.perf_counter()
p = inflect.engine()
print(' ')
print('eban numbers up to and including 1000:')
print(' ')
count = 0
for i in range(1,1001):
if not 'e' in p.number_to_words(i):
print(str(i)+' ',end='')
count += 1
print(' ')
print(' ')
print... |
numeric digits 20
parse arg $
if $='' then $= '1 1000 1000 4000 1 -10000 1 -100000 1 -1000000 1 -10000000'
do k=1 by 2 to words($)
call banE word($, k), word($, k+1)
end
exit ... |
Write the same code in REXX as shown below in Python. |
import inflect
import time
before = time.perf_counter()
p = inflect.engine()
print(' ')
print('eban numbers up to and including 1000:')
print(' ')
count = 0
for i in range(1,1001):
if not 'e' in p.number_to_words(i):
print(str(i)+' ',end='')
count += 1
print(' ')
print(' ')
print... |
numeric digits 20
parse arg $
if $='' then $= '1 1000 1000 4000 1 -10000 1 -100000 1 -1000000 1 -10000000'
do k=1 by 2 to words($)
call banE word($, k), word($, k+1)
end
exit ... |
Change the following Python code into REXX without altering its purpose. |
from functools import (reduce)
def mayanNumerals(n):
return showIntAtBase(20)(
mayanDigit
)(n)([])
def mayanDigit(n):
if 0 < n:
r = n % 5
return [
(['β' * r] if 0 < r else []) +
(['ββ'] * (n // 5))
]
else:
return ['Ξ']
... |
parse arg $
if $='' then $= 4005 8017 326205 886205,
172037122592320200101
do j=1 for words($)
#= word($, j)
say
say center('converting the decimal number ' # " to ... |
Transform the following Python implementation into REXX, maintaining the same output and logic. | def monkey_coconuts(sailors=5):
"Parameterised the number of sailors using an inner loop including the last mornings case"
nuts = sailors
while True:
n0, wakes = nuts, []
for sailor in range(sailors + 1):
portion, remainder = divmod(n0, sailors)
wakes.append((n0, ... |
parse arg L H .; if L=='' then L= 5
if H=='' then H= 6
do n=L to H
do $=0 while \valid(n, $)
end
say 'sailors='n " coco... |
Translate the given Python code snippet into REXX without altering its behavior. | def monkey_coconuts(sailors=5):
"Parameterised the number of sailors using an inner loop including the last mornings case"
nuts = sailors
while True:
n0, wakes = nuts, []
for sailor in range(sailors + 1):
portion, remainder = divmod(n0, sailors)
wakes.append((n0, ... |
parse arg L H .; if L=='' then L= 5
if H=='' then H= 6
do n=L to H
do $=0 while \valid(n, $)
end
say 'sailors='n " coco... |
Rewrite the snippet below in REXX so it works the same as the original Python code. | import time, calendar, sched, winsound
duration = 750
freq = 1280
bellchar = "\u2407"
watches = 'Middle,Morning,Forenoon,Afternoon,First/Last dog,First'.split(',')
def gap(n=1):
time.sleep(n * duration / 1000)
off = gap
def on(n=1):
winsound.Beep(freq, n * duration)
def bong():
on(); of... |
Parse Arg msg
If msg='?' Then Do
Say 'Ring a nautical bell'
Exit
End
Signal on Halt
Do Forever
Parse Value time() With hh ':' mn ':' ss
ct=time('C')
hhmmc=left(right(ct,7,0),5)
If msg>'' Then
Say center(arg(1) ct time(),79)
If ss==00 & ( mn==00... |
Convert the following code from Python to REXX, ensuring the logic remains intact. | import time, calendar, sched, winsound
duration = 750
freq = 1280
bellchar = "\u2407"
watches = 'Middle,Morning,Forenoon,Afternoon,First/Last dog,First'.split(',')
def gap(n=1):
time.sleep(n * duration / 1000)
off = gap
def on(n=1):
winsound.Beep(freq, n * duration)
def bong():
on(); of... |
Parse Arg msg
If msg='?' Then Do
Say 'Ring a nautical bell'
Exit
End
Signal on Halt
Do Forever
Parse Value time() With hh ':' mn ':' ss
ct=time('C')
hhmmc=left(right(ct,7,0),5)
If msg>'' Then
Say center(arg(1) ct time(),79)
If ss==00 & ( mn==00... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. | >>> import winsound
>>> for note in [261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25]:
winsound.Beep(int(note+.5), 500)
>>>
|
* 24.02.2013 Walter Pachl derived from original REXX version
* Changes: sound(f,sec) --> beep(trunc(f),millisec)
* $ -> sc
* @. -> f.
* re > ra (in sc)
*--------------------------------------------------------------------*/
sc='do ra mi fa so la te do'
dur=1250
... |
Change the programming language of this snippet from Python to REXX without modifying what it does. | >>> import winsound
>>> for note in [261.63, 293.66, 329.63, 349.23, 392.00, 440.00, 493.88, 523.25]:
winsound.Beep(int(note+.5), 500)
>>>
|
* 24.02.2013 Walter Pachl derived from original REXX version
* Changes: sound(f,sec) --> beep(trunc(f),millisec)
* $ -> sc
* @. -> f.
* re > ra (in sc)
*--------------------------------------------------------------------*/
sc='do ra mi fa so la te do'
dur=1250
... |
Ensure the translated REXX code behaves exactly like the original Python snippet. |
import pandas as pd
df_patients = pd.read_csv (r'patients.csv', sep = ",", decimal=".")
df_visits = pd.read_csv (r'visits.csv', sep = ",", decimal=".")
df_visits['VISIT_DATE'] = pd.to_datetime(df_visits['VISIT_DATE'])
df_merge = df_patients.merge(df_visits, on='PATIENT_ID', how='left')
df_group = df_merge.... |
patients='patients.csv'
l=linein(patients)
Parse Var l h1 ',' h2
n=0
idl=''
Do n=1 By 1 While lines(patients)>0
l=linein(patients)
Parse Var l id ',' lastname.id
idl=idl id
End
n=n-1
visits='visits.csv'
l=linein(visits)
h3='LAST_VISIT'
h4='SCORE_SUM'
h5='SCORE_AVG'
date.=''
score.=0
Say '|' h1 '|' h2 '|' h3 ... |
Generate a REXX translation of this Python snippet without changing its computational steps. | import ldap
l = ldap.initialize("ldap://ldap.example.com")
try:
l.protocol_version = ldap.VERSION3
l.set_option(ldap.OPT_REFERRALS, 0)
bind = l.simple_bind_s("me@example.com", "password")
finally:
l.unbind()
|
options replace format comments java crossref symbols binary
import org.apache.directory.ldap.client.api.LdapConnection
import org.apache.directory.ldap.client.api.LdapNetworkConnection
import org.apache.directory.shared.ldap.model.exception.LdapException
import org.slf4j.Logger
import org.slf4j.LoggerFactory
class ... |
Can you help me rewrite this code in REXX instead of Python, keeping it the same logically? | from optparse import OptionParser
[...]
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="write report to FILE", metavar="FILE")
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose", default=True,
help="don't print s... |
parse arg opts
opts=space(opts)
!.=
do while opts\==''
parse var opts x opts
select
when x=='-e' ... |
Convert this Python snippet to REXX and keep its semantics consistent. | from optparse import OptionParser
[...]
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="write report to FILE", metavar="FILE")
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose", default=True,
help="don't print s... |
parse arg opts
opts=space(opts)
!.=
do while opts\==''
parse var opts x opts
select
when x=='-e' ... |
Produce a language-to-language conversion: from Python to REXX, same semantics. | board = []
given = []
start = None
def setup(s):
global board, given, start
lines = s.splitlines()
ncols = len(lines[0].split())
nrows = len(lines)
board = [[-1] * (ncols + 2) for _ in xrange(nrows + 2)]
for r, row in enumerate(lines):
for c, cell in enumerate(row.split()):
... |
maxR=0; maxC=0; maxX=0; minR=9e9; minC=9e9; minX=9e9; cells=0; @.=
parse arg xxx; PZ='Hidato puzzle'
xxx=translate(xxx, , "/\;:_", ',')
do while xxx\=''; parse var xxx r c marks ',' xxx
do while marks\=''; _=@... |
Produce a language-to-language conversion: from Python to REXX, same semantics. | board = []
given = []
start = None
def setup(s):
global board, given, start
lines = s.splitlines()
ncols = len(lines[0].split())
nrows = len(lines)
board = [[-1] * (ncols + 2) for _ in xrange(nrows + 2)]
for r, row in enumerate(lines):
for c, cell in enumerate(row.split()):
... |
maxR=0; maxC=0; maxX=0; minR=9e9; minC=9e9; minX=9e9; cells=0; @.=
parse arg xxx; PZ='Hidato puzzle'
xxx=translate(xxx, , "/\;:_", ',')
do while xxx\=''; parse var xxx r c marks ',' xxx
do while marks\=''; _=@... |
Change the programming language of this snippet from Python to REXX without modifying what it does. | def merge_list(a, b):
out = []
while len(a) and len(b):
if a[0] < b[0]:
out.append(a.pop(0))
else:
out.append(b.pop(0))
out += a
out += b
return out
def strand(a):
i, s = 0, [a.pop(0)]
while i < len(a):
if a[i] > s[-1]:
s.append(a.pop(i))
else:
i += 1
return s
def strand_sort(a):
out = st... |
options replace format comments java crossref savelog symbols binary
import java.util.List
placesList = [String -
"UK London", "US New York", "US Boston", "US Washington" -
, "UK Washington", "US Birmingham", "UK Birmingham", "UK Boston" -
]
lists = [ -
placesList -
, strandSort(St... |
Produce a functionally identical REXX code for the snippet given in Python. | PI = 3.141592653589793
TWO_PI = 6.283185307179586
def normalize2deg(a):
while a < 0: a += 360
while a >= 360: a -= 360
return a
def normalize2grad(a):
while a < 0: a += 400
while a >= 400: a -= 400
return a
def normalize2mil(a):
while a < 0: a += 6400
while a >= 6400: a -= 6400
return a
def normalize... |
numeric digits length( pi() ) - length(.)
parse arg x
if x='' | x="," then x= '-2 -1 0 1 2 6.2831853 16 57.2957795 359 399 6399 1000000'
w= 20; w7= w+7
@deg = 'degrees'; @grd= "gradians"; @mil = 'mils'; @rad = "rad... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. |
from xml.dom import minidom
xmlfile = file("test3.xml")
xmldoc = minidom.parse(xmlfile).documentElement
xmldoc = minidom.parseString("<inventory title="OmniCorp Store
i = xmldoc.getElementsByTagName("item")
firstItemElement = i[0]
for j in xmldoc.getElementsByTagName("price"):
print j.childNodes[0].data ... |
options replace format comments java symbols binary
import javax.xml.parsers.
import javax.xml.xpath.
import org.w3c.dom.
import org.w3c.dom.Node
import org.xml.sax.
xmlStr = '' -
|| '<inventory title="OmniCorp Store #45x10^3">' -
|| ' <section name="health">' -
|| ' <item upc="123456789" stock="12">' -
... |
Change the following Python code into REXX without altering its purpose. | def mc_rank(iterable, start=1):
lastresult, fifo = None, []
for n, item in enumerate(iterable, start-1):
if item[0] == lastresult:
fifo += [item]
else:
while fifo:
yield n, fifo.pop(0)
lastresult, fifo = item[0], fifo + [item]
while fi... |
44 Solomon 1 1 1 1 1
42 Jason 2 3 2 2 2.5
42 Errol 2 3 2 3 2.5
41 Garry 4 6 3 4 5
41 Bernard 4 6 3 5 5
41 Barry 4 6 3 6 5
39 Stephen 7 7 4 7 7
**************************/
Do i=1 To 7
Parse Value sourceline(i+1) With rank.i name.i .
End
pool=0
crank=0
Do i=1 To 7
If rank.i<>crank Then Do
poo... |
Translate the given Python code snippet into REXX without altering its behavior. |
import re
import string
DISABLED_PREFIX = ';'
class Option(object):
def __init__(self, name, value=None, disabled=False,
disabled_prefix=DISABLED_PREFIX):
self.name = str(name)
self.value = value
self.disabled = bool(disabled)
self.... |
parse arg iFID oFID .
if iFID=='' | iFID=="," then iFID= 'UPDATECF.TXT'
if oFID=='' | oFID=="," then oFID='\TEMP\UPDATECF.$$$'
call lineout iFID; call lineout oFID
$.=0
call dos 'ERASE' oFID
cha... |
Please provide an equivalent version of this Python code in REXX. | T = [["79", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"],
["", "H", "O", "L", "", "M", "E", "S", "", "R", "T"],
["3", "A", "B", "C", "D", "F", "G", "I", "J", "K", "N"],
["7", "P", "Q", "U", "V", "W", "X", "Y", "Z", ".", "/"]]
def straddle(s):
return "".join(L[0]+T[0][L.index(c)] for c in ... |
parse arg msg
if msg='' then msg= 'One night-it was the twentieth of March, 1888-I was returning'
say 'plain text=' msg
call genCipher 'et aon ris', 'bcdfghjklm', 'pq/uvwxyz.'
enc= encrypt(msg); say ' encrypted=' enc
dec= decrypt(enc); say... |
Translate the given Python code snippet into REXX without altering its behavior. | import urllib.request
import re
PLAUSIBILITY_RATIO = 2
def plausibility_check(comment, x, y):
print('\n Checking plausibility of: %s' % comment)
if x > PLAUSIBILITY_RATIO * y:
print(' PLAUSIBLE. As we have counts of %i vs %i, a ratio of %4.1f times'
% (x, y, x / y))
else:
... |
parse arg iFID .
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT'
#.=0
do r=0 while lines(iFID)\==0
u=space( lineIn(iFID), 0); upper u
if u=='' then iterate
#.words=#.wor... |
Port the provided Python code into REXX while preserving the original functionality. | import urllib.request
import re
PLAUSIBILITY_RATIO = 2
def plausibility_check(comment, x, y):
print('\n Checking plausibility of: %s' % comment)
if x > PLAUSIBILITY_RATIO * y:
print(' PLAUSIBLE. As we have counts of %i vs %i, a ratio of %4.1f times'
% (x, y, x / y))
else:
... |
parse arg iFID .
if iFID=='' | iFID=="," then iFID='UNIXDICT.TXT'
#.=0
do r=0 while lines(iFID)\==0
u=space( lineIn(iFID), 0); upper u
if u=='' then iterate
#.words=#.wor... |
Preserve the algorithm and functionality while converting the code from Python to REXX. |
from __future__ import division
import sys
from PIL import Image
def _fpart(x):
return x - int(x)
def _rfpart(x):
return 1 - _fpart(x)
def putpixel(img, xy, color, alpha=1):
compose_color = lambda bg, fg: int(round(alpha * fg + (1-alpha) * bg))
c = compose_color(img.getpixel(xy), color)
i... |
background= 'Β·'
image.= background
plotC= 'ββββ'
EoE= 3000
do j=-EoE to +EoE
image.j.0= 'β'
... |
Change the following Python code into REXX without altering its purpose. | def closest_more_than(n, lst):
"(index of) closest int from lst, to n that is also > n"
large = max(lst) + 1
return lst.index(min(lst, key=lambda x: (large if x <= n else x)))
def nexthigh(n):
"Return nxt highest number from n's digits using scan & re-order"
assert n == int(abs(n)), "n >= 0"
th... |
parse arg n
if n='' | n="," then n= 0 9 12 21 12453 738440 45072010 95322020
w= length( commas( word(n, words(n) ) ) )
do j=1 for words(n); y= word(n, j)
masky= mask(y)
lim= copies(9, length(y) ) ... |
Rewrite the snippet below in REXX so it works the same as the original Python code. | def closest_more_than(n, lst):
"(index of) closest int from lst, to n that is also > n"
large = max(lst) + 1
return lst.index(min(lst, key=lambda x: (large if x <= n else x)))
def nexthigh(n):
"Return nxt highest number from n's digits using scan & re-order"
assert n == int(abs(n)), "n >= 0"
th... |
parse arg n
if n='' | n="," then n= 0 9 12 21 12453 738440 45072010 95322020
w= length( commas( word(n, words(n) ) ) )
do j=1 for words(n); y= word(n, j)
masky= mask(y)
lim= copies(9, length(y) ) ... |
Rewrite the snippet below in REXX so it works the same as the original Python code. | import autopy
autopy.key.type_string("Hello, world!")
autopy.key.type_string("Hello, world!", wpm=60)
autopy.key.tap(autopy.key.Code.RETURN)
autopy.key.tap(autopy.key.Code.F1)
autopy.key.tap(autopy.key.Code.LEFT_ARROW)
|
call press 'This text will be put into a buffer as if it came from the keyboard'
|
Convert this Python block to REXX, preserving its control flow and logic. | import random
from collections import OrderedDict
numbers = {
1: 'one',
2: 'two',
3: 'three',
4: 'four',
5: 'five',
6: 'six',
7: 'seven',
8: 'eight',
9: 'nine',
10: 'ten',
11: 'eleven',
12: 'twelve',
13: 'thirteen',
14: 'fourteen',
15: 'fifteen',
16: 's... |
numeric digits 3003
parse arg x
if x='' then x= -164 0 4 6 11 13 75 100 337 9223372036854775807
@.= .
do j=1 for words(x)
say 4_is( word(x, j) )
... |
Rewrite this program in REXX while keeping its functionality equivalent to the Python version. |
import numpy as np
class Revolver:
def __init__(self):
self.cylinder = np.array([False] * 6)
def unload(self):
self.cylinder[:] = False
def load(self):
while self.cylinder[1]:
self.cylinder[:] = np.roll(self.cylinder, 1)
self.c... |
parse arg cyls tests seed .
if cyls=='' | cyls=="," then cyls= 6
if tests=='' | tests=="," then tests= 100000
if datatype(seed, 'W') then call random ,,seed
cyls_ = cyls - 1; @0= copies(0, cyls)
@abc= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
scenarios= 'LSLSFsF... |
Produce a language-to-language conversion: from Python to REXX, same semantics. |
beforeTxt =
smallrc01 =
rc01 =
def intarray(binstring):
return [[1 if ch == '1' else 0 for ch in line]
for line in binstring.strip().split()]
def chararray(intmatrix):
return '\n'.join(''.join(str(p) for p in row) for row in intmatrix)
def toTxt(intmatrix):
Return 8-neighb... |
parse arg iFID .; if iFID=='' then iFID='ZHANG_SUEN.DAT'
white=' '; @.=white
do row=1 while lines(iFID)\==0; _=linein(iFID)
_=translate(_,,.0); cols.row=length(_)
do col=1 for cols.row; @.row.col=substr(_,col,1)
end ... |
Write the same code in REXX as shown below in Python. | >>> from itertools import permutations
>>> pieces = 'KQRrBbNN'
>>> starts = {''.join(p).upper() for p in permutations(pieces)
if p.index('B') % 2 != p.index('b') % 2
and ( p.index('r') < p.index('K') < p.index('R')
or p.index('R') < p.index('K') <... |
parse arg seed .
if seed\=='' then call random ,,seed
@.=.
r1=random(1,6)
@.r1='R'
do until r2\==r1 & r2\==r1-1 & r2\==r1+1
r2=random(1,8)
end
@.r2=... |
Port the provided Python code into REXX while preserving the original functionality. |
import itertools
import re
RE_BARCODE = re.compile(
r"^(?P<s_quiet> +)"
r"(?P<s_guard>
r"(?P<left>[
r"(?P<m_guard>
r"(?P<right>[
r"(?P<e_guard>
r"(?P<e_quiet> +)$"
)
LEFT_DIGITS = {
(0, 0, 0, 1, 1, 0, 1): 0,
(0, 0, 1, 1, 0, 0, 1): 1,
(0, 0, 1, 0, 0, 1, 1): 2,
(0, 1,... |
#.0= ' ## #'
#.1= ' ## #'
#.2= ' # ##'
#.3= ' #### #'
#.4= ' # ##'
#.5= ' ## #'
#.6= ' # ####'
#.7= ' ### ##'
#.8= ' ## ###'
#.9= ' # ##' ; do i=0 for 10; ... |
Write a version of this Python function in REXX with identical behavior. | import win32api
import win32con
import win32evtlog
import win32security
import win32evtlogutil
ph = win32api.GetCurrentProcess()
th = win32security.OpenProcessToken(ph, win32con.TOKEN_READ)
my_sid = win32security.GetTokenInformation(th, win32security.TokenUser)[0]
applicationName = "My Application"
eventID = 1
catego... |
eCMD = 'EVENTCREATE'
type = 'INFORMATION'
id = 234
logName = 'APPLICATION'
source = 'REXX'
desc = 'attempting to add an entry for a Rosetta Code demonstrat... |
Ensure the translated REXX code behaves exactly like the original Python snippet. | irregularOrdinals = {
"one": "first",
"two": "second",
"three": "third",
"five": "fifth",
"eight": "eighth",
"nine": "ninth",
"twelve": "twelfth",
}
def num2ordinal(n):
conversion = int(float(n))
num = spell_integer(conversion)
hyphen = num.rsplit("-", 1)
num = num.rsplit(" ", 1)
... |
numeric digits 3000
parse arg n
if n='' | n="," then n= 1 2 3 4 5 11 65 100 101 272 23456 8007006005004003
pgmOpts= 'ordinal quiet'
do j=1 for words(n)
x=word(n, j) ... |
Keep all operations the same but rewrite the snippet in REXX. | from ipaddress import ip_address
from urllib.parse import urlparse
tests = [
"127.0.0.1",
"127.0.0.1:80",
"::1",
"[::1]:80",
"::192.168.0.1",
"2605:2700:0:3::4713:93e3",
"[2605:2700:0:3::4713:93e3]:80" ]
def parse_ip_port(netloc):
try:
ip = ip_address(netloc)
port = Non... |
_= "_"; say center('input IP address' , 30),
center('hex IP address' , 32),
center('decimal IP address' , 39) "space port"
say copies(_, 30) copies(_, 32) copies(_, 39) copies(_, 5) copies(_, 5)
call IP_parse 127.0.0.1
call IP... |
Translate the given Python code snippet into REXX without altering its behavior. | In [6]: def dec(n):
...: return len(n.rsplit('.')[-1]) if '.' in n else 0
In [7]: dec('12.345')
Out[7]: 3
In [8]: dec('12.3450')
Out[8]: 4
In [9]:
|
numeric digits 1000
@.=;
parse arg @.1; if @.1='' then do; #= 9
@.1 = 12
@.2 = 12.345
@.3 = 12.345555555555
... |
Convert this Python block to REXX, preserving its control flow and logic. | def min_cells_matrix(siz):
return [[min(row, col, siz - row - 1, siz - col - 1) for col in range(siz)] for row in range(siz)]
def display_matrix(mat):
siz = len(mat)
spaces = 2 if siz < 20 else 3 if siz < 200 else 4
print(f"\nMinimum number of cells after, before, above and below {siz} x {siz} square:"... |
parse arg $
if $='' | $="," then $= 21 10 9 2 1
@title= ' the minimum number of cells after, before, above, and below a '
do j=1 for words($); g= word($, j)
w= length( (g-1) % 2)
say center(@title g"x"g ' squa... |
Write a version of this Python function in REXX with identical behavior. |
def maxDeltas(ns):
pairs = [
(abs(a - b), (a, b)) for a, b
in zip(ns, ns[1:])
]
delta = max(pairs, key=lambda ab: ab[0])[0]
return [
ab for ab in pairs
if delta == ab[0]
]
def main():
maxPairs = maxDeltas([
1, 8, 2, -3, 0, 1, 1, -2.3, 0... |
parse arg $
if $='' | S=="," then $= ,
'1,8,2,-3,0,1,1,-2.3,0,5.5,8,6,2,9,11,10,3'
w= 0
$= translate($, , ',')
#= words($)
do i=1... |
Generate a REXX translation of this Python snippet without changing its computational steps. | from sys import stdout
neighbours = [[2, 2], [-2, 2], [2, -2], [-2, -2], [3, 0], [0, 3], [-3, 0], [0, -3]]
cnt = 0
pWid = 0
pHei = 0
def is_valid(a, b):
return -1 < a < pWid and -1 < b < pHei
def iterate(pa, x, y, v):
if v > cnt:
return 1
for i in range(len(neighbours)):
a = x + neighb... |
call time 'Reset'
maxR=0; maxC=0; maxX=0; minR=9e9; minC=9e9; minX=9e9; cells=0; @.=
parse arg xxx
xxx=translate(xxx, , "/\;:_", ',')
do while xxx\=''; parse var xxx r c marks ',' x... |
Translate the given Python code snippet into REXX without altering its behavior. | from sys import stdout
neighbours = [[2, 2], [-2, 2], [2, -2], [-2, -2], [3, 0], [0, 3], [-3, 0], [0, -3]]
cnt = 0
pWid = 0
pHei = 0
def is_valid(a, b):
return -1 < a < pWid and -1 < b < pHei
def iterate(pa, x, y, v):
if v > cnt:
return 1
for i in range(len(neighbours)):
a = x + neighb... |
call time 'Reset'
maxR=0; maxC=0; maxX=0; minR=9e9; minC=9e9; minX=9e9; cells=0; @.=
parse arg xxx
xxx=translate(xxx, , "/\;:_", ',')
do while xxx\=''; parse var xxx r c marks ',' x... |
Translate this program into REXX but keep the logic exactly as in Python. | from sys import stdout
neighbours = [[-1, 0], [0, -1], [1, 0], [0, 1]]
exists = []
lastNumber = 0
wid = 0
hei = 0
def find_next(pa, x, y, z):
for i in range(4):
a = x + neighbours[i][0]
b = y + neighbours[i][1]
if wid > a > -1 and hei > b > -1:
if pa[a][b] == z:
... |
maxR= 0; maxC= 0; maxX= 0;
minR= 9e9; minC= 9e9; minX= 9e9;
cells= 0
parse arg xxx
xxx=translate(xxx, ',,,,,' , "/\;:_")
@.=
do while xxx\=''; parse var xxx r c marks... |
Translate the given Python code snippet into REXX without altering its behavior. | from sys import stdout
neighbours = [[-1, 0], [0, -1], [1, 0], [0, 1]]
exists = []
lastNumber = 0
wid = 0
hei = 0
def find_next(pa, x, y, z):
for i in range(4):
a = x + neighbours[i][0]
b = y + neighbours[i][1]
if wid > a > -1 and hei > b > -1:
if pa[a][b] == z:
... |
maxR= 0; maxC= 0; maxX= 0;
minR= 9e9; minC= 9e9; minX= 9e9;
cells= 0
parse arg xxx
xxx=translate(xxx, ',,,,,' , "/\;:_")
@.=
do while xxx\=''; parse var xxx r c marks... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.