fork download
  1. input = [1, 3, 2, 0, 5]
  2.  
  3. find xs = find' ([], []) xs
  4. where find' _ [] = []
  5. find' s@([m], [a,b]) (c:xs)
  6. | c > b = [a,b,c]
  7. | c < m = find' ([c], [a,b]) xs
  8. | c < a = find' ([m], [m,a]) xs
  9. | c < b = find' ([m], [a,c]) xs
  10. | otherwise = find' s xs
  11. find' s@([m], [_]) (c:xs)
  12. | c < m = find' ([c], [c]) xs
  13. | otherwise = find' s xs
  14. find' ([], []) (c:xs) = find' ([c], [c]) xs
  15.  
  16. main = print $ find input
Success #stdin #stdout 0.01s 3592KB
stdin
Standard input is empty
stdout
[]