summaryrefslogtreecommitdiff
path: root/ipl/gpacks/weaving/comb.icn
blob: 2ca4af6b836ee15ff576910e85ff8aa584aae6e8 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
############################################################################
#
#	File:     plexity.icn
#
#	Subject:  Program to count distinct weaves
#
#	Author:   Ralph E. Griswold
#
#	Date:     April 5, 1999
#
############################################################################
#
#  This file is in the public domain.
#
############################################################################
#
#  This program counts the distinct weaves with k color, m warp threads,
#  and n wft threads.
#
#  The options supported are:
#
#	-k i	number of colors; default 2 (the maximum supported is 10)
#	-m i	number of warp threads (columns); default 2
#	-n i	number of weft threads (rows); default 2
#
#  To allow k up to 10 (temporary), the representation of colors goes
#  from 0 to k - 1.
#
############################################################################
#
#  Links:  options
#
############################################################################

link options

procedure main(args)
   local opts, k, m, n

   opts := options(args, "k+n+m+")

   k := \opts["k"] | 2
   m := \opts["m"] | 2
   n := \opts["n"] | 2

   plexity(k, m, n)

end

# weaves for k combinations on an m-by-n grid
#
# presently limited to 10 combinations ...

procedure plexity(k, m, n)
   local warps, wefts, boards, weaves

   warps := []
   every put(warps, combinations(k, m))

   wefts := []
   every put(wefts, combinations(k, n))

   boards := []
   every put(boards, combinations(2, n * m))

#  weaves := set()
   weaves := []

#  every insert(weaves, weave(!warps, !wefts, !boards))
   every put(weaves, weave(!warps, !wefts, !boards))

#  write(*weaves)

   every write(!weaves)

end

procedure combinations(k, n)	#: all combinations of k characters n times

   if n = 0 then return ""

   suspend (0 to k - 1) || combinations(k, n - 1)

end

procedure weave(warp, weft, board)
   local n, m, weaving

   weaving := board

   every n := 1 to *weft do
      every m := 1 to *warp do
         weaving[m + n - 1] := if weaving[m + n - 1] == "0"
            then weft[n] else warp[m]

   return weaving

end