Nhc98

From HaskellWiki
Revision as of 10:57, 12 August 2012 by Chandan (talk | contribs) (Here is a program to form a new list from two given lists such that a term appears in this new list iff it appeared in exactly one of those two lists. It takes O(nlog n) time.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

uncommon :: [Int]->[Int]->[Int] uncommon x y=common (finalsort (x++y))

common :: [Int]->[Int] common []=[] common [x]=[x] common (x:y:zs)

| (x==y) =common zs
| otherwise =x:(common (y:zs))

sort :: [Int]->[Int]->[Int] sort [] x=x sort x []=x sort (x:xs) (y:ys)

| (x>=y) =x:(sort xs (y:ys))
| otherwise =y:(sort (x:xs) ys)

finalsort :: [Int]->[Int] finalsort [x]=[x] finalsort x=sort (finalsort (first x)) (finalsort (lastest x))

mylength :: [Int]->Int mylength []=0 mylength (x:xs)=1+ mylength xs

auxfirst :: [Int]->Int->[Int] auxfirst x 0=[] auxfirst (y:ys) x=y:(auxfirst ys (x-1))

first :: [Int]->[Int] first x=auxfirst x (div (mylength x) 2)

auxlast :: [Int]->Int->[Int] auxlast x 0=x auxlast (x:xs) y=auxlast xs (y-1)

lastest :: [Int]->[Int] lastest x=auxlast x (div (mylength x) 2)