diff options
author | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-03 22:06:37 +0100 |
---|---|---|
committer | Laura Orvokki Kursula <lav@vampires.gay> | 2024-12-03 22:06:37 +0100 |
commit | 818e93ec4aa870d020be71981d4c2d1d72390ed2 (patch) | |
tree | 3d5a736391f4beb82fbbfbe8dd1c2aa3b77551bc | |
download | aoc2024-818e93ec4aa870d020be71981d4c2d1d72390ed2.tar.gz aoc2024-818e93ec4aa870d020be71981d4c2d1d72390ed2.zip |
1-1
-rw-r--r-- | 1-1.hs | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -0,0 +1,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) |