Created
October 19, 2015 14:28
-
-
Save LukaHorvat/5e9c3b2dacbc324be7ba to your computer and use it in GitHub Desktop.
This file contains 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 characters
data Node = Value Int | List [Node] | Sequence [Node] | |
steps :: Node -> [[Int]] | |
steps (Value x) = [[x]] | |
steps (List ns) = case substeps of | |
[] -> [] | |
(x : xs) -> x ++ concat (zipWith prepend lastStates xs) | |
where substeps = map steps ns | |
lastStates = scanl1 (++) $ map last substeps | |
prepend pref ss = map (pref ++) ss | |
steps (Sequence ns) = concatMap steps ns |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment