From: William James Date: 2005-12-06T10:37:34+09:00 Subject: Re: Speed Golf - Remove Early Dups Phrogz wrote: > SUMMARY > What's the fastest and/or shortest you can turn this: > in = ["i", "v", "w", "e", "l", "d", "u", "f", "e", "v", "f", "e", > "d", "e", "w", "d"] > > into this: > ["i", "l", "u", "v", "f", "e", "w", "d"] > ? > > > DETAILS > The goal is, given a stream of items, to produce the same ordered > stream with no duplicates, where the relative position of the last item > wins. The shortest (and fastest?) for me turns out to be simply: > in.reverse.uniq.reverse > .... > The input for me isn't REALLY an array, but rather a series of items > that I receive one at a time from a depth-first traversal of a graph. > If this influences your answer, so be it :) In = ["i", "v", "w", "e", "l", "d", "u", "f", "e", "v", "f", "e", "d", "e", "w", "d"] out = [] In.each{ |x| out.delete( x ); out << x } p out