diff options
author | Akshay <[email protected]> | 2020-12-05 05:48:34 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-12-05 05:48:34 +0000 |
commit | 4c0b08c857afb6f308e01c19e5df68b994617311 (patch) | |
tree | 84c840220268b7f2717677122dd8a4fc80fd7757 | |
parent | b2a0507e6418c7853651e4aa0759752eb67808f2 (diff) |
tidy up
-rw-r--r-- | aoc.cabal | 2 | ||||
-rw-r--r-- | execs/Day05.hs | 21 |
2 files changed, 8 insertions, 15 deletions
@@ -42,6 +42,6 @@ executable Day04 | |||
42 | 42 | ||
43 | executable Day05 | 43 | executable Day05 |
44 | main-is: Day05.hs | 44 | main-is: Day05.hs |
45 | build-depends: base, parsec | 45 | build-depends: base |
46 | default-language: Haskell2010 | 46 | default-language: Haskell2010 |
47 | hs-source-dirs: execs | 47 | hs-source-dirs: execs |
diff --git a/execs/Day05.hs b/execs/Day05.hs index 4251cd6..c018203 100644 --- a/execs/Day05.hs +++ b/execs/Day05.hs | |||
@@ -1,23 +1,16 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Text.ParserCombinators.Parsec | ||
4 | import Data.List (sort) | ||
5 | import Control.Monad | ||
6 | |||
7 | data Direction = Upper | Lower | 3 | data Direction = Upper | Lower |
8 | 4 | ||
9 | doHalving :: [Direction] -> (Int, Int) -> (Int, Int) | 5 | doHalf :: [Direction] -> (Int, Int) -> Int |
10 | doHalving [] p = p | 6 | doHalf ls start = fst $ foldl fn start ls |
11 | doHalving (Lower:rest) (l, u) = doHalving rest (l, (u+l) `div` 2) | 7 | where fn (l, u) Lower = (l, (u+l) `div` 2) |
12 | doHalving (Upper:rest) (l, u) = doHalving rest ((u+l) `div` 2 + 1, u) | 8 | fn (l, u) Upper = ((u+l) `div` 2 + 1, u) |
13 | |||
14 | findId :: (Int, Int) -> Int | ||
15 | findId (row, col) = row * 8 + col | ||
16 | 9 | ||
17 | doValidate :: String -> Int | 10 | doValidate :: String -> Int |
18 | doValidate s = findId (row, col) | 11 | doValidate s = row * 8 + col |
19 | where row = fst $ flip doHalving (0, 127) $ map readDir (take 7 s) | 12 | where row = flip doHalf (0, 127) $ map readDir (take 7 s) |
20 | col = fst $ flip doHalving (0, 7) $ map readDir (drop 7 s) | 13 | col = flip doHalf (0, 7) $ map readDir (drop 7 s) |
21 | 14 | ||
22 | readDir :: Char -> Direction | 15 | readDir :: Char -> Direction |
23 | readDir c | 16 | readDir c |