Re: my brain block

new topic     » goto parent     » topic index » view thread      » older message » newer message

Kat,

Have a look at the routine below. Is it what you wanted?
You will need Gabriel's pretty print include for a prettier output.

jiri


--  kat.ex
--  jiri babor
--  jiri_babor at hotmail.com
--  00-08-10

include print.e     -- Gabriel's extension

function strip(sequence s)
--  return sequence s with empty substrings removed
    sequence v,si

    v = {}
    for i=1 to length(s) do
        si = s[i]
        if length(si) then
            v = append(v, si)
        end if
    end for
    return v
end function

function mesh(sequence s)
    sequence u,v
    integer n

    n = length(s)
    for i=1 to n do
        s[i] = strip(s[i])
    end for

    v = {}
    for i=1 to length(s[1]) do
        v = append(v, {s[1][i]})
    end for
    for i=2 to n do
        u = v
        v = {}
        for j=1 to length(u) do
            for k=1 to length(s[i]) do
                v = append(v, append(u[j], s[i][k]))
            end for
        end for
    end for
    return v
end function

-- test --------------------------------------------------------------

constant sa = {"one","","three","","","six"}
constant sb = {"1","2","","","5",""}
constant sc = {"uno","dos","tres","cinco",""}

print(1, mesh({sa,sb}))
puts(1, "\n\n")
print(1, mesh({sa,sb,sc}))
puts(1, '\n')

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu