Vampire number: Difference between revisions

m
→‎{{header|REXX}}: added more comments, optimized the function.
(→‎{{header|REXX}}: added/changed comments and whitespace, aligned the output, optimized the program and function.)
m (→‎{{header|REXX}}: added more comments, optimized the function.)
Line 2,946:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
vampire: procedure; parse arg ?x,, $. a bot; L= length(x) /*get arg; compute len L=of length(?)X*/
if L//2 then return '' /*Is L an odd length /*is L odd? Then ¬vampire.*/
do k=1 for L; _= substr(?x, k, 1); $._= $._ || _
end /*k*/
w= L % 2 /*%: is REXX's integer ÷ */
Line 2,955:
top= left( reverse(bot), w)
bot= left(bot, w) /*determine limits of search*/
inc= ?x // 2 + 1 /*?X is odd? INC=2. No? INC=1*/
beg= max(bot, 10**(w-1) ) /*calculate where to start.*/
if inc==2 then if beg//2==0 then beg= beg + 1 /*possibly adjust the start.*/
/* [↑] odd BEG if odd INC*/
do d=beg to min(top, 10**w - 1) by inc /*use smart start, end, inc.*/
if ?x // d \==0 then iterate /*?X not ÷ by D? Then skip,*/
q= ?x % d; if d>q then iterate /*is D > Q Then skip.*/
if q*d//9 \== (q+d)//9 then iterate /*modulo 9 congruence test. */
if length(q) \==w then iterate /*Len of Q ^¬= W? Then skip.*/
ifparse var right(q, '' -1) _ ==0 then if right(d, 1) ==0 then iterate /*get last decimal dig. of Q*/
if _==0 then if right(d, 1) ==0 then iterate
dq= d || q
t= ?x; do i=1 for L; p= pos( substr(dq, i, 1), t)
if p==0 then iterate d; t= delstr(t, p, 1)
end /*i*/