init + day 1
This commit is contained in:
commit
f2c4afd7b4
2 changed files with 23 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
inputs/
|
||||||
22
src/Day2501.hs
Normal file
22
src/Day2501.hs
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
part1 :: String -> Int
|
||||||
|
part1 = length . dropNonZero . scanl (+) 50 . convertToInts . lines
|
||||||
|
where
|
||||||
|
convertToInts = map (\it -> (if head it == 'L' then -1 else 1) * read (drop 1 it))
|
||||||
|
dropNonZero = filter ((0==) . (`mod` 100))
|
||||||
|
|
||||||
|
|
||||||
|
part2 :: String -> Int
|
||||||
|
part2 = length . dropNonZero . scanl (+) 50 . makeSingleSteps . convertToInts . lines
|
||||||
|
where
|
||||||
|
convertToInts = map (\it -> (if head it == 'L' then -1 else 1) * read (drop 1 it))
|
||||||
|
dropNonZero = filter ((0==) . (`mod` 100))
|
||||||
|
makeSingleSteps = concatMap (\it -> replicate (abs it) (signum it))
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
str <- readFile "inputs/2025-1"
|
||||||
|
|
||||||
|
print $ part1 str
|
||||||
|
print $ part2 str
|
||||||
Loading…
Add table
Add a link
Reference in a new issue