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
99
100
101
102
103
104
105
106
107
108
109
110
111
|
############################################################################
#
# File: dd2draft.icn
#
# Subject: Program to create draft information from drawdown
#
# Author: Ralph E. Griswold
#
# Date: November 16, 2001
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program reads a drawdown in terms of rows of zeros and ones from
# standard input and outputs draft information in textual form.
#
# It also accepts BLPs as input.
#
############################################################################
#
# Links: patutils. patxform
#
############################################################################
link patutils
link patxform
record analysis(rows, sequence, patterns)
procedure main()
local threading, treadling, rows, columns, pattern, i
local symbols, symbol, tieup, line
line := read() | stop("empty file")
if upto("#", line) then rows := pat2rows(line)
else {
rows := [line]
while put(rows, read()) # read in row pattern
}
write("Drawdown:")
write()
every write(!rows)
write()
treadling := analyze(rows)
write("Treadling:")
write()
every writes(!treadling.sequence, ", ")
write()
write()
columns := protate(rows) # rotate 90 degrees
threading := analyze(columns)
write("Threading:")
write()
every writes(!threading.sequence, ", ")
write()
write()
# Now do the tie-up.
symbols := table("")
every pattern := !treadling.patterns do {
symbol := treadling.rows[pattern]
symbols[symbol] := repl("0", *threading.rows)
pattern ? {
every i := upto('1') do
symbols[symbol][threading.sequence[i]] := "1"
}
}
symbols := sort(symbols, 3)
tieup := []
while get(symbols) do
put(tieup, get(symbols))
write("Tie-up:")
write()
every write(!tieup)
end
procedure analyze(drawdown)
local sequence, rows, row, count, patterns
sequence := []
patterns := []
rows := table()
count := 0
every row := !drawdown do {
if /rows[row] then {
rows[row] := count +:= 1
put(patterns, row)
}
put(sequence, rows[row])
}
return analysis(rows, sequence, patterns)
end
|