~rootmos/AoC

33a1d6d3905dccc51f30144000ddd8a8dfe79e3f — Gustav Behm a month ago a5c249d
Add solution to AoC 2023 #06a
3 files changed, 48 insertions(+), 0 deletions(-)

A 2023/06.example
A 2023/06.hs
A 2023/06.input
A 2023/06.example => 2023/06.example +2 -0
@@ 0,0 1,2 @@
Time:      7  15   30
Distance:  9  40  200

A 2023/06.hs => 2023/06.hs +44 -0
@@ 0,0 1,44 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Main where

import Qulude

--import Data.Array ( (!) )
import qualified Data.Array as Array
import qualified Data.Array.ST as STArray
import qualified Data.Either as Either
import qualified Data.List as List
--import Data.Array ( (!) )
import qualified Data.Map as Map
import qualified Data.Maybe as Maybe
import qualified Data.Sequence as Seq
import qualified Data.Set as Set

import qualified Text.Parsec as P

type Parse = [ (Int, Int) ]
parser :: Parser Parse
parser = do
  string "Time:" >> spaces
  ts <- many $ int <* spaces
  string "Distance:" >> spaces
  ds <- many $ int <* spaces
  return $ zip ts ds

partA :: Parse -> Int
partA rs = foldr (*) 1 $ fmap f rs
  where f (t, r) = length $ filter (>r) $ take (t+1) [0..] <&> \h -> h * (t - h)

--partB :: Parse -> Parse
--partB = id

main :: IO ()
main = with parser $ do
  run "06.example" "a example" partA
  run "06.input" "a input" partA
  --run "06.example" "b example" partB
  --run "06.input" "b input" partB

A 2023/06.input => 2023/06.input +2 -0
@@ 0,0 1,2 @@
Time:        61     67     75     71
Distance:   430   1036   1307   1150