summaryrefslogtreecommitdiff
path: root/ipl/procs/patword.icn
blob: e8fd1d303f82686424d34e6b6f5afa09d2fce96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
############################################################################
#
#	File:     patword.icn
#
#	Subject:  Procedures to find letter patterns
#
#	Author:   Kenneth Walker
#
#	Date:     December 2, 1995
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#     The procedure patword(s) returns a letter pattern in which each
#  different character in s is assigned a letter.  For example,
#  patword("structural") returns "abcdebdcfg".
#
############################################################################

procedure patword(s)
    local numbering, orderS, orderset, patlbls
    static labels, revnum

    initial {
	labels := &lcase || &lcase
	revnum := reverse(&cset)
	}

# First map each character of s into another character, such that the
# the new characters are in increasing order left to right (note that
# the map function chooses the rightmost character of its second
# argument, so things must be reversed.
#
# Next map each of these new characters into contiguous letters.

    numbering := revnum[1 : *s + 1] | stop("word too long")
    orderS := map(s, reverse(s), numbering)
    orderset := string(cset(orderS))
    patlbls := labels[1 : *orderset + 1] | stop("too many characters")

    return map(orderS, orderset, patlbls)

end