Created
October 9, 2017 18:24
-
-
Save wuerges/e7bda99cd928325711ddb84dfc8366f6 to your computer and use it in GitHub Desktop.
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 characters
import Data.Array.IArray | |
type G = Array Int [Int] | |
g1 :: G | |
g1 = array (1, 4) [[], [1], [1], [2, 3]] | |
preds :: Int -> G -> [Int] | |
preds x g = g !! x | |
dfs :: Int -> G -> Array Int [Int] | |
dfs o g = r | |
where r = array (1, size g) [go x | x <- [1..size g]] | |
go x = if x == o then [x] | |
else case preds x g of | |
[] -> [x] | |
(s, _) -> (x:r!!s) | |
main = print $ dfs g1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment