1. Flat sequence - String detection
How would you detect if a sequence was 1 dimensional?
----------flattest.ex---------------------------------
--Would you use this?
type old_flat(sequence s)
for A = 1 to length(s) do
if sequence(s[A]) then
return 0
end if
end for
return 1
end type
-- OR did you know you could do this?
type flat(sequence s)
return equal(repeat(0, length(s)), (s * 0))
end type
atom speed, cnt
puts(1, "speed test...")
cnt = 0
speed = time() + 5
while (speed > time()) do
cnt += 1
end while
speed = floor((cnt/5)/100)
printf(1, "\r iterations = %d\n\n", speed)
procedure test(sequence s)
atom t
integer i
if (flat(s) != old_flat(s)) then
puts(1, "sanity failure\n")
end if
t = time()
for A = 1 to (speed) do
i = flat(s)
end for
t = time() - t
printf(1, "flat\t\t: %4.2f\n", t)
t = time()
for A = 1 to (speed * 5) do
i = old_flat(s)
end for
t = time() - t
printf(1, "old_flat\t: %4.2f\n\n", t)
end procedure
puts(1, "test append({}, \"1000 random bytes\")\n")
test(append({}, rand(repeat(256, 1000))-1))
puts(1, "test append(\"1000 random bytes\", {})\n")
test(append(rand(repeat(256, 1000))-1, {}))
puts(1, "test \"1000 random bytes\"\n")
test(rand(repeat(256, 1000))-1)
puts(1, "test \"1000 random floats\"\n")
test(rand(repeat(65536, 1000))/rand(repeat(65536, 1000)))
puts(1, "test append(\"1000 random floats\", {})\n")
test(append(rand(repeat(65536, 1000))/rand(repeat(65536, 1000)), {}))
puts(1, "Press any key to continue...")
while get_key() = -1 do end while
----------flattest.ex---------------------------------
Lucius L. Hilley III
lhilley at cdc.net
+----------+--------------+--------------+
| Hollow | ICQ: 9638898 | AIM: LLHIII |
| Horse +--------------+--------------+
| Software | http://www.cdc.net/~lhilley |
+----------+-----------------------------+