blob: 157dd520e19cb74285e19b24d29e8e4ae34f525f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
-- Gnome sort for christmas ;3
gnomeSort :: Ord a => [a] -> [a]
gnomeSort = gs []
gs :: Ord a => [a] -> [a] -> [a]
gs [] (x:front) = gs [x] front
gs (p:back) (q:front) | p <= q = gs (q:p:back) front
gs (p:back) (q:front) | p > q = gs back (q:p:front)
gs xs [] = reverse xs
main :: IO ()
main = do
ls <- getContents
let ns = map (map read . words) . lines $ ls
let xs = map head ns
let ys = map last ns
let ms = zipWith ((abs .) . (-)) (gnomeSort xs) (gnomeSort ys)
print (sum ms)
|