projects
/
advent-of-code-22.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Optimised day 19
[advent-of-code-22.git]
/
advent03
/
Main.hs
diff --git
a/advent03/Main.hs
b/advent03/Main.hs
index 409ca338c6cc396c83e41b9ab1be4b055582cf50..fa01d402ccce5337f514a1e5740394afb2488628 100644
(file)
--- a/
advent03/Main.hs
+++ b/
advent03/Main.hs
@@
-1,6
+1,6
@@
-- Writeup at https://work.njae.me.uk/2022/12/03/advent-of-code-2022-day-3/
-- Writeup at https://work.njae.me.uk/2022/12/03/advent-of-code-2022-day-3/
-import
System.Environment
+import
AoC
import Data.Char
import qualified Data.Set as S
import Data.List
import Data.Char
import qualified Data.Set as S
import Data.List
@@
-17,16
+17,6
@@
main =
print $ part1 rucksacks
print $ part2 rucksacks
print $ part1 rucksacks
print $ part2 rucksacks
-getDataFileName :: IO String
-getDataFileName =
- do args <- getArgs
- progName <- getProgName
- let baseDataName = if null args
- then progName
- else head args
- let dataFileName = "data/" ++ baseDataName ++ ".txt"
- return dataFileName
-
part1 :: [Rucksack] -> Int
part1 = sum . fmap (priority . commonItem)
part1 :: [Rucksack] -> Int
part1 = sum . fmap (priority . commonItem)
@@
-57,5
+47,5
@@
commonItem (Rucksack contents1 contents2) = S.findMin (c1 `S.intersection` c2)
priority :: Char -> Int
priority item
priority :: Char -> Int
priority item
- | i
tem >= 'a'
= ord item - ord 'a' + 1
+ | i
sLower item
= ord item - ord 'a' + 1
| otherwise = ord item - ord 'A' + 27
| otherwise = ord item - ord 'A' + 27