import AoC
import qualified Data.Set as S
-import qualified Data.Map.Strict as M
import Linear hiding (Trace, trace, distance)
import Control.Lens
import Data.Maybe
-- Writeup at https://work.njae.me.uk/2022/12/21/advent-of-code-2022-day-19/
-import Debug.Trace
+-- import Debug.Trace
import AoC
import Data.Text (Text)
import Data.Sequence ((|>))
import Data.List
import Data.Maybe
-import Data.Ord
+-- import Data.Ord
import Control.Monad.Reader
import Control.Lens hiding ((<|), (|>), (:>), (:<), indices)
import Control.Parallel.Strategies
-- Writeup at https://work.njae.me.uk/2022/12/21/advent-of-code-2022-day-20/
import AoC
-import Data.List
+import Data.List hiding (elemIndex)
import Data.Maybe
import Data.CircularList
-import Control.Lens
+import Control.Lens hiding (element)
data IndexedElem = IndexedElem { _idx :: Int, _shift :: Int, _value :: Int}
deriving (Show, Eq, Ord)
import Control.Applicative
import qualified Data.Map.Strict as M
import Data.Map.Strict ((!))
-import Control.Lens
+import Control.Lens hiding (op)
data Shout = Literal Int | Operation Operator String String
deriving (Show, Eq, Ord)
-- import Debug.Trace
+
import AoC
import Prelude hiding (Left, Right)
import qualified Data.Map.Strict as M
where isRow = r < length rows
isCol = c < (length $ rows !! r)
-mkInstructions :: String -> [PathElement]
+mkInstructions, mkWalk, mkTurn :: String -> [PathElement]
mkInstructions [] = []
-mkInstructions text@(t:ts)
+mkInstructions text@(t:_)
| isDigit t = mkWalk text
| otherwise = mkTurn text
+
mkWalk text = (Forward $ read digits) : (mkInstructions remainder)
where (digits, remainder) = span (isDigit) text
+
+mkTurn [] = []
mkTurn (t:ts)
| t == 'R' = Clockwise : (mkInstructions ts)
| t == 'L' = Anticlockwise : (mkInstructions ts)
packSnafu digits
| carry == 0 = shown
| otherwise = (snafuRep carry) : shown
- where (carry, shown) = foldl' packSnafuDigit (0, "")
+ where (carry, shown) = foldl' packSnafuDigit (0, "") digits
packSnafuDigit :: (Int, String) -> Int -> (Int, String)
packSnafuDigit (carry, acc) d