22 lines
587 B
Haskell
22 lines
587 B
Haskell
import Part1
|
|
import Part2 (getSimilarityScore, getValueCounts)
|
|
import System.IO
|
|
|
|
main = do
|
|
inputs <- readFile "inputs.txt"
|
|
let (listA, listB) = parseFileString inputs
|
|
|
|
-- Solve part 1
|
|
let sortedListA = quickSort listA
|
|
let sortedListB = quickSort listB
|
|
let distances = [abs (a - b) | (a, b) <- zip sortedListA sortedListB]
|
|
let distance = sum distances
|
|
putStrLn "The solution to part 1 is: "
|
|
print distance
|
|
|
|
-- Solve part 2
|
|
let bMap = getValueCounts sortedListB
|
|
let score = getSimilarityScore sortedListA bMap
|
|
putStrLn "The solution to part 2 is: "
|
|
print score
|