Added split package to dev env
This commit is contained in:
parent
18ea7d1466
commit
f818178760
2 changed files with 17 additions and 13 deletions
|
@ -1,9 +1,17 @@
|
|||
import Data.List
|
||||
import Data.List.Split
|
||||
import Control.Monad (join)
|
||||
import Control.Concurrent
|
||||
|
||||
main :: IO ()
|
||||
main = readFile "5/riley.txt" >>= print . solve . parse . lines
|
||||
main = do
|
||||
input <- readFile "5/example.txt"
|
||||
let x = parse $ lines input
|
||||
print $ f x
|
||||
print $ g x
|
||||
where
|
||||
f = length . nub . solve . filter (not . diagonal)
|
||||
g = length . nub . solve
|
||||
|
||||
parse :: [String] -> [(Point,Point)]
|
||||
parse = map (parseLine . words)
|
||||
|
@ -26,16 +34,11 @@ toRange (a @ (xa,ya), b @ (xb,yb))
|
|||
parseCoord :: String -> (Int,Int)
|
||||
parseCoord l = (head n, last n)
|
||||
where
|
||||
n = map read $ words [ if c == ',' then ' ' else c | c <- l ]
|
||||
n = map read . wordsBy (== ',') $ l
|
||||
|
||||
solve :: [(Point,Point)] -> (Int,Int)
|
||||
solve i = (f i, g i)
|
||||
where f = length . nub . overlapping . filter (not . diagonal)
|
||||
g = length . nub . overlapping
|
||||
|
||||
overlapping :: [(Point, Point)] -> [Point]
|
||||
overlapping [_] = []
|
||||
overlapping (p:ps) = overlapping' p ps ++ overlapping ps
|
||||
solve :: [(Point, Point)] -> [Point]
|
||||
solve [_] = []
|
||||
solve (p:ps) = overlapping' p ps ++ solve ps
|
||||
|
||||
overlapping' :: (Point, Point) -> [(Point, Point)] -> [Point]
|
||||
overlapping' _ [] = []
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
{ pkgs ? import <nixpkgs> {} }: pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
haskell-language-server
|
||||
cabal-install
|
||||
ghc
|
||||
(ghc.withPackages (pkgs: with pkgs; [
|
||||
split
|
||||
]))
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue