
19 Sep
2010
19 Sep
'10
10:23 a.m.
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