diff --git a/1/Skit.hs b/1/Skit.hs new file mode 100644 index 0000000..9d7216f --- /dev/null +++ b/1/Skit.hs @@ -0,0 +1,33 @@ +import Data.List (sort, transpose) + +main :: IO () +main = do + input <- readFile "./input" + putStrLn (solve input) + +solve :: String -> String +solve input = show (riktigaSolve (parseInput input)) + +--splitString :: String -> [String] +--splitString input = lines input + +parseInput :: String -> [[Int]] +parseInput input = transpose (stringToIntList (lines input)) + where + getPairs :: String -> [Int] + getPairs line = map stringToInt (words line) + + stringToInt :: String -> Int + stringToInt input = read input + + stringToIntList :: [String] -> [[Int]] + stringToIntList input = map getPairs input + +riktigaSolve :: [[Int]] -> Int +riktigaSolve [left,right] = svaret + where + sortedLeft = sort left + sortedRight = sort right + absedList = map (\(x, y) -> abs(x - y)) (zip sortedLeft sortedRight) + svaret = sum absedList +riktigaSolve fuckedShit = error "hlvetes textfil"