From SETL to Python translation

cyberian bear cyberian_bear at
Mon Mar 12 05:19:07 CET 2001

Hi guys I have 2 programs below that I must have in Python but I have them
in SETL(whatever the hell that is) and I don't know anything about it. I
tried finding stuff about it on the web but all I found was two small,
irrelevant pages and no tutorials. The thing is, if at least I knew what the
'Euler path construction', or 'Prime factors' are, I could just program them
on my own without looking at the SETL code, but i don't. Basically I just
want to ask some good soul if he could translate these two programs for me
from SETL to Python. I know chances of finding anyone who knows SETL are
negligibe but i guess it's worth a try.
I just want to thank anyone in advance if someone decides to help me. If not
that's OK I understand it's a lot to ask for.
Well. Thanx a lot guys.
PS: my e-mail is cyberian_bear at
program Euler;    -- Eulerian path construction

    graph := {[1,2], [2,3], [3,4], [4,1], [4,2]};             -- a small
    print(euler_path(graph + {[y, x]: [x, y] in graph}));        -- which is

    procedure Euler_path(G);                -- constructs Eulerian path for
graph G

        nodes := domain(G);                        -- all nodes in the

        if #(odds := {x in nodes | odd(#G{x})}) > 2 then
            return OM;      -- since more than two nodes are
        end if;             -- touched by an odd number of edges

                        -- odds is the set of all nodes of G that
                        -- are touched by an odd number of edges
        x := arb(odds)?arb(nodes);      -- pick a node of odds if possible
                                        -- otherwise pick any node of G

        path := [x] + build_path(x,G);

        while exists z = path(i) | G{z} /= {} loop
            new_p := build_path(z, G); -- insert new section into path
            G -:= ({[y,x]: [x,y] in new_p} + {e: e in new_p});
            path := path(i..i - 1) + new_p + path(i..);
        end loop;

        return path;

    end Euler_path;

    procedure build_path(x, rw G);        -- builds maximal path section
starting at x,
                                          -- and deletes all edges traversed

        p := [ ];

         while (y := arb G{x}) /= OM loop
                 -- while there exists an edge leaving the last point
            p with:= y;                 -- extend path to traverse the edge
            G -:= {[x, y], [y, x]};        -- delete the edge just traversed
            x := y;                        -- step to y
        end loop;

        return p;

    end build_path;

end euler;
package body prime_factors_pak;

    procedure prime_factors(n);            -- get tuple  of prime factors of

        facts := [];        -- will collect

        while even(n) loop facts with:= 2; n /:= 2; end loop;        -- even

        while exists k in [3,5..ceil(sqrt(float(n)))] | n mod k = 0 loop

            facts with:= k; n /:= k;        -- smallest remaining  factor,
up to sqrt(n)

        end loop;

       facts with:= n;            -- the final factor

        return facts;

    end prime_factors;

end prime_factors_pak;

More information about the Python-list mailing list