1. Re: permutation

On 1 Jun 2002, at 0:43, rforno at tutopia.com wrote:

> 
> Kat:
> I was unable to find mesh.e in the archives. Can you tell me where is it?

Hmm,, i thought it was there. It was a 
<bright flashing colored lights and strobes>
Jiri_Special
</bright flashing colored lights and strobes>
function. I use it in error detection and alternative-finding. Since it was
posted
to the list (2 years ago!!), i spose i can repost it. I don't think it returns 
duplicates, i could be wrong, i do use a duplicate remover in code anyhow, 
and dropped this in, pretty much unchanged, before the dupe-remover code. 
Here is Jiri's code with a demo:


--  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

print(1,s)
puts(1,"\n\n")
    n = length(s)
    for i=1 to n do
      if sequence(s[i][2]) then
        s[i] = strip(s[i])
      end if
    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\nDone\n")
object junk
junk = wait_key()

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu