Skip to content

Commit 66f78ac

Browse files
author
Achim Krause
committed
Forgot to recursively optimize loops in multitape-brainfuck.
1 parent a0dcc34 commit 66f78ac

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: BFMulti.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ print (c:cs) = (show c) ++ (concat . map (\x -> " " ++ (show x)) $ cs)
2121
type Program = [Command]
2222

2323
optimize :: Program -> Program
24-
optimize p = concat $ foldr1 (.) (map ((flip optimize_step) []) [0..(last_tape p)]) $ (map (\x -> [x]) p) where
25-
24+
optimize p = concat $ foldr1 (.) (map ((flip optimize_step) []) [0..(last_tape p)]) $ (map prepare p) where
25+
prepare (Loop k p) = [Loop k (optimize p)]
26+
prepare c = [c]
27+
2628
-- index, accumulator, code, result
2729
optimize_step :: Int -> Program -> [Program] -> [Program]
2830
optimize_step i acc [] = [acc]

0 commit comments

Comments
 (0)