home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / OL.LZH / PROCS.LZH / PATWORD.ICN < prev    next >
Text File  |  1991-07-13  |  1KB  |  41 lines

  1. ############################################################################
  2. #
  3. #    Name:    patword.icn
  4. #
  5. #    Title:    Letter patterns in words
  6. #
  7. #    Author:    Kenneth Walker
  8. #
  9. #    Date:    June 10, 1988
  10. #
  11. ############################################################################
  12. #
  13. #     The procedure patword(s) returns a letter pattern in which each
  14. #  different character in s is assigned a letter.  For example,
  15. #  patword("structural") returns "abcdedbcfg".
  16. #
  17. ############################################################################
  18.  
  19. procedure patword(s)
  20.     local numbering, orderS, orderset, patlbls
  21.     static labels, revnum
  22.  
  23.     initial {
  24.     labels := &lcase || &lcase
  25.     revnum := reverse(&cset)
  26.     }
  27.  
  28. # First map each character of s into another character, such that the
  29. # the new characters are in increasing order left to right (note that
  30. # the map function chooses the rightmost character of its second
  31. # argument, so things must be reversed.
  32. #
  33. # Next map each of these new characters into contiguous letters.
  34.  
  35.     numbering := revnum[1 : *s + 1] | stop("word too long")
  36.     orderS := map(s, reverse(s), numbering)
  37.     orderset := string(cset(orderS))
  38.     patlbls := labels[1 : *orderset + 1] | stop("too many characters")
  39.     return map(orderS, orderset, patlbls)
  40. end
  41.