Day 4.5: Haskell

TLDR : The one that flew over my head

Jack Nicholson from “The one who flew over the cuckoo’s nest”: He looks like he could kill someone. Exactly like me.
Diagram of directed graph. 1 is connected to 2, 2 to 3, 3 to 2 and 3 to 4.
hasPath :: [(Int,Int)] -> Int -> Int -> Bool
hasPath [] _ _ = False
hasPath [(a,b)] _ _ = True
hasPath xs a b = elem (a,b) xs || hasPath xs y b
where y | [] = -1
| [x] = x
| otherwise = ...
for y in [y in (x,y) in xs]
recursive call findPath xs y b
hasPath [] x y = x == y
hasPath xs x y
| x == y = True
| otherwise = let xs1 = [(n,m) | (n,m) <- xs, n/=x] in or [hasPath xs1 m y | (n,m) <- xs , n == x]

--

--

I do stuff. Like stuff about policy. And book stuff. And gaming stuff. And stuff about life. And stuff about stuff.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store