Compare commits

..

No commits in common. "a65b14a35ab7f486dbd0c959537238f35e01bce0" and "27c17c492efb7e15f35c29f3bceb5fa9f4d870d2" have entirely different histories.

3 changed files with 0 additions and 32 deletions

30
3.hs
View File

@ -1,30 +0,0 @@
{-# LANGUAGE ScopedTypeVariables #-}
import Data.List
main = do
lines <- readFile "3.in"
putStrLn . show . solve . (!!0) . words $ lines
where
solve = length . Data.List.group . Data.List.sort . partB
-- solves all lines, returns a string
partA :: [Char] -> [(Int, Int)]
partA = getPositions
where
getPositions = snd . foldl updatePosition ((0,0), [(0,0)]) . map coords
-- updatePosition :: b -> a -> b
updatePosition ((x, y), positions) (a, b) = ((x + a, y + b), (x + a, y + b):positions)
-- (right, up)
coords '>' = (1, 0)
coords '<' = (-1, 0)
coords 'v' = (0, -1)
coords '^' = (0, 1)
coords _ = (0, 0)
partB :: [Char] -> [(Int, Int)]
partB l = id =<< [ partA . odds $ l, partA . evens $ l]
where
evens = odds . tail
odds [] = []
odds [x] = [x]
odds (x:y:r) = x:(odds r)

1
3.in

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,3 @@
target:
ghc 1.hs
ghc 2.hs
ghc 3.hs