Day 11 - part 1.
This commit is contained in:
parent
9f6aa1dc69
commit
c53606ebfa
|
@ -30,4 +30,4 @@ import qualified Day24
|
||||||
import qualified Day25
|
import qualified Day25
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = Day10.main
|
main = Day11.main
|
||||||
|
|
21
src/Day11.hs
21
src/Day11.hs
|
@ -1,6 +1,23 @@
|
||||||
module Day11 (main) where
|
module Day11 (main) where
|
||||||
|
|
||||||
|
import Data.Char (digitToInt)
|
||||||
|
import Data.List (maximumBy)
|
||||||
|
import Data.Ord (comparing)
|
||||||
|
|
||||||
|
indexToCoord :: Int -> (Int, Int)
|
||||||
|
indexToCoord i = (1 + i `div` 300, 1 + i `mod` 300)
|
||||||
|
|
||||||
|
powerLevel :: (Int, Int) -> Int
|
||||||
|
powerLevel (x, y) = (subtract 5) . digitToInt . (!! 2) . reverse . show $ ((x + 10) * y + 7672) * (x + 10)
|
||||||
|
|
||||||
|
powerSquare :: Int -> (Int, Int) -> Int
|
||||||
|
powerSquare size (x, y) =
|
||||||
|
if x > 300 - size + 1 || y > 300 - size + 1 then -5
|
||||||
|
else sum [powerLevel (x', y') | x' <- [x .. x + size - 1], y' <- [y .. y + size - 1]]
|
||||||
|
|
||||||
|
part1 :: (Int, Int)
|
||||||
|
part1 = indexToCoord . fst . maximumBy (comparing snd) . zip [0..] . map (powerSquare 3 . indexToCoord) $ [0 .. 300 * 300]
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
input <- readFile "input/11.txt"
|
print part1
|
||||||
print input
|
|
Loading…
Reference in New Issue