X-Git-Url: https://git.njae.me.uk/?p=advent-of-code-19.git;a=blobdiff_plain;f=advent24%2Fsrc%2Fadvent24tape.hs;fp=advent24%2Fsrc%2Fadvent24tape.hs;h=0000000000000000000000000000000000000000;hp=8f6ce9653460089ec89283e0158b90461599f0ce;hb=6a1a537ac8f0d4fab44b806aa8986dce4aab8f9e;hpb=38d570c8528a68170cbfaf50cc750c7d4e1cde5c diff --git a/advent24/src/advent24tape.hs b/advent24/src/advent24tape.hs deleted file mode 100644 index 8f6ce96..0000000 --- a/advent24/src/advent24tape.hs +++ /dev/null @@ -1,89 +0,0 @@ - --- import Debug.Trace - - -import Data.Bool (bool) -import Data.Distributive (Distributive(..)) -import Data.Functor.Rep (Representable(..), distributeRep) -import Data.Functor.Identity (Identity(..)) -import Control.Comonad.Representable.Store (Store(..), StoreT(..), store, experiment, runStore) -import Control.Comonad (Comonad(..)) - -import Data.Maybe -import Data.List -import qualified Data.Set as S -import qualified Data.Map as M - -import Control.Concurrent (threadDelay) -import Control.Monad (forM_) - -import Control.Comonad -import Control.Comonad.Cofree -import Data.Distributive -import Data.Functor.Rep -import qualified Data.Sequence as Q -import qualified Data.List.NonEmpty as NE - - -data TPossible a = TPossible - { leftward :: a - , rightward :: a - , above :: a - , below :: a - } deriving (Show, Eq, Functor) - -data TChoice = L | R | U | D - deriving (Show, Eq) - -instance Distributive TPossible where - distribute :: Functor f => f (TPossible a) -> TPossible (f a) - distribute fga = TPossible (fmap leftward fga) (fmap rightward fga) - (fmap above fga) (fmap below fga) - -instance Representable TPossible where - type Rep TPossible = TChoice - - index :: TPossible a -> TChoice -> a - index here L = leftward here - index here R = rightward here - index here U = above here - index here D = below here - - tabulate :: (TChoice -> a) -> TPossible a - tabulate describe = TPossible (describe L) (describe R) - (describe U) (describe D) - -relativePosition :: Q.Seq TChoice -> Int -relativePosition = sum . fmap valOf - where - valOf L = (-1) - valOf R = 1 - valOf U = (-10) - valOf D = 10 - -numberLine :: Cofree TPossible Int -numberLine = tabulate relativePosition - -project :: NE.NonEmpty a -> Cofree TPossible a -project l = tabulate describe - where - describe = (l NE.!!) . foldl go 0 - maxIndex = length l - 1 - minIndex = 0 - go n L = max minIndex (n - 1) - go n R = min maxIndex (n + 1) - go n U = max minIndex (n - 1) - go n D = min maxIndex (n + 1) - -elems :: NE.NonEmpty String -elems = "one" NE.:| ["two", "three"] - -path :: Q.Seq TChoice -path = Q.fromList [R, R, R, R, L] - -moveTo :: Q.Seq TChoice -> Cofree TPossible a -> Cofree TPossible a -moveTo ind = extend (\cfr -> index cfr ind) - -main :: IO () -main = print $ index (project elems) path --- main = print elems