diff options
author | Akshay <[email protected]> | 2020-12-16 07:27:38 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-12-16 07:27:38 +0000 |
commit | 8c1193fece01bb80e86d8cc36efcf8820a6ccb46 (patch) | |
tree | f13ed4cdb33e748f596db9b7e7a2b08d8b3ba0ef /execs | |
parent | 38f3a717b0f8095fb05b9be0bebd158474eb7618 (diff) |
format *
Diffstat (limited to 'execs')
-rw-r--r-- | execs/Day01.hs | 2 | ||||
-rw-r--r-- | execs/Day02.hs | 14 | ||||
-rw-r--r-- | execs/Day04.hs | 18 | ||||
-rw-r--r-- | execs/Day05.hs | 6 | ||||
-rw-r--r-- | execs/Day09.hs | 10 | ||||
-rw-r--r-- | execs/Day10.hs | 8 | ||||
-rw-r--r-- | execs/Day11.hs | 10 | ||||
-rw-r--r-- | execs/Day12.hs | 2 | ||||
-rw-r--r-- | execs/Day13.hs | 12 | ||||
-rw-r--r-- | execs/Day14.hs | 20 | ||||
-rw-r--r-- | execs/Day15.hs | 6 |
11 files changed, 54 insertions, 54 deletions
diff --git a/execs/Day01.hs b/execs/Day01.hs index 4a10259..2f50b27 100644 --- a/execs/Day01.hs +++ b/execs/Day01.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Control.Monad | 3 | import Control.Monad |
4 | 4 | ||
5 | main :: IO () | 5 | main :: IO () |
6 | main = do | 6 | main = do |
diff --git a/execs/Day02.hs b/execs/Day02.hs index 412d1d1..43f6e31 100644 --- a/execs/Day02.hs +++ b/execs/Day02.hs | |||
@@ -1,18 +1,18 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Text.ParserCombinators.Parsec | 3 | import Text.Parsec.Char |
4 | import Text.Parsec.Char | 4 | import Text.ParserCombinators.Parsec |
5 | import Utils | 5 | import Utils |
6 | 6 | ||
7 | type PassProp = (Int, Int, Char, String) | 7 | type PassProp = (Int, Int, Char, String) |
8 | 8 | ||
9 | parseInt :: Parser Int | 9 | parseInt :: Parser Int |
10 | parseInt = read <$> many1 digit | 10 | parseInt = read <$> many1 digit |
11 | parseProp :: Parser PassProp | 11 | parseProp :: Parser PassProp |
12 | parseProp = (,,,) | 12 | parseProp = (,,,) |
13 | <$> parseInt <* char '-' | 13 | <$> parseInt <* char '-' |
14 | <*> parseInt <* space | 14 | <*> parseInt <* space |
15 | <*> letter <* string ": " | 15 | <*> letter <* string ": " |
16 | <*> many letter | 16 | <*> many letter |
17 | 17 | ||
18 | doCheck1 :: PassProp -> Bool | 18 | doCheck1 :: PassProp -> Bool |
diff --git a/execs/Day04.hs b/execs/Day04.hs index a95dfd0..1834250 100644 --- a/execs/Day04.hs +++ b/execs/Day04.hs | |||
@@ -1,12 +1,12 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Text.ParserCombinators.Parsec | 3 | import Data.Char (isDigit, isHexDigit) |
4 | import Data.Map.Strict (Map, (!)) | 4 | import Data.Map.Strict (Map, (!)) |
5 | import qualified Data.Map.Strict as Map | 5 | import qualified Data.Map.Strict as Map |
6 | import Data.Char (isDigit, isHexDigit) | 6 | import Text.ParserCombinators.Parsec |
7 | import Utils | 7 | import Utils |
8 | 8 | ||
9 | requiredFields = [ "byr" , "iyr" , "eyr" , "hgt" , "hcl" , "ecl" , "pid" ] | 9 | requiredFields = [ "byr" , "iyr" , "eyr" , "hgt" , "hcl" , "ecl" , "pid" ] |
10 | eyeColors = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"] | 10 | eyeColors = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"] |
11 | 11 | ||
12 | block = cell `sepBy` oneOf " \n" | 12 | block = cell `sepBy` oneOf " \n" |
@@ -28,15 +28,15 @@ validEyr s = bet (read s :: Int) (2020, 2030) | |||
28 | validEcl = flip elem eyeColors | 28 | validEcl = flip elem eyeColors |
29 | validPid s = length s == 9 && all isDigit s | 29 | validPid s = length s == 9 && all isDigit s |
30 | validHcl ('#':rest) = length rest == 6 && all isHexDigit rest | 30 | validHcl ('#':rest) = length rest == 6 && all isHexDigit rest |
31 | validHcl _ = False | 31 | validHcl _ = False |
32 | validHgt s = | 32 | validHgt s = |
33 | let value = takeWhile isDigit s | 33 | let value = takeWhile isDigit s |
34 | unit = dropWhile isDigit s | 34 | unit = dropWhile isDigit s |
35 | height = (read value :: Int, unit) | 35 | height = (read value :: Int, unit) |
36 | in case height of | 36 | in case height of |
37 | (v, "cm") -> bet v (150, 193) | 37 | (v, "cm") -> bet v (150, 193) |
38 | (v, "in") -> bet v (59, 76) | 38 | (v, "in") -> bet v (59, 76) |
39 | _ -> False | 39 | _ -> False |
40 | 40 | ||
41 | doValidate :: Map String String -> Bool | 41 | doValidate :: Map String String -> Bool |
42 | doValidate map = all ((== True) . (\(s, v) -> v $ map ! s)) ls | 42 | doValidate map = all ((== True) . (\(s, v) -> v $ map ! s)) ls |
diff --git a/execs/Day05.hs b/execs/Day05.hs index a47c024..40965ec 100644 --- a/execs/Day05.hs +++ b/execs/Day05.hs | |||
@@ -1,8 +1,8 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Data.Char (digitToInt) | 3 | import Data.Char (digitToInt) |
4 | import Data.List (sort) | 4 | import Data.List (sort) |
5 | import Utils (binaryToInt) | 5 | import Utils (binaryToInt) |
6 | 6 | ||
7 | doValidate = binaryToInt . map readBin | 7 | doValidate = binaryToInt . map readBin |
8 | readBin s | s `elem` "FL" = '0' | 8 | readBin s | s `elem` "FL" = '0' |
diff --git a/execs/Day09.hs b/execs/Day09.hs index f1c41f2..7bf4908 100644 --- a/execs/Day09.hs +++ b/execs/Day09.hs | |||
@@ -1,9 +1,9 @@ | |||
1 | 1 | ||
2 | module Main where | 2 | module Main where |
3 | 3 | ||
4 | import Utils | 4 | import Data.Bifunctor |
5 | import Data.List (inits, tails, find, sort) | 5 | import Data.List (find, inits, sort, tails) |
6 | import Data.Bifunctor | 6 | import Utils |
7 | 7 | ||
8 | parseLine :: String -> Int | 8 | parseLine :: String -> Int |
9 | parseLine = read | 9 | parseLine = read |
@@ -13,12 +13,12 @@ doCheck preamble target = target `elem` p | |||
13 | where p = [x + y | x <- preamble, y <- preamble, x /= y] | 13 | where p = [x + y | x <- preamble, y <- preamble, x /= y] |
14 | 14 | ||
15 | checkAll :: [[Int]] -> [Int] -> [(Int, Bool)] | 15 | checkAll :: [[Int]] -> [Int] -> [(Int, Bool)] |
16 | checkAll = zipWith (\p t -> (t, doCheck p t)) | 16 | checkAll = zipWith (\p t -> (t, doCheck p t)) |
17 | 17 | ||
18 | findWeakness :: [[Int]] -> Int -> Int | 18 | findWeakness :: [[Int]] -> Int -> Int |
19 | findWeakness subs target = minimum t + maximum t | 19 | findWeakness subs target = minimum t + maximum t |
20 | where Just t = find ((== target) . sum) subs | 20 | where Just t = find ((== target) . sum) subs |
21 | 21 | ||
22 | main :: IO () | 22 | main :: IO () |
23 | main = do | 23 | main = do |
24 | n <- map parseLine . lines <$> readFile "input/09" | 24 | n <- map parseLine . lines <$> readFile "input/09" |
diff --git a/execs/Day10.hs b/execs/Day10.hs index 40d3d61..826fc65 100644 --- a/execs/Day10.hs +++ b/execs/Day10.hs | |||
@@ -1,10 +1,10 @@ | |||
1 | 1 | ||
2 | module Main where | 2 | module Main where |
3 | 3 | ||
4 | import Utils | 4 | import Control.Monad |
5 | import Data.List (sort) | 5 | import Control.Monad.Memo |
6 | import Control.Monad | 6 | import Data.List (sort) |
7 | import Control.Monad.Memo | 7 | import Utils |
8 | 8 | ||
9 | parseLine :: String -> Int | 9 | parseLine :: String -> Int |
10 | parseLine = read | 10 | parseLine = read |
diff --git a/execs/Day11.hs b/execs/Day11.hs index e2f138b..cca9fa0 100644 --- a/execs/Day11.hs +++ b/execs/Day11.hs | |||
@@ -1,10 +1,10 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Utils | 3 | import Data.List (sortOn) |
4 | import Data.List (sortOn) | 4 | import Data.Map (Map, (!)) |
5 | import Data.Map (Map, (!)) | 5 | import qualified Data.Map as Map |
6 | import qualified Data.Map as Map | 6 | import Data.Maybe |
7 | import Data.Maybe | 7 | import Utils |
8 | 8 | ||
9 | dirs = [ (-1,-1), (0,-1), (1,-1) | 9 | dirs = [ (-1,-1), (0,-1), (1,-1) |
10 | , (-1, 0), (1, 0) | 10 | , (-1, 0), (1, 0) |
diff --git a/execs/Day12.hs b/execs/Day12.hs index 11d2aa6..130e539 100644 --- a/execs/Day12.hs +++ b/execs/Day12.hs | |||
@@ -1,6 +1,6 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Utils | 3 | import Utils |
4 | 4 | ||
5 | parseLine s = (head s, read (tail s) :: Float) | 5 | parseLine s = (head s, read (tail s) :: Float) |
6 | 6 | ||
diff --git a/execs/Day13.hs b/execs/Day13.hs index 07d379d..ca64fe0 100644 --- a/execs/Day13.hs +++ b/execs/Day13.hs | |||
@@ -1,11 +1,11 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Utils | 3 | import Control.Monad (ap, zipWithM) |
4 | import Data.List.Split | 4 | import Data.Bifunctor |
5 | import Data.Tuple | 5 | import Data.List (sortOn) |
6 | import Data.List (sortOn) | 6 | import Data.List.Split |
7 | import Data.Bifunctor | 7 | import Data.Tuple |
8 | import Control.Monad (zipWithM, ap) | 8 | import Utils |
9 | 9 | ||
10 | earliest :: Int -> [Int] -> Int | 10 | earliest :: Int -> [Int] -> Int |
11 | earliest start ls = t * b | 11 | earliest start ls = t * b |
diff --git a/execs/Day14.hs b/execs/Day14.hs index 7f4368a..e1e0e37 100644 --- a/execs/Day14.hs +++ b/execs/Day14.hs | |||
@@ -1,15 +1,15 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Utils | 3 | import Data.Bifunctor (bimap) |
4 | import Text.ParserCombinators.Parsec | ||
5 | import Text.Parsec.Char | ||
6 | import Data.Either | ||
7 | import Data.Char | 4 | import Data.Char |
8 | import Data.Bifunctor (bimap) | 5 | import Data.Either |
6 | import Data.Map (Map) | ||
7 | import qualified Data.Map as Map | ||
9 | import Data.Strings | 8 | import Data.Strings |
10 | import Numeric (showIntAtBase, readInt) | 9 | import Numeric (readInt, showIntAtBase) |
11 | import Data.Map (Map) | 10 | import Text.Parsec.Char |
12 | import qualified Data.Map as Map | 11 | import Text.ParserCombinators.Parsec |
12 | import Utils | ||
13 | 13 | ||
14 | data Stmt = Mask String | Mem Int Int deriving Show | 14 | data Stmt = Mask String | Mem Int Int deriving Show |
15 | 15 | ||
@@ -41,9 +41,9 @@ runProgram ls = sum regs | |||
41 | where nval = applyMask val m | 41 | where nval = applyMask val m |
42 | 42 | ||
43 | floatings :: String -> [String] | 43 | floatings :: String -> [String] |
44 | floatings [] = [[]] | 44 | floatings [] = [[]] |
45 | floatings ('X':xs) = floatings xs >>= (\b -> ['0':b, '1':b]) | 45 | floatings ('X':xs) = floatings xs >>= (\b -> ['0':b, '1':b]) |
46 | floatings (x:xs) = map (x:) $ floatings xs | 46 | floatings (x:xs) = map (x:) $ floatings xs |
47 | 47 | ||
48 | genIdxs :: Int -> String -> [Int] | 48 | genIdxs :: Int -> String -> [Int] |
49 | genIdxs v m = map (fst . head . readInt 2 (`elem` "01") digitToInt) (floatings wm) | 49 | genIdxs v m = map (fst . head . readInt 2 (`elem` "01") digitToInt) (floatings wm) |
diff --git a/execs/Day15.hs b/execs/Day15.hs index cd498fb..c54e331 100644 --- a/execs/Day15.hs +++ b/execs/Day15.hs | |||
@@ -1,8 +1,8 @@ | |||
1 | module Main where | 1 | module Main where |
2 | 2 | ||
3 | import Data.Maybe | 3 | import Data.List.Split |
4 | import Data.List.Split | 4 | import qualified Data.Map as M |
5 | import qualified Data.Map as M | 5 | import Data.Maybe |
6 | 6 | ||
7 | run :: [Int] -> Int -> [Int] -> Int | 7 | run :: [Int] -> Int -> [Int] -> Int |
8 | run ls start input = fst $ foldl fn (start, startMap) ls | 8 | run ls start input = fst $ foldl fn (start, startMap) ls |