aboutsummaryrefslogtreecommitdiff
path: root/execs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-12-16 07:27:38 +0000
committerAkshay <[email protected]>2020-12-16 07:27:38 +0000
commit8c1193fece01bb80e86d8cc36efcf8820a6ccb46 (patch)
treef13ed4cdb33e748f596db9b7e7a2b08d8b3ba0ef /execs
parent38f3a717b0f8095fb05b9be0bebd158474eb7618 (diff)
format *
Diffstat (limited to 'execs')
-rw-r--r--execs/Day01.hs2
-rw-r--r--execs/Day02.hs14
-rw-r--r--execs/Day04.hs18
-rw-r--r--execs/Day05.hs6
-rw-r--r--execs/Day09.hs10
-rw-r--r--execs/Day10.hs8
-rw-r--r--execs/Day11.hs10
-rw-r--r--execs/Day12.hs2
-rw-r--r--execs/Day13.hs12
-rw-r--r--execs/Day14.hs20
-rw-r--r--execs/Day15.hs6
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 @@
1module Main where 1module Main where
2 2
3import Control.Monad 3import Control.Monad
4 4
5main :: IO () 5main :: IO ()
6main = do 6main = 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 @@
1module Main where 1module Main where
2 2
3import Text.ParserCombinators.Parsec 3import Text.Parsec.Char
4import Text.Parsec.Char 4import Text.ParserCombinators.Parsec
5import Utils 5import Utils
6 6
7type PassProp = (Int, Int, Char, String) 7type PassProp = (Int, Int, Char, String)
8 8
9parseInt :: Parser Int 9parseInt :: Parser Int
10parseInt = read <$> many1 digit 10parseInt = read <$> many1 digit
11parseProp :: Parser PassProp 11parseProp :: Parser PassProp
12parseProp = (,,,) 12parseProp = (,,,)
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
18doCheck1 :: PassProp -> Bool 18doCheck1 :: 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 @@
1module Main where 1module Main where
2 2
3import Text.ParserCombinators.Parsec 3import Data.Char (isDigit, isHexDigit)
4import Data.Map.Strict (Map, (!)) 4import Data.Map.Strict (Map, (!))
5import qualified Data.Map.Strict as Map 5import qualified Data.Map.Strict as Map
6import Data.Char (isDigit, isHexDigit) 6import Text.ParserCombinators.Parsec
7import Utils 7import Utils
8 8
9requiredFields = [ "byr" , "iyr" , "eyr" , "hgt" , "hcl" , "ecl" , "pid" ] 9requiredFields = [ "byr" , "iyr" , "eyr" , "hgt" , "hcl" , "ecl" , "pid" ]
10eyeColors = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"] 10eyeColors = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"]
11 11
12block = cell `sepBy` oneOf " \n" 12block = cell `sepBy` oneOf " \n"
@@ -28,15 +28,15 @@ validEyr s = bet (read s :: Int) (2020, 2030)
28validEcl = flip elem eyeColors 28validEcl = flip elem eyeColors
29validPid s = length s == 9 && all isDigit s 29validPid s = length s == 9 && all isDigit s
30validHcl ('#':rest) = length rest == 6 && all isHexDigit rest 30validHcl ('#':rest) = length rest == 6 && all isHexDigit rest
31validHcl _ = False 31validHcl _ = False
32validHgt s = 32validHgt 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
41doValidate :: Map String String -> Bool 41doValidate :: Map String String -> Bool
42doValidate map = all ((== True) . (\(s, v) -> v $ map ! s)) ls 42doValidate 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 @@
1module Main where 1module Main where
2 2
3import Data.Char (digitToInt) 3import Data.Char (digitToInt)
4import Data.List (sort) 4import Data.List (sort)
5import Utils (binaryToInt) 5import Utils (binaryToInt)
6 6
7doValidate = binaryToInt . map readBin 7doValidate = binaryToInt . map readBin
8readBin s | s `elem` "FL" = '0' 8readBin 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
2module Main where 2module Main where
3 3
4import Utils 4import Data.Bifunctor
5import Data.List (inits, tails, find, sort) 5import Data.List (find, inits, sort, tails)
6import Data.Bifunctor 6import Utils
7 7
8parseLine :: String -> Int 8parseLine :: String -> Int
9parseLine = read 9parseLine = 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
15checkAll :: [[Int]] -> [Int] -> [(Int, Bool)] 15checkAll :: [[Int]] -> [Int] -> [(Int, Bool)]
16checkAll = zipWith (\p t -> (t, doCheck p t)) 16checkAll = zipWith (\p t -> (t, doCheck p t))
17 17
18findWeakness :: [[Int]] -> Int -> Int 18findWeakness :: [[Int]] -> Int -> Int
19findWeakness subs target = minimum t + maximum t 19findWeakness subs target = minimum t + maximum t
20 where Just t = find ((== target) . sum) subs 20 where Just t = find ((== target) . sum) subs
21 21
22main :: IO () 22main :: IO ()
23main = do 23main = 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
2module Main where 2module Main where
3 3
4import Utils 4import Control.Monad
5import Data.List (sort) 5import Control.Monad.Memo
6import Control.Monad 6import Data.List (sort)
7import Control.Monad.Memo 7import Utils
8 8
9parseLine :: String -> Int 9parseLine :: String -> Int
10parseLine = read 10parseLine = 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 @@
1module Main where 1module Main where
2 2
3import Utils 3import Data.List (sortOn)
4import Data.List (sortOn) 4import Data.Map (Map, (!))
5import Data.Map (Map, (!)) 5import qualified Data.Map as Map
6import qualified Data.Map as Map 6import Data.Maybe
7import Data.Maybe 7import Utils
8 8
9dirs = [ (-1,-1), (0,-1), (1,-1) 9dirs = [ (-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 @@
1module Main where 1module Main where
2 2
3import Utils 3import Utils
4 4
5parseLine s = (head s, read (tail s) :: Float) 5parseLine 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 @@
1module Main where 1module Main where
2 2
3import Utils 3import Control.Monad (ap, zipWithM)
4import Data.List.Split 4import Data.Bifunctor
5import Data.Tuple 5import Data.List (sortOn)
6import Data.List (sortOn) 6import Data.List.Split
7import Data.Bifunctor 7import Data.Tuple
8import Control.Monad (zipWithM, ap) 8import Utils
9 9
10earliest :: Int -> [Int] -> Int 10earliest :: Int -> [Int] -> Int
11earliest start ls = t * b 11earliest 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 @@
1module Main where 1module Main where
2 2
3import Utils 3import Data.Bifunctor (bimap)
4import Text.ParserCombinators.Parsec
5import Text.Parsec.Char
6import Data.Either
7import Data.Char 4import Data.Char
8import Data.Bifunctor (bimap) 5import Data.Either
6import Data.Map (Map)
7import qualified Data.Map as Map
9import Data.Strings 8import Data.Strings
10import Numeric (showIntAtBase, readInt) 9import Numeric (readInt, showIntAtBase)
11import Data.Map (Map) 10import Text.Parsec.Char
12import qualified Data.Map as Map 11import Text.ParserCombinators.Parsec
12import Utils
13 13
14data Stmt = Mask String | Mem Int Int deriving Show 14data 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
43floatings :: String -> [String] 43floatings :: String -> [String]
44floatings [] = [[]] 44floatings [] = [[]]
45floatings ('X':xs) = floatings xs >>= (\b -> ['0':b, '1':b]) 45floatings ('X':xs) = floatings xs >>= (\b -> ['0':b, '1':b])
46floatings (x:xs) = map (x:) $ floatings xs 46floatings (x:xs) = map (x:) $ floatings xs
47 47
48genIdxs :: Int -> String -> [Int] 48genIdxs :: Int -> String -> [Int]
49genIdxs v m = map (fst . head . readInt 2 (`elem` "01") digitToInt) (floatings wm) 49genIdxs 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 @@
1module Main where 1module Main where
2 2
3import Data.Maybe 3import Data.List.Split
4import Data.List.Split 4import qualified Data.Map as M
5import qualified Data.Map as M 5import Data.Maybe
6 6
7run :: [Int] -> Int -> [Int] -> Int 7run :: [Int] -> Int -> [Int] -> Int
8run ls start input = fst $ foldl fn (start, startMap) ls 8run ls start input = fst $ foldl fn (start, startMap) ls