Difference between revisions of "Nhc98"

From HaskellWiki
Jump to: navigation, search
m
m
 
Line 39: Line 39:
 
lastest x=auxlast x (div (mylength x) 2)
 
lastest x=auxlast x (div (mylength x) 2)
 
</haskell>
 
</haskell>
  +
  +
[[Category:Pages under construction]]

Latest revision as of 04:14, 18 June 2021

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)