Created
October 10, 2025 10:19
-
-
Save lotusirous/88e155ad7f327ee32eccfb1d77181d09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Question: https://adventofcode.com/2015/day/3 | |
| import qualified Data.Set as S | |
| import System.IO (readFile) | |
| -- Move Santa according to a direction | |
| move :: (Int, Int) -> Char -> (Int, Int) | |
| move (x, y) c = case c of | |
| '^' -> (x, y + 1) | |
| 'v' -> (x, y - 1) | |
| '>' -> (x + 1, y) | |
| '<' -> (x - 1, y) | |
| _ -> (x, y) | |
| -- Count unique houses visited | |
| santa :: String -> Int | |
| santa path = S.size visited | |
| where | |
| (visited, _) = foldl step (S.singleton (0,0), (0,0)) path | |
| step (seen, pos) c = | |
| let next = move pos c | |
| in (S.insert next seen, next) | |
| -- main | |
| main :: IO () | |
| main = do | |
| contents <- readFile "./day03.txt" | |
| let firstLine = head (lines contents) | |
| print (santa firstLine) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment