module Three (three) where

import Data.List

tuplify :: String -> (Integer, Integer, Integer)
tuplify l = (a, b, c)
    where (a:b:c:[]) = read <$> words l

isValid :: (Integer, Integer, Integer) -> Bool
isValid (x, y, z) = x + y > z && x + z > y && y + z > x

blockDiv :: [(Integer, Integer, Integer)] -> [(Integer, Integer, Integer)]
blockDiv [] = []
blockDiv ((a, i, x):(b, j, y):(c, k, z):bs) = (a, b, c) : (i, j, k) : (x, y, z) : blockDiv bs

three = do
    input <- (fmap tuplify) <$> lines <$> readFile "data/three.txt"
    putStrLn $ "part A: " ++ show (length $ filter isValid input)

    let inputB = blockDiv input
    putStrLn $ "part B: " ++ show (length $ filter isValid inputB)
