From 8c1193fece01bb80e86d8cc36efcf8820a6ccb46 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 16 Dec 2020 12:57:38 +0530 Subject: format * --- execs/Day01.hs | 2 +- execs/Day02.hs | 14 +++++++------- execs/Day04.hs | 18 +++++++++--------- execs/Day05.hs | 6 +++--- execs/Day09.hs | 10 +++++----- execs/Day10.hs | 8 ++++---- execs/Day11.hs | 10 +++++----- execs/Day12.hs | 2 +- execs/Day13.hs | 12 ++++++------ execs/Day14.hs | 20 ++++++++++---------- execs/Day15.hs | 6 +++--- 11 files changed, 54 insertions(+), 54 deletions(-) (limited to 'execs') 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 @@ module Main where -import Control.Monad +import Control.Monad main :: IO () 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 @@ module Main where -import Text.ParserCombinators.Parsec -import Text.Parsec.Char -import Utils +import Text.Parsec.Char +import Text.ParserCombinators.Parsec +import Utils type PassProp = (Int, Int, Char, String) parseInt :: Parser Int parseInt = read <$> many1 digit parseProp :: Parser PassProp -parseProp = (,,,) - <$> parseInt <* char '-' - <*> parseInt <* space - <*> letter <* string ": " +parseProp = (,,,) + <$> parseInt <* char '-' + <*> parseInt <* space + <*> letter <* string ": " <*> many letter 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 @@ module Main where -import Text.ParserCombinators.Parsec -import Data.Map.Strict (Map, (!)) -import qualified Data.Map.Strict as Map -import Data.Char (isDigit, isHexDigit) -import Utils +import Data.Char (isDigit, isHexDigit) +import Data.Map.Strict (Map, (!)) +import qualified Data.Map.Strict as Map +import Text.ParserCombinators.Parsec +import Utils -requiredFields = [ "byr" , "iyr" , "eyr" , "hgt" , "hcl" , "ecl" , "pid" ] +requiredFields = [ "byr" , "iyr" , "eyr" , "hgt" , "hcl" , "ecl" , "pid" ] eyeColors = ["amb", "blu", "brn", "gry", "grn", "hzl", "oth"] block = cell `sepBy` oneOf " \n" @@ -28,15 +28,15 @@ validEyr s = bet (read s :: Int) (2020, 2030) validEcl = flip elem eyeColors validPid s = length s == 9 && all isDigit s validHcl ('#':rest) = length rest == 6 && all isHexDigit rest -validHcl _ = False -validHgt s = +validHcl _ = False +validHgt s = let value = takeWhile isDigit s unit = dropWhile isDigit s height = (read value :: Int, unit) in case height of (v, "cm") -> bet v (150, 193) (v, "in") -> bet v (59, 76) - _ -> False + _ -> False doValidate :: Map String String -> Bool 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 @@ module Main where -import Data.Char (digitToInt) -import Data.List (sort) -import Utils (binaryToInt) +import Data.Char (digitToInt) +import Data.List (sort) +import Utils (binaryToInt) doValidate = binaryToInt . map readBin 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 @@ module Main where -import Utils -import Data.List (inits, tails, find, sort) -import Data.Bifunctor +import Data.Bifunctor +import Data.List (find, inits, sort, tails) +import Utils parseLine :: String -> Int parseLine = read @@ -13,12 +13,12 @@ doCheck preamble target = target `elem` p where p = [x + y | x <- preamble, y <- preamble, x /= y] checkAll :: [[Int]] -> [Int] -> [(Int, Bool)] -checkAll = zipWith (\p t -> (t, doCheck p t)) +checkAll = zipWith (\p t -> (t, doCheck p t)) findWeakness :: [[Int]] -> Int -> Int findWeakness subs target = minimum t + maximum t where Just t = find ((== target) . sum) subs - + main :: IO () main = do 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 @@ module Main where -import Utils -import Data.List (sort) -import Control.Monad -import Control.Monad.Memo +import Control.Monad +import Control.Monad.Memo +import Data.List (sort) +import Utils parseLine :: String -> Int 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 @@ module Main where -import Utils -import Data.List (sortOn) -import Data.Map (Map, (!)) -import qualified Data.Map as Map -import Data.Maybe +import Data.List (sortOn) +import Data.Map (Map, (!)) +import qualified Data.Map as Map +import Data.Maybe +import Utils dirs = [ (-1,-1), (0,-1), (1,-1) , (-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 @@ module Main where -import Utils +import Utils parseLine s = (head s, read (tail s) :: Float) 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 @@ module Main where -import Utils -import Data.List.Split -import Data.Tuple -import Data.List (sortOn) -import Data.Bifunctor -import Control.Monad (zipWithM, ap) +import Control.Monad (ap, zipWithM) +import Data.Bifunctor +import Data.List (sortOn) +import Data.List.Split +import Data.Tuple +import Utils earliest :: Int -> [Int] -> Int 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 @@ module Main where -import Utils -import Text.ParserCombinators.Parsec -import Text.Parsec.Char -import Data.Either +import Data.Bifunctor (bimap) import Data.Char -import Data.Bifunctor (bimap) +import Data.Either +import Data.Map (Map) +import qualified Data.Map as Map import Data.Strings -import Numeric (showIntAtBase, readInt) -import Data.Map (Map) -import qualified Data.Map as Map +import Numeric (readInt, showIntAtBase) +import Text.Parsec.Char +import Text.ParserCombinators.Parsec +import Utils data Stmt = Mask String | Mem Int Int deriving Show @@ -41,9 +41,9 @@ runProgram ls = sum regs where nval = applyMask val m floatings :: String -> [String] -floatings [] = [[]] +floatings [] = [[]] floatings ('X':xs) = floatings xs >>= (\b -> ['0':b, '1':b]) -floatings (x:xs) = map (x:) $ floatings xs +floatings (x:xs) = map (x:) $ floatings xs genIdxs :: Int -> String -> [Int] 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 @@ module Main where -import Data.Maybe -import Data.List.Split -import qualified Data.Map as M +import Data.List.Split +import qualified Data.Map as M +import Data.Maybe run :: [Int] -> Int -> [Int] -> Int run ls start input = fst $ foldl fn (start, startMap) ls -- cgit v1.2.3