Initial commit

This commit is contained in:
Daniele Fucini
2025-12-01 19:31:18 +01:00
commit 3f7baccf0c
9 changed files with 187 additions and 0 deletions

27
src/Day01.hs Normal file
View File

@@ -0,0 +1,27 @@
module Day01
( day01_1,
)
where
parseInput :: IO [String]
parseInput = do
lines <$> readFile "input/day1.txt"
rotate :: Int -> String -> Int
rotate n ('L':xs) = (n - read xs) `mod` 100
rotate n ('R':xs) = (n + read xs) `mod` 100
rotate n _ = n
getPassword :: Int -> Int -> [String] -> Int
getPassword pass 0 [] = pass + 1
getPassword pass _ [] = pass
getPassword pass 0 (x:xs) = getPassword (pass + 1) (rotate 0 x) xs
getPassword pass curr (x:xs) = getPassword pass (rotate curr x) xs
day01_1 :: IO ()
day01_1 = do
input <- parseInput
let result = getPassword 0 50 input
putStrLn $
"Day 1, Puzzle 1 solution: "
++ show result