Nhc98 - Revision history
https://wiki.haskell.org/index.php?title=Nhc98&action=history
Revision history for this page on the wikienMediaWiki 1.19.14+dfsg-1Tue, 26 Jul 2016 21:42:13 GMTChandan: 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.
https://wiki.haskell.org/index.php?title=Nhc98&diff=48648&oldid=prev
https://wiki.haskell.org/index.php?title=Nhc98&diff=48648&oldid=prev<p>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.</p>
<p><b>New page</b></p><div>uncommon :: [Int]->[Int]->[Int]<br />
uncommon x y=common (finalsort (x++y))<br />
<br />
common :: [Int]->[Int]<br />
common []=[]<br />
common [x]=[x]<br />
common (x:y:zs)<br />
| (x==y) =common zs<br />
| otherwise =x:(common (y:zs))<br />
<br />
sort :: [Int]->[Int]->[Int]<br />
sort [] x=x<br />
sort x []=x<br />
sort (x:xs) (y:ys)<br />
| (x>=y) =x:(sort xs (y:ys))<br />
| otherwise =y:(sort (x:xs) ys)<br />
<br />
finalsort :: [Int]->[Int]<br />
finalsort [x]=[x]<br />
finalsort x=sort (finalsort (first x)) (finalsort (lastest x))<br />
<br />
mylength :: [Int]->Int<br />
mylength []=0<br />
mylength (x:xs)=1+ mylength xs<br />
<br />
auxfirst :: [Int]->Int->[Int]<br />
auxfirst x 0=[]<br />
auxfirst (y:ys) x=y:(auxfirst ys (x-1))<br />
<br />
first :: [Int]->[Int]<br />
first x=auxfirst x (div (mylength x) 2)<br />
<br />
auxlast :: [Int]->Int->[Int]<br />
auxlast x 0=x<br />
auxlast (x:xs) y=auxlast xs (y-1)<br />
<br />
lastest :: [Int]->[Int]<br />
lastest x=auxlast x (div (mylength x) 2)</div>Sun, 12 Aug 2012 10:57:50 GMTChandanhttps://wiki.haskell.org/Talk:Nhc98