ABC problem: Difference between revisions

→‎version 1: re-instated REXX version 1 (and it's OUTPUT) after being reverted (or UNDOne) by someone/something. -- ~~~~
No edit summary
(→‎version 1: re-instated REXX version 1 (and it's OUTPUT) after being reverted (or UNDOne) by someone/something. -- ~~~~)
Line 384:
<lang rexx>/*REXX pgm checks if some words can be spelt from a pool of toy blocks. */
blocks = 'BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM'
list = 'A baRkbark bOOk trEattreat coMMoncommon squaD conFuse' /*words can be any case.*/
do k=01 tofor words(list) /*traipse through list of words. */
if k==0call thenspell call can_make_word ''word(list,k) /*performshow if aword be NULLspelt (or testnot).*/
end /*k*/ else call can_make_word word(list,k) /*···a vanilla[↑] testtests each word in list. */
end /*k*/
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────SPELL subroutine────────────────────*/
/*──────────────────────────────────CAN_MAKE_WORD subroutine────────────*/
can_make_wordspell: procedure expose blocks; parse arg ox . 1 x . /*X:get the word to be built. */
z=' ' blocks; " "; upper x z=translate(z); oz=z; L=length(x) /*paduppercase pool,the uppercaseblocks. it*/
try=0; n=0; OK=0; L=length(x); trip=L*L+L /*set some REXX vars. */
/* [↓] try to spell it.*/
do try=1 while try<trip*2; n=n+1 /*bump thepointer characterto ptrletter*/
y=substr(x,n,1) /*find particular letter*/
if try>trip then do; z=oz; n=0; iterate; end /*use a fresh copy of Z?*/
Line 402 ⟶ 401:
if p==0 then do; n=0; iterate; end /*Not found? Try again.*/
z=overlay(' ',z,p) /*transform block─► 1-sy*/
do k=1 for words(zblocks); _=word(z,k) /*scrub block pool (¬1s)*/
if length(_word(z,k))==1 then z=delword(z,k,1) /*is block 1 char?*/
end /*k*/ end /*k*/ /* [↑] elide any 1─sy.*/
OK= n==L /*athe flag:last letter spelt or not.?*/
if OK then leave /*allYes? the lettersThen found?word spelt.*/
end /*n*/
 
ifsay x=='' then x="right(nullox,30)" right(word("can't can", OK+1), 6) 'be /*express a NULL betterspelt.*/'
say right(x,30) right(word("can't can", OK+1), 6) 'be spelt.'
return OK /*also, return the flag.*/</lang>
'''output'''
{{out}}
<!-- Spelling note: "spelt" is an alternate version of "spelled". -->
<pre>
(null) can't be spelt.
A can be spelt.
BARKbark can be spelt.
BOOKbOOk can't be spelt.
TREATtreat can be spelt.
COMMONcommon can't be spelt.
SQUADsquaD can be spelt.
CONFUSEconFuse can be spelt.
</pre>