Last active
April 27, 2018 02:32
-
-
Save shhyou/cffcaafe0fe6bb410a60a0f8aaf44701 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bun [] = [] | |
bun (x:xs) | x `elem` xs = bun xs | |
| otherwise = x : bun xs | |
nub :: Eq a => [a] -> [a] | |
nub = reverse . bun . reverse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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