From: "David A. Black" Date: 2005-12-06T12:16:34+09:00 Subject: Re: Speed Golf - Remove Early Dups Hi -- On Tue, 6 Dec 2005, 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 This entry is not in contention on shortness or speed (don't even bother to benchmark it -- it's completely off the charts), but I just thought it looked really cool :-) a.inject([]){|r,*b|r-b+b} David __ David A. Black dblack@wobblini.net "Ruby for Rails", forthcoming from Manning Publications, April 2006!