Skip to content

Instantly share code, notes, and snippets.

@phagenlocher
Last active January 13, 2020 12:50
Show Gist options
  • Select an option

  • Save phagenlocher/0587b9f2b80f26958d525aa36e9dbbaa to your computer and use it in GitHub Desktop.

Select an option

Save phagenlocher/0587b9f2b80f26958d525aa36e9dbbaa to your computer and use it in GitHub Desktop.
elem :: (Eq a) => a -> [a] -> Bool
elem _ [] = False
elem e (x:xs) = (e == x) || (elem e xs)
nub :: (Eq a) => [a] -> [a]
nub [] = []
nub (x:xs)
| x `elem` xs = nub xs
| otherwise = x : nub xs
isAsc :: [Int] -> Bool
isAsc [] = True
isAsc [x] = True
isAsc (x:y:xs) = (x <= y) && isAsc (y:xs)
hasPath :: [(Int,Int)] -> Int -> Int -> Bool
hasPath [] x y = x == y
hasPath xs x y
| x == y = True
| otherwise =
let xs' = [ (n,m) | (n,m) <- xs, n /= x ] in
or [ hasPath xs' m y | (n,m) <- xs, n == x ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment