On Thu, 2004-06-10 at 09:45, Steve Wampler wrote:
...
> Steve Hunter has pointed out a solution found in an old issue
> of the Icon Newsletter (Issue 18, from 1985!):
...
> procedure anagram(s)
>     local c, s1
> 
>     s1 := ""               # start with the empty string
>     every c := !cset(s) do # for every character in s
>         every find(c,s) do     # and every time it occurs in s
>             s1 ||:= c              # append one
>     return s1
> end

Looking at this, one advantage it has is that avoids some
type coercions that occur in some of the other solutions
(such as mine).  Here's adaptations of my solutions 1 and 3
taking advantage of lessons learned from the above:

Solution 1a:

    procedure ssort(s)
        s ?  every (ns:="") ||:= (find(c := !cset(s)),c)
        return ns
    end

Solution 3a (dictonary order):

    procedure ssort(s)
        map(s) ?  every (ns:="") ||:= s[find(!cset(map(s)))]
        return ns
    end

> And here are its times:
(fixed the typo above...)
> 
> Case 1:
> weaver% RunTests
> ------------------ icon18 -----------------------
>         1.48s user 0.23s system 100% cpu 1.705 total
> 
> Case 2:
> weaver% RunTests --infile=input2.txt --valid=valid3.txt
> ------------------ icon18 -----------------------
>        3.60s user 0.07s system 99% cpu 3.687 total

And the times for solution 1a are:

Case 1:
weaver% RunTests
------------------ Steve Wampler (1a) -----------------------
        1.41s user 0.30s system 100% cpu 1.708 total

Case 2:

weaver% RunTests --infile=input2.txt --valid=valid3.txt
------------------ Steve Wampler (1a) -----------------------
        3.50s user 0.11s system 99% cpu 3.610 total


-- 
Steve Wampler -- [EMAIL PROTECTED]
The gods that smiled on your birth are now laughing out loud.


-------------------------------------------------------
This SF.Net email is sponsored by the new InstallShield X.
>From Windows to Linux, servers to mobile, InstallShield X is the
one installation-authoring solution that does it all. Learn more and
evaluate today! http://www.installshield.com/Dev2Dev/0504
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to