Skip to content

Instantly share code, notes, and snippets.

@wuerges
Created October 9, 2017 18:24
Show Gist options
  • Save wuerges/e7bda99cd928325711ddb84dfc8366f6 to your computer and use it in GitHub Desktop.
Save wuerges/e7bda99cd928325711ddb84dfc8366f6 to your computer and use it in GitHub Desktop.
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