I like this one! Here's a variant using fold:
lastk :: Int -> [a] -> [a] lastk k xs = foldl' (const.tail) xs (drop k xs) or point free: lastk = ap (foldl' (const. tail)). drop Hallo Luke Palmer, je schreef op 18-09-10 22:42: > I think this is O(n) time, O(1) space (!). > > lastk :: Int -> [a] -> [a] > lastk k xs = last $ zipWith const (properTails xs) (drop k xs) > where properTails = tail . tails > > -- Met vriendelijke groet, =@@i _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
