finish day three
This commit is contained in:
parent
018d194796
commit
2fc2e7351e
11
three.hs
11
three.hs
|
@ -1,3 +1,4 @@
|
|||
import Data.Char
|
||||
|
||||
splitlist :: [a] -> ([a],[a])
|
||||
splitlist list = (take n list,drop n list)
|
||||
|
@ -8,8 +9,14 @@ inBoth (first,second) = do
|
|||
inFirst <- first
|
||||
if (inFirst `elem` second) then return inFirst else []
|
||||
|
||||
|
||||
toPriority :: Char -> Int
|
||||
toPriority char = ordNum - (substract ordNum)
|
||||
where
|
||||
ordNum = (ord char)
|
||||
substract n
|
||||
| n < 97 = 38
|
||||
| otherwise = 96
|
||||
|
||||
main = do
|
||||
input <- readFile "three-input.txt"
|
||||
print $ map ( inBoth . splitlist ) $ lines input
|
||||
print $sum $ map (toPriority . head . inBoth . splitlist ) $ lines input
|
||||
|
|
22
three2.hs
Normal file
22
three2.hs
Normal file
|
@ -0,0 +1,22 @@
|
|||
import Data.Char
|
||||
import Data.List.Split
|
||||
|
||||
|
||||
inAll :: [String] -> [Char]
|
||||
inAll [first,second,third] = do
|
||||
eachChar <- first
|
||||
if (eachChar `elem` second && eachChar `elem` third) then return eachChar else []
|
||||
|
||||
|
||||
toPriority :: Char -> Int
|
||||
toPriority char = ordNum - (substract ordNum)
|
||||
where
|
||||
ordNum = (ord char)
|
||||
substract n
|
||||
| n < 97 = 38
|
||||
| otherwise = 96
|
||||
|
||||
main = do
|
||||
input <- readFile "three-input.txt"
|
||||
print $sum $ map (toPriority . head . inAll ) $ chunksOf 3 $ lines input
|
||||
--print $map ( inAll ) $ chunksOf 3 $ lines input
|
Loading…
Reference in a new issue