6TR3H656MQ3WM3RFWZRHWATU4G5MPRR2CEVM3BAVONWMRMVNVQ4QC FU6HYDVYMIX5ZW5ZD5S76WXJBUOA3XTO2377PTHVNW2ZLT4DJUAAC K7KUOYE2VONTDGZ6BIAGA3F7RYQEBNTY3LQOYQM4FH3MOUTLBL6AC Y2N6GDITBJID3Q4Z2Y7KEDY46F7R3SU4DRK3ST6ZMA4CNLXWSFDAC EW3Z5HY7MUE25EJ3EOJDR4F4GP4DQQSSMIYWP5LQEPSMMGUKKKJAC 7QP2V7ZBVZ7SKQ3SYV6NYA7V77G3Y7GF5V6EPIXLIYFSMFRWR4VAC ANAAF3LVFG2YCTAWUZKMT75XQN6YNS4CLLZIXSVGKJQRWJVNBMEAC JDI62ZLKN7J4572C7E2WL2HPGAMFU5YEIDOERVGIOBPOOV3DRF5AC RCDJ2AGX5X4FJ7B7XFLWFVMM6LTVZKTXONYQOYT4JQB7WX5TQPMQC generate v rs = foldr ($) (verse 11)$ set Robot { name = "@" , ops = mempty } 0: set Robot { name = "t0" , ops = Move <$> cycle [U,N,L] } (shift v 1 U 0): set Robot { name = "t1" , ops = Move <$> cycle [N,L,U] } (shift v 2 U 0): set Robot { name = "t2" , ops = Move <$> cycle [L,U,N] } (shift v 1 U $ shift v 1 H 0): set Robot { name = "i" , ops = Move <$> repeat N } (shift v 8 I 0): set Robot { name = "n" , ops = Move <$> repeat I } (shift v 2 I 0): set Robot { name = "x" , ops = mempty } (shift v 7 M 0): set Robot { name = "L0" , ops = Move <$> repeat L } (shift v 17 H 0): set Robot { name = "L1" , ops = Move <$> repeat L } (shift v 18 H 0): set Robot { name = "L2" , ops = Move <$> repeat L } (shift v 19 H 0)
generate v rs = foldr ($) v$ set Robot { name = "@" , go = mempty } 0: set Robot { name = "t0" , go = Move <$> cycle [U,N,L] } (shift v 1 U 0): set Robot { name = "t1" , go = Move <$> cycle [N,L,U] } (shift v 2 U 0): set Robot { name = "t2" , go = Move <$> cycle [L,U,N] } (shift v 1 U $ shift v 1 H 0): set Robot { name = "i" , go = Move <$> repeat N } (shift v 8 I 0): set Robot { name = "n" , go = Move <$> repeat I } (shift v 2 I 0): set Robot { name = "x" , go = mempty } (shift v 7 M 0): set Robot { name = "L0" , go = Move <$> repeat L } (shift v 17 H 0): set Robot { name = "L1" , go = Move <$> repeat L } (shift v 18 H 0): set Robot { name = "L2" , go = Move <$> repeat L } (shift v 19 H 0)
data Unit = None | Wall | Box { pushed :: Maybe Dir } | Ball { pushed :: Maybe Dir } | Robot { name :: String , ops :: [Op] }deriving Showdata Op = Lock | Move Dir
data Unit = None | Wall | Box | Ball | Robot { name :: String , go :: [Move] }
| Robot {} <- a , Move d : _ <- ops a = Just d| Box {} <- a = pushed a| Ball {} <- a = pushed a| otherwise = Nothinglock a| Wall <- a = True| Robot {} <- a = True| Box {} <- a = True| Ball {} <- a = True| otherwise = False
| Robot {} <- a , m : _ <- go a = m| Wall <- a = Lock| otherwise = None
| Just 'H' <- k = z { center = shift v 1 H $ center s } | Just 'J' <- k = z { center = shift v 1 N $ center s } | Just 'K' <- k = z { center = shift v 1 I $ center s }
| Just 'H' <- k = z { center = shift v 1 H $ center s }| Just 'J' <- k = z { center = shift v 1 N $ center s }| Just 'K' <- k = z { center = shift v 1 I $ center s }
module Nove.Utils whereimport Data.List.NonEmpty-- | Historydata History a = History { past :: NonEmpty a , future :: [a] }-- step backwards in timebefore :: History a -> History abefore (History (m :| p : ps) f) = History (p :| ps) (m:f)before h = h-- step forwards in timeafter :: History a -> History aafter (History p (m:f)) = History (m <| p) fafter h = h-- go to presentultimate :: History a -> History aultimate h@(History _ []) = hultimate h = ultimate $ after h-- get currentmoment :: History a -> amoment (History (m :| _) _) = m-- record momentrecord :: a -> History a -> History arecord m (History p f) = History (m <| p) f
import Data.IntMap as IntMap ( IntMap, (!), foldrWithKey, fromDistinctAscList )import Data.Map as Map ( Map, fromList, filterWithKey, elems )
import Data.IntMap as IntMap ( IntMap, (!), mapWithKey, foldrWithKey, mapWithKey, fromDistinctAscList )import Data.Map as Map ( Map )
(memo',nodes') = bimap intmap intmap $ IntMap.foldrWithKey go mempty $ nodes vwhereintmap :: [v] -> IntMap vintmap = IntMap.fromDistinctAscList . zip [0..]-- simulate atom and apply fgo :: Int -> a -> ([Memo a], [a]) -> ([Memo a], [a])go i a (ms,as) = (m : ms , a' : as)where-- memoization for this nodem :: Memo am = Memo{ mauto = w, mdest = dest, mfree = free}w :: aw = f (adjacents v i) a-- new atoma' :: a| free , [n] <- ins = n -- move in| d : _ <- dest , mfree (memo' IntMap.! d) = void -- move out| otherwise = w-- move inins :: [a]ins = Map.elems $ Map.filterWithKey (\dir c -> move c == Just (opposite dir)) nsns :: Map Dir ans = Map.fromList $ (,) <*> (node v . flip (shift v 1) i) <$> total-- chain of destinationsdest :: [Int]| Just dir <- move w , d <- shift v 1 dir i = d : mdest (memo' IntMap.! d)| otherwise = []
(ms,nodes') = bimap intmap intmap $ foldrWithKey go mempty $ nodes v-- ms: future memory of movement intent
-- is this node free?free :: Bool| lock w , null dest = False| length ins > 1 = False -- stall| Just (_,d) <- floyd $ i : dest = False -- i == d -- floyd $ cycle [0,1] => Just (2,1) , so (i /= d) when reciprocal| otherwise = all (mfree . (memo' IntMap.!)) $ take 1 dest -- dest is free
intmap :: [v] -> IntMap vintmap = fromDistinctAscList . zip [0..]