
5 Jun
2009
5 Jun
'09
11:21 a.m.
Thomas ten Cate wrote:
Possible, yes.
Efficient, not really.
inTwain = foldr (\x (ls, rs) -> if length ls == length rs then (x:ls, rs) else (x:(init ls), (last ls):rs)) ([], [])
But this uses length and init and last all of which are recursive functions. I consider that cheating: only foldr may do the recursion. Martijn.