Last active
November 24, 2024 08:42
Revisions
-
tttardigrado revised this gist
Nov 23, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ left (Tape (l:ls) v rs) = Tape ls l (v:rs) right :: Tape -> Tape right (Tape ls v (r:rs)) = Tape (v:ls) r rs peek :: Tape -> Int peek (Tape _ v _) = v edit :: (Int -> Int) -> Tape -> Tape -
tttardigrado created this gist
Nov 23, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ data P = R | L | Seq P P | Loop P data Tape = Tape [Int] Int [Int] empty :: Tape empty = Tape (repeat 0) 0 (repeat 0) left :: Tape -> Tape left (Tape (l:ls) v rs) = Tape ls l (v:rs) right :: Tape -> Tape right (Tape ls v (r:rs)) = Tape (v:ls) r rs peek :: Tape -> Tape peek (Tape _ v _) = v edit :: (Int -> Int) -> Tape -> Tape edit f (Tape ls v rs) = Tape ls (f v) rs run :: Int -> P -> Tape -> Tape run n R t = right t run n L t = left $ edit ((`mod`n) . (+1)) t run n (Seq p q) t = run n q $ run n p t run n (Loop p) t = if peek t == 0 then t else run n (Seq p $ Loop p) t eval :: P -> Int eval p = peek $ run 256 p empty