Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- checkFlag :: Ord a => [a] -> Int -> Bool -> [a]
- checkFlag l i f =
- if f
- then check l i False
- else l
- check :: Ord a => [a] -> Int -> Bool -> [a]
- check l i f =
- if l !! i > l !! (i + 1)
- then swap l i
- else checkEnd l i f
- swap :: Ord a => [a] -> Int -> [a]
- swap l i =
- checkEnd (take i l ++ [l !! (i + 1)] ++ [l !! i] ++ drop (i + 2) l) i True
- checkEnd :: Ord a => [a] -> Int -> Bool -> [a]
- checkEnd l i f =
- if (i + 2) == length l
- then checkFlag l 0 f
- else check l (i + 1) f
- main :: IO ()
- main = print $ checkFlag [500,499 .. 0] 0 True
- -- real 0m7,509s
- -- user 0m7,468s
- -- sys 0m0,013s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement