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
|
############################################################################
#
# File: versum.icn
#
# Subject: Program to produce versum sequence
#
# Author: Ralph E. Griswold
#
# Date: August 12, 1995
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program writes the versum sequence for an integer to a file of a
# specified name. If such a file exists, it picks up where
# it left off, appending new values to the file.
#
# The supported options are:
#
# -s i The seed for the sequence, default 196
# -f s Name of file to extend, no default
# -F s Name of file, default <i>.vsq, where <i> is the
# seed of the sequence
# -t i The number of steps to carry the sequence out to, default
# essentially unlimited
# -m i Stop when value equals or exceeds m; default no limit
#
# If both -f and -F are given, -f overrides.
#
############################################################################
#
# Links: options
#
############################################################################
link options
procedure main(args)
local start, output, input, i, opts, limit, name, max, count
opts := options(args, "t+s+m+f:F:")
start := (0 < \opts["s"]) | 196
limit := \opts["t"] | -1
max := opts["m"]
name := \opts["F"] | (start || ".vsq")
name := \opts["f"]
if input := open(name) then {
count := 0
while i := read(input) do {
if not integer(i) then exit() # link, not term
count +:= 1
if count > limit then exit()
}
close(input)
}
/i := start # in case file doesn't exist or is empty
if not integer(i) then stop("*** invalid data")
output := open(name, "a") | stop("*** cannot open file")
limit -:= \count
until (limit -:= 1) = -1 do {
i +:= reverse(i)
if i > \max then break
write(output, i := string(i))
}
end
|