Skip to content

Instantly share code, notes, and snippets.

@shhyou
Last active April 27, 2018 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shhyou/cffcaafe0fe6bb410a60a0f8aaf44701 to your computer and use it in GitHub Desktop.
Save shhyou/cffcaafe0fe6bb410a60a0f8aaf44701 to your computer and use it in GitHub Desktop.
bun [] = []
bun (x:xs) | x `elem` xs = bun xs
| otherwise = x : bun xs
nub :: Eq a => [a] -> [a]
nub = reverse . bun . reverse
append3(XS, YS, ZS, OS) :- append(XS, WS, OS), append(YS, ZS, WS).
% nub(PS ++ (Q:QS) ++ (Q:RS)) = nub(PS ++ (Q:QS) ++ RS)
nub(XS, OS) :- append3(PS, [Q|QS], [Q|RS], XS), !,
append3(PS, [Q|QS], RS, YS),
nub(YS, OS).
nub(XS, XS).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment