Skip to content

Instantly share code, notes, and snippets.

@qzchenwl
Last active August 29, 2015 14:25
Show Gist options
  • Save qzchenwl/57ec6f993bba6566dacd to your computer and use it in GitHub Desktop.
Save qzchenwl/57ec6f993bba6566dacd to your computer and use it in GitHub Desktop.
module Main where
import Data.List
vertices = "ABCDEFGHIJK"
edges = ["ADB", "AEC", "AFHJ", "AGIK", "BJKC", "BHIE", "DFGE"]
combinations n = filter ((==n) . length) . subsequences
inSameEdge xs = or [ all (`elem` edge) xs | edge <- edges]
isTriangle (a:b:c:[]) = all inSameEdge [[a, b], [a, c], [b, c]] && not (inSameEdge [a, b, c])
triangles = filter isTriangle (combinations 3 vertices)
main = print triangles
@qzchenwl
Copy link
Author

["ABC","ABE","BCE","ADE","BDE","ADF","AEF","ADG","AEG","AFG","ABH","AEH","EFH","ABI","AEI","EGI","AHI","ABJ","ACJ","BHJ","ABK","ACK","BIK","AJK"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment