RosettaCodeData/Task/Amb/NetRexx/amb.netrexx

72 lines
2.5 KiB
Plaintext

/* REXX **************************************************************
* 25.08.2013 Walter Pachl derived from REXX version 2
*********************************************************************/
w=''
l=0
mm=0
mkset(1,'the that a if',w,mm,l)
mkset(2,'frog elephant thing',w,mm,l)
mkset(3,'walked treaded grows trots',w,mm,l)
mkset(4,'slowly quickly',w,mm,l)
show(w,mm,l)
Loop i=1 to 3 /* loop over sets */
k=i+1 /* the following set */
Loop ii=1 To 10 /* loop over elements in set k*/
If w[i,ii].words=i Then Do /* a sentence part found */
Loop jj=1 To 10 /* loop over following words */
If w[i,ii].right(1)=w[k,jj].left(1) Then Do /* fitting */
ns=w[i,ii]' 'w[k,jj] /* build new sentence (part) */
If ns.words=k Then /* 'complete' part */
add(w,k,ns) /* add to set k */
End
End
End
End
End
Say 'Results:'
Loop jj=1 To 10 /* show the results */
If w[4,jj].words=4 Then
Say '-->' w[4,jj]
End
method add(w,k,s) public static
/*********************************************************************
* add a fitting sentence (part) s to set w[k,*]
*********************************************************************/
Loop i=1 To 10 While w[k,i]>'' /* look for an empty slot */
End
w[k,i]=s /* add the sentence (part) */
Return
method mkset(n,arg,smp,mm,l) public static
/*********************************************************************
* create set smp[n,*] from data in arg
* mm[0] maximum number of elements in any set
* l[n] maximum word length in set n
*********************************************************************/
loop i = 1 to arg.words
smp[n,i] = arg.word(i)
If smp[n,i].length>l[n] Then
l[n]=smp[n,i].length
end
if i-1>mm[0] Then Do
mm[0]=i-1
End
return
method show(w,mm,l) public static
/*********************************************************************
* show the input
*********************************************************************/
Say 'Input:'
Loop j=1 To mm[0] /* output lines */
ol=''
Loop i=1 To 4
ol=ol w[i,j].left(l[i])
End
Say ol.strip
End;
say ''
Return