Day 22, Part 1

This commit is contained in:
daniele 2024-12-22 09:52:47 +01:00
parent 0e0442b9d9
commit ca9b64a8e6
Signed by: fuxino
GPG Key ID: 981A2B2A3BBF5514
3 changed files with 22 additions and 2 deletions

View File

@ -56,4 +56,5 @@ executable adventofcode2024
Day17
Day18
Day19
Day22
Graph

17
src/Day22.hs Normal file
View File

@ -0,0 +1,17 @@
module Day22 (day22_1) where
import Data.Bits
getSecretNumber :: Integer -> Int -> Integer
getSecretNumber x 0 = x
getSecretNumber x n =
let x' = ((x `shiftL` 6) `xor` x) `mod` 16777216
x'' = ((x' `shiftR` 5) `xor` x') `mod` 16777216
in getSecretNumber (((x'' `shiftL` 11) `xor` x'') `mod` 16777216) (n - 1)
day22_1 :: IO ()
day22_1 = do
contents <- map read . lines <$> readFile "input/day22.txt"
putStrLn $
"Day 22, Puzzle 1 solution: "
++ show (sum $ map (`getSecretNumber` 2000) contents)

View File

@ -18,6 +18,7 @@ import Day15 (day15_1)
import Day17 (day17_1, day17_2)
import Day18 (day18_1, day18_2)
import Day19 (day19_1)
import Day22 (day22_1)
import System.Environment (getArgs)
main :: IO ()
@ -94,12 +95,13 @@ main = do
"17" : "1" : _ -> day17_1
"17" : "2" : _ -> day17_2
"17" : _ -> do
day17_1
day17_2
day17_1
day17_2
"18" : "1" : _ -> day18_1
"18" : "2" : _ -> day18_2
"18" : _ -> do
day18_1
day18_2
"19" : "1" : _ -> day19_1
"22" : "1" : _ -> day22_1
_ -> error "Not implemented"